Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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

.data // write your data in this section prompt BYTE "Enter a number ", odh, 0ah, 0 val DWORD? .code / write your program here main proc mov edx, OFFSET prompt call Writestring call ReadInt mov val, eax call Writestring call ReadInt sub val, eax call WriteDec call Crlf invoke ExitProcess,0 main endp end main

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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote