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

Manipulate the presentation and attributes interactive list, How can you m...

How can you manipulate the presentation and attributes of interactive lists? ---Scrolling by Interactive Lists. ---Setting the Cursor from within the Program. ---Changing

Show the two ways in which warnings can be suppressed in php, Show the two ...

Show the two ways in which Warnings can be suppressed in PHP? 1) Stop an individual function call from producing an error message put the @ warning suppression Operator front o

Give example of stack using encapsulation of OOA, Give example of stack usi...

Give example of stack using encapsulation of OOA An example of the Stack.  A Stack abstraction provides methods like pop (), push (), isEmpty(), isFull(). The Stack can be i

Design a sequential circuit with two flip-flop and one input, Design a coun...

Design a counter modulo 4 (sequential circuit with two flip-flops and one input U) which work like that: 1. When U=0, the state of the flip-flop does not change. 2. Whe

Explain naming convention verification points, Explanation:- In functio...

Explanation:- In functional testing, you require to confirm that the objects in the application-under-test look and work as designed from build to build. To accomplish this, yo

Differences between flexgrid control and dbgrid control, Normal 0 ...

Normal 0 false false false EN-IN X-NONE X-NONE MicrosoftInternetExplorer4

How two domain servers having same set of names, Does it makes sense for tw...

Does it makes sense for two domain servers to contain exactly the same set of names? Why or why not? Yes. This is very advantageous for 2-domain servers having same set of name

Node at the highest level in the structure, Node at the highest level in th...

Node at the highest level in the structure is known as?? Root.

Mutability and accessibility of primary memory, Mutability and Accessibilit...

Mutability and Accessibility of primary memory: Mutability: Read/write storage or mutable storage  It provides permit ion for the information to be overwritten at

Write a subroutine in c which toggles the cursor, Q . Write a subroutine in...

Q . Write a subroutine in C which toggles the cursor? Write a subroutine in C which toggles the cursor. It takes one argument which toggles the value between on (1) and off (0)

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