Skip to content

Instantly share code, notes, and snippets.

@Trinitek
Created January 2, 2015 18:12
Show Gist options
  • Save Trinitek/f02085ee99ef7f0ab08c to your computer and use it in GitHub Desktop.
Save Trinitek/f02085ee99ef7f0ab08c to your computer and use it in GitHub Desktop.
32-bit line drawing (broken)
asm("mov ax, [bp - 4] \n" // ax = (dy)
"cwde \n"); // sign extend ax to fill eax
asm("mov bx, [bp - 6] \n" // bx = (newX)
"xchg eax, ebx \n" // ax = (newX) <--> bx = (dy)
"cwde \n"); // sign extend ax to fill eax
asm("imul ebx \n"); // eax = (signed)(dy * newX)
asm("mov edx, eax \n" // edx = eax
"mov ax, [bp - 2] \n" // ax = (dx)
"cwde \n"); // sign extend ax to fill eax
asm("xchg edx, eax \n" // eax = edx (eax = (dy * newX)) <-> edx = eax (dx)
"xor edx, edx \n"); // edx is considered the most significant dword in the dividend
// ...clear it before dividing; only lower half is needed
asm("idiv edx \n"); // eax = (signed)((dy * newX) / dx)
asm("mov [bp - 8], ax"); // (newY) = ax
// only lower half of eax is needed as the quotient should not be
// ...any larger than a signed word
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment