I have this program for emu8086 desire that does not add the values ??as merely
ID: 3633594 • Letter: I
Question
I have this program for emu8086 desire that does not add the values ??as merely the first value is divided into 07 and the second value is eliminated this is an exercise practice that if I can master a complex that I can do that if it is to deliver , posting the program waiting for help in this:
org 100h
jmp start ; skip data.
msg1 db 0Dh,0Ah, 'input numbers in this range: [-32768..32767]', 0Dh,0Ah
db 0Dh,0Ah, 'enter first number: $'
msg2 db 0Dh,0Ah, 'enter second number: $'
msg3 db 0Dh,0Ah, 'the sum is: $'
; declaration of variable:
num dw ?
start:
; print first message
mov dx, offset msg1
mov ah, 9
int 21h
call scan_num
; keep first number:
mov num, cx
; print second message
mov dx, offset msg2
mov ah, 9
int 21h
call scan_num
; add numbers:
add num, cx
jo overflow
; print the result:
mov dx, offset msg3
mov ah, 9
int 21h
mov ax, num
call print_num
jmp exit
; process overlow error:
overflow:
printn 'we have overflow!'
exit:
; wait for any key press:
mov ah, 0
int 16h
ret ; return control to operating system.
Explanation / Answer
Boy, it's been 30 years since I had to write some 8086 assembler .. and DOS function calls as well 8) It looks good, so I have to wonder if the problem is in scan_num or print_num, which you haven't provided. Check the register usage for calling them to be sure that scan_num returns value in CX and print_num expects the value in AX. This looks like a .EXE, rather than a .COM, based on the .org 100h at the top (leaving room for the TPA). I cant remember if DS is set correctly on entry for a .EXE, or whether you need to load it yourself. CS and SS should be set up for you by DOS, and ES is not used in any of your instructions. Again, check the assumptions for print_num and scan_num AND MAKE FRIENDS WITH DEBUG!!! You can single step through this relatively quickly (use breakpoints to bypass the int 21's)