Advertisement
Zeda

DEHL_Mul_32Stack (SMC)

Jan 4th, 2012
593
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;===============================================================
  2. ;***********
  3. ;**  RAM  **
  4. ;***********
  5. ;This uses Self Modifying Code to get a speed boost over the
  6. ;other routine. This must be used from RAM.
  7. DEHL_Mul_32Stack:
  8. ;Inputs:
  9. ;    DEHL
  10. ;    Two pushes to the stack (big endian) with the other 32-bit value
  11. ;Outputs:
  12. ;    AF is the return address
  13. ;    HLDEBC is the lower 48-bit result
  14. ;    4 bytes at TempWord1 contain the upper 32-bits of the result
  15. ;    4 bytes at TempWord3 contain the value of the input stack values
  16. ;    The stack contains two pops to perform:
  17. ;       First pop is the bits 33 to 48
  18. ;       Second pop is the bits 49 to 64
  19. ;Speed: 1216 cycles saved minimum
  20. ;       1600 cycles saved maximum
  21. ;       At least 3700 cycles, at most 8264 cycles.
  22. ;Size:  88 bytes
  23. ;Comparison/Perspective:
  24. ;    6MHz:
  25. ;       At the slowest, this can be executed about 6 times in
  26. ;       the time it takes to update the LCD. This can be
  27. ;       executed a little over 726 times per second.
  28. ;    15MHz:
  29. ;       At the slowest, this can be executed about 13 times in
  30. ;       the time it takes to update the LCD and about 1815 times
  31. ;       per second.
  32. ;===============================================================
  33.      ld (TempWord1),hl
  34.      ld (TempWord2),de
  35.      pop bc \ pop hl
  36.      ld (TempWord3),hl
  37.      pop hl
  38.      ld (TempWord4),hl
  39.      push bc
  40.      ld a,32
  41.      ld bc,0
  42.      ld d,b \ ld e,b
  43. Mult32StackLoop:
  44.      sla c \ rl b \ rl e \ rl d
  45.      .db 21h                     ;ld hl,**
  46. TempWord1:
  47.      .dw 0
  48.      adc hl,hl
  49.      .db 21h                     ;ld hl,**
  50. TempWord2:
  51.      .dw 0
  52.      adc hl,hl
  53.      jr nc,OverFlowDone
  54.        .db 21h
  55. TempWord3:
  56.        .dw 0
  57.        add hl,bc
  58.        ld b,h \ ld c,l
  59.        .db 21h
  60. TempWord4:
  61.        .dw 0
  62.        adc hl,de
  63.        ex de,hl
  64.        jr nc,OverFlowDone
  65.          ld hl,TempWord1
  66.          inc (hl) \ jr nz,OverFlowDone
  67.          inc hl \ inc (hl) \ jr nz,OverFlowDone
  68.          inc hl \ inc (hl) \ jr nz,OverFlowDone
  69.          inc hl \ inc (hl)
  70. OverFlowDone:
  71.      dec a
  72.      jr nz,Mult32StackLoop
  73.      pop af
  74.      ld hl,(TempWord2) \ push hl
  75.      ld hl,(TempWord1) \ push hl
  76.      push af
  77.      ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement