Example: OpAdd
•
OpAdd JSR POP ; Get first operand.
ADD R5,R5,#0 ; Check for POP success.
BRp Exit ; If error, bail.
ADD R1,R0,#0 ; Make room for second.
JSR POP ; Get second operand.
ADD R5,R5,#0 ; Check for POP success.
BRp Restore1 ; If err, restore & bail.
ADD R0,R0,R1 ; Compute sum.
JSR RangeCheck ; Check size.
BRp Restore2 ; If err, restore & bail.
JSR PUSH ; Push sum onto stack.
RET
Restore2 ADD R6,R6,#-1 ; Decr stack ptr (undo POP)
Restore1 ADD R6,R6,#-1 ; Decr stack ptr
Exit RET
Data Type Conversion
• LC3 keyboard input routines read ASCII characters,
not binary values.
•Similarly, LC3 output routines write ASCII.
•You’ve seen this program:
• IN ; input from keybd into R0
ADD R1, R0, #0 ; move to R1
IN ; read next input from keybd
ADD R2, R0, #0 ; move to R2 add two inputs
ADD R0, R1,R2 ; add the two inputs
OUT ; print result
•What happened ?
• Why? ASCII '2' (x32) + ASCII '3' (x33) = ASCII 'e' (x65)