Question: Write an 8086 program that adds two numbers and displays the answer in a message like the sum of a and b is c where

Write an 8086 program that adds two numbers and displays the answer in a message like "the sum of a and b is c" where a is the first number, b is the second number and c is the sum.

Then the program should add the first number and a third number d and display the answer in a message like "the sum of a and d is e" where a is the first number, d is the third number and e is the sum.

After that the program should compare the two sums and display either the message "the sum of a and b is greater than the sum of a and d" or "the sum of a and d is greater than the sum of a and b" depending on which is true.

You should start each new message on a new line.

Test your program using the values a = 4, b = 3 and d = 2 and a = 1, b = 3 and d = 5. You can just embed these values in your program as constants and don't have to accept them from the keyboard.

;a program to perform addition

.model small ;define memory model

.stack 100h ;set stack size to 256

.data ;define data to be used

numa dw 4h ;word storage values

numb dw 3h ;for arithmetic

numd dw 2h

sum dw ? ;storage word for numa + numb

diff dw ? ; storage for difference

summsg db 'the sum of a and b is ',10,13 ;output message

ascsum db 5 dup(' '),'$' ;storage byte for sum

diffmsg db 'the sum of a and d is: ',10,13 ;output message for second addition

ascdiff db 5 dup(' '),'$' ;storage byte for difference

message3 db 'the sum of a and b is greater than the sum of a and d:',"$"

.code ;begin code segment

start:

mov ax,@data ;set up ds to point to the

mov ds,ax ;data segment

;calculate and display sum

mov ax,numa ;add num a and

add ax,numb ;and numb

mov sum,ax ;store result in

;calculate and display the difference

mov ax,numa ;subtract num a and

sub ax,numb ;and numb and store result in ax

mov sum,ax

;display sum

mov ah,09h ;use function 9 of int 21

mov dx,offset summsg ;use address of summsg to begin display

int 21h

;display difference

mov ah,09h ;use function 9 of int 21

mov dx,offset diffmsg ;use address of diffmsg to begin display

int 21h

;end program

mov ax,4c00h ;use function 4c of int 21

int 21h ;return to dos

end start

what I have so far

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!