Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- GCDHL_BC:
- ;Inputs:
- ; HL is a number
- ; BC is a number
- ;Outputs:
- ; A is 0
- ; BC is the GCD
- ; DE is 0
- ;Destroys:
- ; HL
- ;Size: 25 bytes
- ;Speed: 30 to 49708 cycles
- ; -As slow as about 126 times per second at 6MHz
- ; -As fast as about 209715 times per second at 6MHz
- ;Speed break down:
- ; If HL=BC, 30 cycles
- ; 24+1552x
- ; If BC>HL, add 20 cycles
- ; *x is from 1 to at most 32 (because we use 2 16-bit numbers)
- ;
- or a \ sbc hl,bc ;B7ED42 19
- ret z ;C8 5|11
- add hl,bc ;09 11
- jr nc,$+8 ;3006 11|31
- ld a,h ;7C --
- ld h,b ;60 --
- ld b,a ;47 --
- ld a,l ;7D --
- ld l,c ;69 --
- ld c,a ;4F --
- Loop:
- call HL_Div_BC ;CD**** 1511
- ld a,d \ or e ;7AB2 8
- ret z ;C8 5|11
- ld h,b \ ld l,c ;6069 8
- ld b,d \ ld c,e ;424B 8
- jr $-10 ;18F8 12
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement