Advertisement
Zeda

gcdD_C

May 31st, 2016
565
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     gcdD_C:
  2.     ;gcd(D,C)->HL
  3.     ;binary GCD algorithm
  4.         ld a,d \ or a \ ret z
  5.         ld a,c \ or a \ ret z
  6.         cp d \ ret z
  7.         ld b,1
  8.         or d \ rra \ jr c,+_
  9.         inc b \ rr d \ rr c
  10.         ld a,d \ or c \ rra \ jr nc,$-8
  11.     _:
  12.         srl d \ jr nc,$-2
  13.         rl d
  14.         ld a,c
  15.     _:
  16.         rra \ jr nc,$-1
  17.         rla
  18.         sub d
  19.         jr z,+_
  20.         jr nc,-_ \ neg
  21.         ld c,d
  22.         ld d,a
  23.         ld a,c
  24.         jp -_
  25.     _:
  26.         ld a,d
  27.         add a,a
  28.         djnz $-1
  29.         ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement