For Assembly Language x86: I have the following code: It currently outputs: Ente
ID: 3741790 • Letter: F
Question
For Assembly Language x86:
I have the following code:
It currently outputs:
Enter a number
4
Enter a number
3
7 ;// after adding 4+3
+7 ;// help
My question is how can I perform subtraction between my two entered integers so the result will be 1 instead of +7?
.data prompt BYTE " Enter a number ", 0dh, 0ah, 0 val DWORD? val2 DWORD? .code main proc mov edx, OFFSET prompt; call Writestring call ReadInt mov val, eax call Writestring call ReadInt add eax, val mov val2, eax call WriteDec call Crlf sub val, eax call WriteInt call Crlf invoke ExitProcess,0 main endp end mainExplanation / Answer
WriteInt prints integer value with sign while WriteDec does not print sign of interger.
so editing WriteDec to WriteInt prints +7 instead of 7.
for printing subtracted value of two numbers,
.data
prompt BYTE "Enter a number", 0dh, 0ah, 0
val DWORD ?
val2 DWORD ?
.doc
main proc
mov edx, OFFSET prompt;
call WriteString
call ReadInt
mov val, eax
call WriteString
call ReadInt
sub val, eax
call WriteDec
call Clrf
invoke ExitProcess,0
main endp
end main
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.