Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;***********
- ;** Flash **
- ;***********
- ;(For programs, use the RAM version. This version is designed for Apps
- ;that cannot use SMC whereas the RAM one uses SMC to get a speeed boost).
- 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
- ;Notes:
- ; This uses 8 bytes of static RAM. I typically do this for the
- ; TempWords:
- ;TempWord1 equ OP6
- ;TempWord2 equ OP6+2
- ;TempWord3 equ OP6+4
- ;TempWord4 equ OP6+6
- ;
- ;Speed: At least 4916 cycles, at most 9864 cycles.
- ;Size: 93 bytes
- 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:
- ld hl,TempWord1
- sla c \ rl b \ rl e \ rl d
- rl (hl) \ inc hl
- rl (hl) \ inc hl
- rl (hl) \ inc hl
- rl (hl)
- jr nc,OverFlowDone
- ld hl,(TempWord3) \ add hl,bc
- ld b,h \ ld c,l
- ld hl,(TempWord4) \ 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