0 Members and 1 Guest are viewing this topic.
ld c,a$: rl a rr b jr c, +$ jz nz, -$$: or c push af ld a,b or b ret z pop af jr -2$;Your next command, upon returning, should be pop af.
D_Times_E:;Inputs:; D and E are factors;Outputs:; A is the product (lower 8 bits); B is 0; C,DE, HL are not changed;Size: 12 bytes;Speed: 304+b cycles where b is the number of set bits in E xor a ;This is an optimised way to set A to zero. 4 cycles, 1 byte. ld b,8 ;Number of bits in E, so number of times we will cycle throughLoop: add a,a ;We double A, so we shift it left. rlc e ;We want the next bit in E, so it is shifted into the c flag jr nc,$+3 ;If it is 0, we don't need to add anything to A add a,d ;Since it was 1, we do A+1*D djnz Loop ;Decrements B, if it isn't zero yet, jump back to Loop: ret
Oh, and so to do 2-byte multiplication, you can simply change the counter to 16, and then the input registers to 16-bit ones?and yeah, the division routine would be great.
HL_Div_C:;Inputs:; HL is the numerator; C is the denominator;Outputs:; A is the remainder; B is 0; C is not changed; DE is not changed; HL is the quotient; ld b,16 xor aLoop: add hl,hl rla cp c jr c,$+4 inc l sub c djnz Loop ret