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

Graph has a minimum spanning tree already computed, Assume that a graph has...

Assume that a graph has a minimum spanning tree already computed.  How fastly can the minimum spanning tree be updated if a new vertex and incident edges are added to G? If the

Explain dns, DNS is The horizontal naming system.

DNS is The horizontal naming system.

Describe the size and speed of scanners, Q. Describe the Size and Speed of ...

Q. Describe the Size and Speed of Scanners? Before actual scanning, a quick, low resolution scan known as pre-scan is made to preview the image and select scanning area. After

Adding server-side include to the page, Step 1: Click on the icon in the ob...

Step 1: Click on the icon in the object tool bar Or Insert -> SSI Step 2: Select the file Step 3: Add the file Step 4: Provide the URL (where to be attached) Step

How to create a new object order preference, 1. In an ASCII editor, make an...

1. In an ASCII editor, make an empty text file with the extension .ord. 2. Save the file in the Dat folder of the project. 3. Click To o l s > G UI R e c o r d O p t i o n s

Show arithmetic subtraction, Q. Show Arithmetic Subtraction? The subtra...

Q. Show Arithmetic Subtraction? The subtraction can be done easily using 2's complement by taking 2's complement of value which is to be subtracted (inclusive of sign bit) and

Determine about the virtual private networks, Virtual Private Networks (VPN...

Virtual Private Networks (VPN) In order to encrypt/decrypt all the communication network traffic that passes through the Internet or Intranet, a VPN uses software or hardware.

Define a formal system, Q. Define a Formal System? A Formal System is o...

Q. Define a Formal System? A Formal System is one which is planned in advance and is used according to schedule. In this system procedures and policies are documented well in a

State the example of begin end, State the Example of begin end module s...

State the Example of begin end module sequential(); reg a; initial begin $monitor ("‰g a = ‰b", $time, a); #10 a = 0; #11 a = 1; #12 a = 0; #13 a = 1; #

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