main:
STR R7, R6, #1 ; even main needs to store return address
:
: ; call to printf, test for the while loop
:
LDR R0, R6, #3 ; load value of echo
STR R0, R6, #8 ; store echo as first parameter
STR R6, R6, #7 ; store current top of stack as dynamic link
ADD R6, R6, #5 ; move top of stack to new activation record
JSR ToUpper ; the call
LDR R0, R6, #5 ; load return value and stick it into upcase
STR R0, R6, #4 ; upcase = ToUpper(echo);
:
: ; code for call putchar
ToUpper:
STR R7, R6, #1 ; store away the return address
LDR R0, R6, #3 ; load the parameter inchar
STR R0, R6, #4 ; outchar = inchar;
LD R1, ASCII_a ; load the ascii value of 'a'
NOT R1
ADD R1, R1, #1 ; R1 contains -'a'
ADD R1, R0, R1 ; inchar - 'a'
BRn FALSE ; inchar is less than 'a'
LD R1, ASCII_z ; load the ascii value of 'z'
NOT R1
ADD R1, R1, #1 ; R1 contains -'z'
ADD R1, R0, R1 ; inchar - 'z'
BRn FALSE ; inchar is greater than 'z'
; The condition is true ('a'<= inchar && inchar <= 'z')
LD R1, neg_ASCII_a_minus_A ; load ascii value of -('a'-'A')
LDR R0, R6, #3 ; load inchar
ADD R0, R1, R0 ; calculate inchar - ('a' - 'A')
STR R0, R6, #4 ; outchar = inchar - ('a' - 'A');
FALSE:
LDR R0, R6, #4 ; load outchar
STR R0, R6, #0 ; store it into the return value entry
LDR R7, R6, #1 ; load the return address
LDR R6, R6, #2 ; load the dynamic link
RET ; return outchar;
ASCII_a: .FILL #97
ASCII_z: .FILL #122
neg_ASCII_a_minus_A: .FILL #-32