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

Variance of predictions is expected to decrease, Suppose the random sample ...

Suppose the random sample used for each tree in the previous random forest is decreased from 1000 rows to 500 rows. Circle ALL that are true for the ensemble classifier. a) Vari

Explain different system calls for performing different task, Write down di...

Write down different system calls for performing different kinds of tasks. The major types of system calls are given as: Process Control: These kinds of system calls are

Explain cocomo model, A COCOMO model is :- COCOMO:- Constructive Cost Es...

A COCOMO model is :- COCOMO:- Constructive Cost Estimation Model.

What is known as multiphase clocking, What is known as multiphase clocking?...

What is known as multiphase clocking? When edge-triggered flip flops are not used, two or more clock signals may be required to guarantee proper transfer of data. This is calle

JAVA, HOW WAS JAVA INVENTED?

HOW WAS JAVA INVENTED?

Find gain in db of an amplifier has 600 ohm input resistance, An amplifier ...

An amplifier has an input resistance of 600 ohms and a resistive load of 75 ohms. When it has an rms input voltage of 100 mV, the rms output current is 20mA. Find the gain in dB.

Human computer interaction, Preamble The owner of the local shopping mal...

Preamble The owner of the local shopping mall, MaxiMart, has contracted you to assist in the design of an interactive directory. The interactive directory is to be permanently l

Define process control block, Define Process Control Block (PCB). Pr...

Define Process Control Block (PCB). Process Control Block (PCB): Information related with each process is stored into Process control Block. a)      Process state b)

How to clear a datagrid on a button click, How to clear a datagrid on a but...

How to clear a datagrid on a button click? You require to Clear the DataSource of the dataGrid. So try this: dataSet1.Clear(); dataGrid1.DataSource = dataSet1.TableNam

Write an algorithm to outline the macro-expansion, Write an algorithm to ou...

Write an algorithm to outline the macro-expansion using macro-expansion counter. The flow of control throughout macro expansion can be implemented by using a MEC that is macro-

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