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

Using the AddSub program from the book as a reference, write an assembly program

ID: 3732891 • Letter: U

Question

Using the AddSub program from the book as a reference, write an assembly program to perform the following operations using only 16-bit registers: AX = 20 - (15 + 30). You must perform 15 + 30 first and then perform the subtraction operation. Insert a call DumpRegs statement after each operation and confirm that result is correct. Include code to output your name as well. Add a comment after each instruction to describe it. Once your program is working correctly, modify it to add the following calculation: BX = a - (b + d), but do keep the code from previous step. Once again, you must perform addition operation first and then perform the subtraction operation. Define variables a, b, and d as 16-bits signed integers with values 20, 15, and 30 respectively. Use DumRegs to confirm that it calculates the result correctly.

addsub program:

TITLE Add and Subtract (AddSubAlt.asm)
; This program adds and subtracts 32-bit integers.
.386
.model flat,stdcall
.stack 4096
ExitProcess PROTO, dwExitCode:DWORD
DumpRegs PROTO
.code
main PROC
mov eax,10000h ; EAX = 10000h
add eax,40000h ; EAX = 50000h
sub eax,20000h ; EAX = 30000h
call DumpRegs
INVOKE ExitProcess,0
main ENDP
END main

Explanation / Answer

TITLE Add and Subtract (AddSubAlt.asm)

; This program adds and subtracts 32-bit integers.
.386
.model flat,stdcall
.stack 4096
ExitProcess PROTO, dwExitCode:DWORD
DumpRegs PROTO
.data
a dw 2000h
b dw 1500h
d dw 3000h

.code
main PROC
resultLbl AddSub, 0 ;code to output yourName
output resultLbl, "yourName"
mov ax,15 ; AX = 15h

call DumpRegs
add ax,30 ; AX = 30h
call DumpRegs
sub ax,20 ; AX = 20h
call DumpRegs

mov bx,b ; bX = 15h ;for a-(b+d)
call DumpRegs
add bx,d ; bX = 30h
call DumpRegs
sub bx,a ; bX = 20h

call DumpRegs
INVOKE ExitProcess,0
main ENDP
END main

Please make the changes as shown in above program and execute.

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