Find the average of two values, Computer Engineering

Assignment Help:

Q. Find the average of two values?

Find the average of two values which are stored in 

; Memory locations named FIRST and SECOND 

; And puts result in memory location AVGE.

; Input:  Two memory variables stored in memory locations FIRST and SECOND

; REGISTERS            ; Uses DS, CS, AX, BL

; PORTS                      ; None used

DATA             SEGMENT

FIRST             DB   90h         ; FIRST number,                      90h is a sample value

SECOND        DB   78h         ; SECOND number,                 78h is a sample value

AVGE             DB   ?              ; Store average here

DATA ENDS

CODE   SEGMENT

                        ASSUME CS:CODE, DS: DATA

START:           MOV    AX, DATA               ; Initialise data segment, i.e. set

                        MOV    DS, AX                     ; Register DS to point to Data Segment

                        MOV    AL, FIRST                            ; Get first number

                        ADD    AL, SECOND           ; add second to it 

                        MOV    AH, 00h                     ; Clear all of AH register

                        ADC    AH, 00h                     ; Put carry in LSB of AH

                        MOV    BL, 02h                     ; Load divisor in BL register

                        DIV      BL                             ; Divide AX by BL. Quotient in AL,

                                                                        ; And remainder in AH

                        MOV    AVGE, AL                ; Copy result to memory

CODE ENDS

END START

Discussion: 

An add instruction can't add two memory locations directly so we moved a single value in AL first and added the second value to it.

Please consider on adding the two values there is a possibility of carry bit. (The values here are being considered as unsigned binary numbers). Now problem is how to putcarry bit in the AH register in such a way that AX(AH:AL) reflects added value. This is done employing ADC instruction.

ADC AH,00h instruction would add immediate number 00h to contents of carry flag and contents of AH register. The result will be left in AH register. As we had cleared AH to all zeros before the add we actually are adding 00h + 00h + CF. Result of all this is the carry flag bit is put in AH register that was anticipated by us.

Lastly to get the average we divide the sum given in AX by 2. A more universal program would need negative and positive numbers. After division 8-bit quotient would be left in AL register that can then be copied in the memory location called as AVGE.


Related Discussions:- Find the average of two values

Why we need to construct state transition diagram, Why we need to construct...

Why we need to construct state transition diagram Basically you need to construct a state transition diagram for each object with important behaviour. You need not construct on

Task and parallel task, Task A logically discrete sector of a computati...

Task A logically discrete sector of a computational effort. A task is naturally a program or program-like set of instructions that is implemented by a processor.  Parallel

Create an input buffer, Q. Create an input buffer ? CODE SEGMENT ......

Q. Create an input buffer ? CODE SEGMENT ... MOV AH, 0AH                       ; Move 04 to AH register MOV DX, BUFF                   ; BUFF must be defined in data

Two services that are used to deal with communication, Explain about the tw...

Explain about the two services that are used to deal with communication. Message Service: Used by the application servers to change short internal messages, all system commu

Perform on occurrence of an interrupt, Q. Perform on occurrence of an inter...

Q. Perform on occurrence of an interrupt? Determining these requirements let's work out steps that CPU should perform on occurrence of an interrupt. The CPU should find

Starting parallel virtual machine, Q. Starting parallel virtual machine? ...

Q. Starting parallel virtual machine? To initialize PVM on any host on that PVM has been installed we can type  % pvm The PVM console known as pvm is a standalone PVM t

What is associative search, What is associative search? The cost of an ...

What is associative search? The cost of an associative cache is higher that the cost of a direct mapped cache due to the need to search all 128 bit tag patterns to verify wheth

Electric circuit analysis, mmmmmmmmmmmmm mmmmmmm s s s s s s s s s d d d ...

mmmmmmmmmmmmm mmmmmmm s s s s s s s s s d d d d d d d d d d d d d d f f ff g gg g g g g gg r r r rr r w ww w w ww w w

What is referred as memory mapped i/o, What is referred as memory mapped I/...

What is referred as memory mapped I/O. The case in computers that employ only set of read and write signals and do not differentiate between memory and I/O address. This is kno

What are the risks involved in electronic payment systems, What are the ris...

What are the risks involved in Electronic Payment Systems?    From the customer's perspective: Dishonest merchants or financial service providers Stolen payment

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd