In: Computer Science
Assembly Language Programming Exercise. Problem # 1:
1. Integer Expression Calculation( 5 pts
)
Using the AddTwo program from Section 3.2 as a reference, write a
program that calculates the
following expression, using registers: A = (A + B) − (C + D).
Assign integer values to the EAX,
EBX, ECX, and EDX registers.
.386
.model flat,stdcall
.stack 4096
ExitProcess PROTO, dwExitCode:DWORD
.code
main PROC
mov eax, 5
mov ebx, 7
mov ecx, 4
mov edx, 1
add eax, ebx
add ecx, edx
sub eax, ecx
INVOKE ExitProcess,0
main ENDP
END main
Explanation:
In the code above mov indicates moving values to the register
mov eax, 5 - storing integer value 5 in register eax ( A = 5
)
mov ebx, 7 - storing integer value 7 in register eax ( B = 7
)
mov ecx, 4- storing integer value 4 in register eax ( C = 4 )
mov edx, 1- storing integer value 1 in register eax ( D = 1 )
add indicates addition operation
add eax, ebx - adding the values in register eax and ebx and
stores the result in register eax
add ecx, edx- adding the values in register ecx and edx and stores
the result in register ecx
sub indicates subtraction operation
sub eax, ecx - Subtracting the values in register eax and ecx and
stores the result in register eax(This will be the final
result)