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

Explain vector-scalar instructions, Vector-Scalar Instructions In this ...

Vector-Scalar Instructions In this category, when combination of vector and scalar are fetched and stored in vector register. These instructions are referred with the subsequen

Integrated test result, COGNITIONS Mr. X exhibits a generally high-quali...

COGNITIONS Mr. X exhibits a generally high-quality level of cognitive and intellectual functioning, as evidenced by his performance on the MMSE-2 and WAIS-IV. His one weakness w

What is the main problem with segmentation, What is the main problem with s...

What is the main problem with segmentation? Problem with segmentation (i) Is with paging, such mapping needs two memory references per logical address that slows down the

Finest way to get a reference to the viewport, What is finest way to get a ...

What is finest way to get a reference to the viewport from anywhere in the code? Ans) You can use refs config to set a reference on the Application/Controllers

State about the mainframe computer, Mainframe computer Mainframe comput...

Mainframe computer Mainframe computers are very large, often can fill an entire room. They can store a large amount of information, can execute many tasks at the same time, can

Master scheduling , The alpha beta company generates two products; A and B,...

The alpha beta company generates two products; A and B, that are made from components C and D. Given the following product structures, master scheduling requirements and inventory

Explain the process of inter-register signalling, Explain the process of in...

Explain the process of inter-register signalling. Registers are utilized in common control exchanges to store and analyze routing data. They are given on a common basis is a

Padovan string , A Padovan string P(n) for a natural number n is defined as...

A Padovan string P(n) for a natural number n is defined as: P(0) = ‘X’ P(1) = ‘Y’ P(2) = ‘Z’ P(n) = P(n-2) + P(n-3), n>2 where + denotes string concatenation. For a string of t

What is interactive reporting, What is interactive reporting? It helps ...

What is interactive reporting? It helps you to make easy-to-read lists.  You can view an overview list first that having general information and give the user with the possibil

Programming.., converting 10 ASCII characters to excess three using mplab i...

converting 10 ASCII characters to excess three using mplab ide

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