pokecrystal/home/math.asm

69 lines
788 B
NASM
Raw Normal View History

AddNTimes::
; Add bc * a to hl.
and a
ret z
.loop
add hl, bc
dec a
jr nz, .loop
ret
2018-06-24 14:09:41 +00:00
SimpleMultiply::
; Return a * c.
and a
ret z
push bc
ld b, a
xor a
.loop
add c
dec b
jr nz, .loop
pop bc
ret
2018-06-24 14:09:41 +00:00
SimpleDivide::
; Divide a by c. Return quotient b and remainder a.
ld b, 0
.loop
inc b
sub c
jr nc, .loop
dec b
add c
ret
2018-06-24 14:09:41 +00:00
Multiply::
; Multiply hMultiplicand (3 bytes) by hMultiplier. Result in hProduct.
; All values are big endian.
push hl
push bc
2017-12-24 17:47:30 +00:00
callfar _Multiply
pop bc
pop hl
ret
2018-06-24 14:09:41 +00:00
Divide::
; Divide hDividend length b (max 4 bytes) by hDivisor. Result in hQuotient.
; All values are big endian.
push hl
push de
push bc
2016-05-27 14:41:59 +00:00
homecall _Divide
pop bc
pop de
pop hl
ret
2018-06-24 14:09:41 +00:00
SubtractSigned::
; Return a - b, sign in carry.
sub b
ret nc
cpl
add 1
scf
ret