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

Assembly language programes, Program to calculate the value of the series 1...

Program to calculate the value of the series 1+x+x2+x3+.... +xn. Read the values of ''x'' and ''n'' from the keyboard.

Explain the term- cycle based simulator, Explain the term- Cycle Based Simu...

Explain the term- Cycle Based Simulator This is a Digital Logic Simulation method which eliminates unnecessary calculations to achieve huge performance gains in verifying Bool

Dbms, write er diagram for company database

write er diagram for company database

Explain the importance of search engines, Explain the importance of Search ...

Explain the importance of Search Engines The most effective way of finding information on the internet is to use a search engine. Though, it's just as easy to use these ineffic

What is imprecise and precise exception, What is imprecise and precise exce...

What is imprecise and precise exception? Situation in which one or more of the succeeding instructions have been implemented to completion is known as imprecise exception. Situ

Boardcoloring, write a java program to board coloring

write a java program to board coloring

Recursion, Ask qurecurrion for short noteestion

Ask qurecurrion for short noteestion

Simulate a worm propagation considering traffic delay, At time t when an in...

At time t when an infected machine scans and finds a vulnerable machine, the vulnerable one will be compromised and start to scan and infect others at time t+X, where X is a r.v. f

Describe about the digital cameras, Describe about the Digital cameras ...

Describe about the Digital cameras The microprocessor would be used to control the below functions, for instance: - shutter speed - lens focus - Flash - Aperture (l

Principles for developing successful system, Q. Principles for developing s...

Q. Principles for developing successful system? (1)  Both developers and customers must be involved for accuracy in the information. (2)  A problem solving approach must be

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