In: Computer Science
The assembly code for A is as follows:
assume cs:code, ds:data
data segment
msg1 db "Enter 5 numbers:$"
msg3 db 10,13,"$" ; msg to display
newline
msg2 db 10,13,"The sum of the entered
numbers is:$"
msg4 db 10,13,"Division of entered number
4 by entered number 2 is:$"
sum db 0
digit2 db ?
digit4 db ?
data ends
code segment
start:
; set segment registers:
mov ax, data
mov ds, ax ; initialize the data segment
lea dx, msg1
mov ah, 09
int 21h ; display msg1 using the above
code
lea dx, msg3
mov ah, 09
int 21h; display
msg3
mov cx,05 ; initialize cx with count of numbers
to be read
up:
mov ah,01h
int 21h ; read a number
sub al,30h ; the ascii value of number is
read
; for eg, if 1 is read, 31h will be available in
al
;subtract 30h from it to obtain the rquired
number
add sum,al ; add the entered value with variable
sum
cmp cx,04h
jne digitf
mov digit2,al
digitf:
cmp cx,02h
jne next
mov digit4,al
next:
mov ah,09h
lea dx,msg3
int 21h ; display msg3
loop up ; loop continues for no.of time
mentioned in cx
lea dx,msg2
mov ah, 09h
int 21h ; display msg2
mov al,sum ; put the final sum in al
aam ; apply aam to convert the packed bcd sum to
unpacked bcd digits
;aam separates the digits and stores it in al
and ah
add ah,30H ; to display any value on screen, the
ascii value has to be generated.
;Hence add 30h to the value
add al,30H
mov dh,al
mov dl,ah
mov ah,02h
int 21h; display the digit1 of sum
mov dl,dh
mov ah,02h
int 21h;display digit2 of sum
lea dx,msg4
mov ah,09h
int 21h ; display msg4
mov ah,00 ;division is to be performed for
ax/bl
mov al,digit4 ; store digit4 in ax
mov bl,digit2 ; store digit2 in bl
div bl ; perform division. quotient will be in
AL register
mov dl,al
add dl,30h; add 30h to result to get the ascii
value of result
mov ah,02h
int 21h ; display the result
mov ah, 4ch ; exit to operating system.
int 21h
code ends
end start
OUTPUT: