Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Math routine, fix divide by zero bug, add Sublime Text syntax file
- Loading branch information
1 parent
c6ad805
commit 482f135
Showing
8 changed files
with
735 additions
and
94 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,92 @@ | ||
package math do | ||
// Quick 16 x 16 unsigned multiply. | ||
// | ||
// By: Jon Tara | ||
// MicroControl Software | ||
// 1300 E. Lafayette #2808 | ||
// Detroit, Michigan 48207 | ||
// (313) 393-2916 | ||
// | ||
// This software is placed in the public domain. | ||
// | ||
// Jon Tara (1982-01-21): Initial release | ||
// Jeff Frohwein (1997-04-25): Bug fixes | ||
// Andrew G. Crowell (2013-05-28): Ported to wiz. | ||
// | ||
// Arguments: | ||
// de = multiplicand | ||
// hl = multiplier | ||
// Returns: | ||
// bcde = product | ||
// Dirty: | ||
// All registers. | ||
// | ||
func multiply_16x16 do | ||
// Save MSBs of multiplier. | ||
c = h | ||
// Save LSBs to accumulator for an 8x16 multiply. | ||
a = l | ||
// Set B = 0, for carry propagation. | ||
b = 0 | ||
// Init LSBs of product | ||
h = b | ||
l = b | ||
unroll 7 do | ||
// Test multiplier bit. | ||
a = a + a | ||
if is carry then | ||
// Add multiplicand to product in AHL. | ||
hl = hl + de | ||
a = a +# b | ||
end | ||
// Shift product left. | ||
hl = hl + hl | ||
end | ||
// Test multiplier bit. | ||
a = a + a | ||
if is carry then | ||
// Add multiplicand to product in AHL. | ||
hl = hl + de | ||
a = a +# b | ||
end | ||
|
||
// Save LSBs on stack. | ||
push hl | ||
// Zero second product. | ||
h = b | ||
l = b | ||
// Save MSBs of first product in B. | ||
b = a | ||
// Get MSBs of multiplier. | ||
a = c | ||
// Set C = 0, for carry propagation. | ||
c = h | ||
unroll 7 do | ||
// Test multiplier bit. | ||
a = a + a | ||
if is carry then | ||
// Add multiplicand to product in AHL. | ||
hl = hl + de | ||
a = a +# c | ||
end | ||
// Shift product left. | ||
hl = hl + hl | ||
end | ||
// Test multiplier bit. | ||
a = a + a | ||
if is carry then | ||
// Add multiplicand to product in AHL. | ||
hl = hl + de | ||
a = a +# c | ||
end | ||
|
||
// Pop LSBs from stack. | ||
de = pop | ||
// Add partial products. | ||
c = a | ||
d = d + l via a | ||
h = b +# h via a | ||
b = c +# 0 via a | ||
c = h | ||
end | ||
end |
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
Oops, something went wrong.