I'm trying to add two numbers from the user and display their sum but I don't get the desired output.I don't know what I did wrong. Can someone please help? Here's my code:
Data_segment_name segment para
n1 db ?
n2 db ?
Data_segment_name ends
Stack_segment_name segment para stack
Stack_segment_name ends
Code_segment_name segment
Main_prog proc far
assume SS:Stack_segment_name,CS:Code_segment_name,DS:Data_segment_name
mov AX,Data_segment_name ; load the starting address of the data
mov DS,AX ; segment into DS reg.
mov ah,01h
int 21h
sub al,30h
mov n1,al
mov ah,01h
int 21h
sub al,30h
mov n2,al
mov al,n1
add al,n2
mov ax,0h
mov bl,10
div bl
mov dl,ah
add dl,30h
mov ah,02h
int 21h
mov dl,al
add dl,30h
mov ah,02h
int 21h
;mov ax,4c00h ; exit program
mov ah,07h
int 21h
Main_prog endp
Code_segment_name ends
end Main_prog
You assume that the results of the division will stay in the registers while you display your first digit.
It will not, so you have to store the result to memory, just like you do with the input.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.