.ORIG x3000 JSR MULTIPLY HALT ; MULTIPLY SUBROUTINE ; Takes the input at X and Y and stores the product X*Y ; at RESULT. ; INPUTS: X, Y ; OUTPUTS: RESULT X .FILL 0 Y .FILL 0 RESULT .FILL 0 MULTIPLY ; Insert code here. MUL_RET RET ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; DO NOT MODIFY ; ; RSH SUBROUTINE ; Effectively performs a "right shift" by ; left-shifting the input at RSH_IN by 15 bits ; and storing the result at RSH_RES ; ; INPUT: RSH_IN ; OUTPUT: RSH_RES RSH_IN .FILL 0 RSH_RES .FILL 0 RSH ST R0, TMPTMP_R0 ; Save registers we intend to use ST R1, TMPTMP_R1 ST R3, TMPTMP_R3 AND R3, R3, 0 ADD R3, R3, 15 LD R0, RSH_IN AND R1, R1, 0 RLOOP ADD R1, R1, R1 ; Left shift R1 ADD R0, R0, 0 BRzp RSKIP ADD R1, R1, 1 RSKIP ADD R0, R0, R0 ; Left shift R0 ADD R3, R3, -1 BRp RLOOP ST R1, RSH_RES LD R3, TMPTMP_R3 ; Restore registers LD R1, TMPTMP_R1 LD R0, TMPTMP_R0 RSH_RET RET ; First level tmp registers TMP_R0: .FILL 0 TMP_R1: .FILL 0 TMP_R2: .FILL 0 TMP_R3: .FILL 0 TMP_R4: .FILL 0 TMP_R5: .FILL 0 TMP_R6: .FILL 0 TMP_R7: .FILL 0 ; Second level tmp registers TMPTMP_R0: .FILL 0 TMPTMP_R1: .FILL 0 TMPTMP_R2: .FILL 0 TMPTMP_R3: .FILL 0 TMPTMP_R4: .FILL 0 TMPTMP_R5: .FILL 0 TMPTMP_R6: .FILL 0 TMPTMP_R7: .FILL 0 .END