TheQuack45

Multiplication and division in x86 MASM

Mar 16th, 2016
391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .586
  2. .MODEL FLAT, C
  3.  
  4. .DATA
  5. oper DB 0 ;Set to 0 if multiplication, 1 if division
  6. a DWORD 25
  7. b DWORD 5
  8.  
  9. .CODE
  10.  
  11. MULTIPLY PROC
  12.     mov ebx, 1 ;Move 0 to EBX register for counter
  13.     mov eax, a
  14.    
  15.     cmp oper, 0
  16.     je multi
  17.     jmp divi
  18.  
  19.     multi:
  20.         add eax, a
  21.         inc ebx
  22.         cmp ebx, b
  23.         jl multi
  24.         jmp endSect
  25.    
  26.     divi:
  27.         sub eax, b
  28.         inc ebx
  29.         cmp eax, 1
  30.         jg divi
  31.         mov eax, ebx
  32.         dec eax
  33.         jmp endSect
  34.  
  35.     endSect:
  36.         mov eax, eax
  37. MULTIPLY ENDP
  38.  
  39. END
Advertisement
Add Comment
Please, Sign In to add comment