ADD THREE, USING A SUBROUTINE, PASSING ARG AS IN-LINE VALUE


.TITLE ADD_THREE
.ENTRY START, 0
.PUTSTR MSG
.PUTSTR MSG_X
.GETHEX ; Get input of X
MOVL R0, X ; X <-- R0
.PUTSTR MSG_Y
.GETHEX ; Get input of Y
MOVL R0, Y ; Y <-- R0
.PUTSTR MSG_Z
.GETHEX ; Get input of Z
MOVL R0, Z ; Z <-- R0
BSBW SUB0 ; Branch to SUB0 subroutine
X: .BLKL 1 ; Allocate longword for X
Y: .BLKL 1 ; Allocate longword for Y
Z: .BLKL 1 ; Allocate longword for Z
RESULT:.BLKL 1 ; Allocate longword for RESULT
.PUTSTR MSG_R
MOVL RESULT, R0 ; R0 <-- RESULT
.PUTHEX ; Print out the RESULT
$EXIT_S
MSG: .ASCIZ/Please enter any three numbers in HEX you'd like to add:/
MSG_X: .ASCIZ/INPUT X:/
MSG_Y: .ASCIZ/INPUT Y:/
MSG_Z: .ASCIZ/INPUT Z:/
MSG_R: .ASCIZ/Sum of three numbers X, Y, Z in HEX is:/
---- Subroutine that passes the argument as IN-LINE VALUES ----
SUB0:
will compute the sum of three HEX numbers X, Y and Z from inputs
where:
(SP) = R5
X = (R5)
Y = (R5+4)
Z = (R5+8)
RESULT = (R5+12)
POPL R5 ; R5 gets the address of X
PUSHL R1 ; Protect register R1
ADDL3 (R5)+, (R5)+, R1 ; R1 <-- X + Y
ADDL (R5)+, R1 ; R1 <-- X + Y + Z
MOVL R1, (R5)+ ; RESULT <-- X + Y + Z
POPL R1 ; Restore R1
PUSHL R5 ; Push return address onto stack
RSB ; Return to Caller
END:
.END START