Advertisement
Zeda

DEHL_Mul_32Stack (No-SMC)

Jan 4th, 2012
436
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;***********
  2. ;** Flash **
  3. ;***********
  4. ;(For programs, use the RAM version. This version is designed for Apps
  5. ;that cannot use SMC whereas the RAM one uses SMC to get a speeed boost).
  6. DEHL_Mul_32Stack:
  7. ;Inputs:
  8. ;    DEHL
  9. ;    Two pushes to the stack (big endian) with the other 32-bit value
  10. ;Outputs:
  11. ;    AF is the return address
  12. ;    HLDEBC is the lower 48-bit result
  13. ;    4 bytes at TempWord1 contain the upper 32-bits of the result
  14. ;    4 bytes at TempWord3 contain the value of the input stack values
  15. ;    The stack contains two pops to perform:
  16. ;       First pop is the bits 33 to 48
  17. ;       Second pop is the bits 49 to 64
  18. ;Notes:
  19. ;     This uses 8 bytes of static RAM. I typically do this for the
  20. ;     TempWords:
  21. ;TempWord1       equ OP6
  22. ;TempWord2       equ OP6+2
  23. ;TempWord3       equ OP6+4
  24. ;TempWord4       equ OP6+6
  25. ;
  26. ;Speed: At least 4916 cycles, at most 9864 cycles.
  27. ;Size:  93 bytes
  28.      ld (TempWord1),hl
  29.      ld (TempWord2),de
  30.      pop bc \ pop hl
  31.      ld (TempWord3),hl
  32.      pop hl
  33.      ld (TempWord4),hl
  34.      push bc
  35.      ld a,32
  36.      ld bc,0
  37.      ld d,b \ ld e,b
  38. Mult32StackLoop:
  39.      ld hl,TempWord1
  40.      sla c \ rl b \ rl e \ rl d
  41.      rl (hl) \ inc hl
  42.      rl (hl) \ inc hl
  43.      rl (hl) \ inc hl
  44.      rl (hl)
  45.      jr nc,OverFlowDone
  46.        ld hl,(TempWord3) \ add hl,bc
  47.        ld b,h \ ld c,l
  48.        ld hl,(TempWord4) \ adc hl,de
  49.        ex de,hl
  50.        jr nc,OverFlowDone
  51.          ld hl,TempWord1
  52.          inc (hl) \ jr nz,OverFlowDone
  53.          inc hl \ inc (hl) \ jr nz,OverFlowDone
  54.          inc hl \ inc (hl) \ jr nz,OverFlowDone
  55.          inc hl \ inc (hl)
  56. OverFlowDone:
  57.      dec a
  58.      jr nz,Mult32StackLoop
  59.      pop af
  60.      ld hl,(TempWord2) \ push hl
  61.      ld hl,(TempWord1) \ push hl
  62.      push af
  63.      ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement