For Assembly Language: I have the code below and I just can\'t figure out how to
ID: 3741796 • Letter: F
Question
For Assembly Language:
I have the code below and I just can't figure out how to subtract between two entered integers.
output should like:
Enter a number
13
Enter a number
12
1 ;// after 13-12
Explanation / Answer
Just before the WriteDec line, enter the following
mov eax, val ;; mov the val into eax so that it can be printed by WriteDec (since WriteDec prints whatever is in eax only.)
The following line does the subtraction.
;; so finally val contains the first_number - second_number
;; WriteDec then prints the difference to the screen (but the value to be printed must be in eax
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.386
.model flat,stdcall
.stack 4096
ExitProcess proto,dwExitCode:dword
WriteString proto
ReadInt proto
WriteDec proto
Crlf proto
.data
prompt BYTE " Enter a number ", 0dh, 0ah, 0
val DWORD ?
.code
main proc
mov edx, OFFSET prompt
call WriteString
call ReadInt
mov val, eax
call WriteString
call ReadInt
sub val, eax
mov eax,val
call WriteDec
call Crlf
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.