Skip to content

Instantly share code, notes, and snippets.

@tuankiet65
Created November 11, 2018 15:38
Show Gist options
  • Save tuankiet65/319a3203a9af6839e5dcdf6c4c488405 to your computer and use it in GitHub Desktop.
Save tuankiet65/319a3203a9af6839e5dcdf6c4c488405 to your computer and use it in GitHub Desktop.
; eax = x / y
divide proc x: SDWORD, y: SDWORD
mov eax, x
cdq
idiv y
ret
divide endp
; eax = x % y
modulo proc x: SDWORD, y: SDWORD
invoke divide, x, y ; eax = (x // y)
mov edx, eax ; edx = (x // y)
imul edx, y ; edx = (x // y) * y
mov eax, x ; eax = x
sub eax, edx ; eax = x - ((x // y) * y)
ret
modulo endp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment