Created
November 29, 2016 03:18
-
-
Save aurorapar/a1d1e3df9ddbd0b22715b7946607e6f5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.TITLE Resursive Multiply | |
.BLKW 1000. | |
ANS: .BLKW 2 | |
M: .BLKW 1 | |
N: .BLKW 1 | |
START: MOV #START, SP ; R6 gets set to this address | |
SUB #10., SP ; R6 -= 10 | |
MOV N, 8.(SP) ; | |
MOV M, 6(SP) ; 2(SP) AND 4(SP) CONTAIN DP ANSWER | |
MOV #NEXT, 0(SP) ; | |
JMP RMUL ; Go to recursive "function" | |
NEXT: MOV 2(SP), ANS | |
MOV 4(SP), ANS+2 | |
ADD #10., SP | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
RETURN: CLR 2(SP) | |
JMP @0(SP) | |
RMUL: TST 8.(SP) | |
BLE RETURN ; N <= 0 ? | |
ADD 6(SP), 4(SP) ; Low Order of Answer gets added by multiple M | |
ADC 2(SP) ; ADC to high order if overflow | |
DEC 8.(SP) ; N -= 1 | |
JMPSTUFF: MOV SP, R5 | |
SUB #10., SP | |
MOV #RETMULT, SP | |
MOV 6(R5), 6(SP) | |
MOV 8.(R5), 8.(SP) | |
RETMULT: ADD 6.(SP), 4(R5) | |
ADC 2(R5) ; Use register instead of SP - faster | |
ADD 2(SP), 2(R5) | |
ADD #10., SP |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment