Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I've wrestled for a long time with how to support integer division with its hard-coded registers. The answer's always been staring me in the face: just turn it into a function! We already expect function outputs to go to hard-coded registers.
- Loading branch information
Showing
4 changed files
with
23 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
== code | ||
|
||
integer-divide: # a: int, b: int -> quotient/eax: int, remainder/edx: int | ||
# . prologue | ||
55/push-ebp | ||
89/<- %ebp 4/r32/esp | ||
# eax = a | ||
8b/-> *(ebp+8) 0/r32/eax | ||
# edx = all 0s or all 1s | ||
99/sign-extend-eax-into-edx | ||
# quotient, remainder = divide eax by b | ||
f7 7/subop/divide-eax-edx-by *(ebp+0xc) | ||
$integer-divide:end: | ||
# . epilogue | ||
89/<- %esp 5/r32/ebp | ||
5d/pop-to-ebp | ||
c3/return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters