the sum OF THREE NUMBERS, PASSING ADDRESSES OF ARG LIST IN REGISTERS
.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
MOVL #ARG, R5 ; Address of ARG array to R5
BSBW SUB1 ; Branch to SUB1 subroutine
.PUTSTR MSG_R
MOVL RESULT, R0 ; R0 <-- RESULT
.PUTHEX ; Print the value of RESULT
$EXIT_S
ARG: .LONG 4, X, Y, Z, RESULT ; Argument address array
X: .LONG 8 ; Initialize X
Y: .LONG 16 ; Initialize Y
Z: .LONG 24 ; Initialize Z
RESULT:.BLKL 1 ; Reserve longword for RESULT
MSG: .ASCIZ/PLEASE ENTER 3 NUMBERS YOU WOULD 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 with ADDRESS of ARG LIST ---
will compute the sum of three input numbers X, Y and Z, then put their
sum into RESULT
SUB1:
Computes RESULT = X + Y + Z
X = @4(R5)
Y = 8@(R5)
Z = 12@(R5)
RESULT = 16@(R5)
PUSHL R1 ; Protect register R1
ADDL3 @4(R5), @8(R5), R1 ; R1 <-- X + Y
ADDL @12(R5), R1 ; R1 <-- X + Y + Z
MOVL R1, @16(R5) ; RESULT <-- X + Y + Z
POPL R1 ; Restore R1
RSB ; Return to Caller
; End of SUB1
END:
.END START