Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;===============================================================
- ;***********
- ;** RAM **
- ;***********
- ;This uses Self Modifying Code to get a speed boost over the
- ;other routine. This must be used from RAM.
- DEHL_Mul_32Stack:
- ;Inputs:
- ; DEHL
- ; Two pushes to the stack (big endian) with the other 32-bit value
- ;Outputs:
- ; AF is the return address
- ; HLDEBC is the lower 48-bit result
- ; 4 bytes at TempWord1 contain the upper 32-bits of the result
- ; 4 bytes at TempWord3 contain the value of the input stack values
- ; The stack contains two pops to perform:
- ; First pop is the bits 33 to 48
- ; Second pop is the bits 49 to 64
- ;Speed: 1216 cycles saved minimum
- ; 1600 cycles saved maximum
- ; At least 3700 cycles, at most 8264 cycles.
- ;Size: 88 bytes
- ;Comparison/Perspective:
- ; 6MHz:
- ; At the slowest, this can be executed about 6 times in
- ; the time it takes to update the LCD. This can be
- ; executed a little over 726 times per second.
- ; 15MHz:
- ; At the slowest, this can be executed about 13 times in
- ; the time it takes to update the LCD and about 1815 times
- ; per second.
- ;===============================================================
- ld (TempWord1),hl
- ld (TempWord2),de
- pop bc \ pop hl
- ld (TempWord3),hl
- pop hl
- ld (TempWord4),hl
- push bc
- ld a,32
- ld bc,0
- ld d,b \ ld e,b
- Mult32StackLoop:
- sla c \ rl b \ rl e \ rl d
- .db 21h ;ld hl,**
- TempWord1:
- .dw 0
- adc hl,hl
- .db 21h ;ld hl,**
- TempWord2:
- .dw 0
- adc hl,hl
- jr nc,OverFlowDone
- .db 21h
- TempWord3:
- .dw 0
- add hl,bc
- ld b,h \ ld c,l
- .db 21h
- TempWord4:
- .dw 0
- adc hl,de
- ex de,hl
- jr nc,OverFlowDone
- ld hl,TempWord1
- inc (hl) \ jr nz,OverFlowDone
- inc hl \ inc (hl) \ jr nz,OverFlowDone
- inc hl \ inc (hl) \ jr nz,OverFlowDone
- inc hl \ inc (hl)
- OverFlowDone:
- dec a
- jr nz,Mult32StackLoop
- pop af
- ld hl,(TempWord2) \ push hl
- ld hl,(TempWord1) \ push hl
- push af
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement