3) How To Use Add, Sub, Mul, Div Instructions

Do simple calculations using the add, sub, mul, and div instructions.

.386
.model flat,stdcall
.stack 4096
ExitProcess proto,dwExitCode:dword

.data
sum DWORD 0
remainder DWORD 0

num1 WORD 5
num2 word 12
num3 word 10
symbolicCon = 8
.code
main proc
; sum = (13 + 6) - 5
mov eax,13 
add eax,6 
sub eax,5 
mov sum,eax               ;Sum = 16 eax= Eh

; sum = (13h + 6h) - 5h
mov eax,13h               ;19 
add eax,6h                ;6
sub eax,5h                ;5
mov sum,eax               ;Sum = 20 eax = 14h

; sum = (44 / (2 * 11)) + 7
; learn more about the mul and div instruction in chapeter 7.3
mov eax, 2
mov ebx, 11
mul ebx                   ;eax = 22 
mov ebx, 44
xchg eax, ebx             ;eax = 44 ebx = 22
div ebx                   ;eax = 2
add eax, 7
mov sum, eax              ;Sum = 9

; sum = (7 * 5) / 4
mov eax, 7
mov ebx, 5
mul ebx
mov ebx, 4
div ebx
mov sum, eax              ;Sum = 8
mov remainder, edx        ;Remainder = 3

; sum = ((num1 * num2) / num3) - symbolicCon
mov ax, num1
mul num2
div num3
sub ax, symbolicCon
mov sum, eax              ;Sum = -2 Eax = FFFE
invoke ExitProcess,0
main endp
end main

Show Code