












Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!













1 To read in a string terminated by a carriage return: pt first char in buffer read character into R while R0! carriage return store R0 into buffer increment buffer pointer read character into R Store null into buffer [Note: this doesn't handle possibility of running past end of buffer]
3
7
9 ; Subroutines for carrying out the PUSH and POP functions. ; R6 is the stack pointer. ; INIT ST R1,Save1 ; Save registers LD R6,BOTTOM : init stack pointer ADD R1,R6,#1 ; Set underflow indicator NOT R1,R1 ; ... as negative of bottom+ ADD R1, #1 ; ... ST R1,UFLOW ; ... LD R1,MINTOP ; Set overflow indicator NOT R1,R1 ; ... as neg(MINTOP) ADD R1,#1 ; ... ST R1,OFLOW ; ... LD R1,Save1 ; Restore registers RET ; and return BOTTOM .FILL x3FFF ; Pt bottom of stack MINTOP .FILL x3FFB ; Pt min legal top value
PUSH ST R2,Save2 ; Save registers that ST R1,Save1 ; are needed by PUSH. LD R1,OFLOW ; MINTOP contains -x3FFB ADD R2,R6,R1 ; Compare stack pointer to -x3FFB BRz FAIL ; Branch if stack is full. ADD R6,R6,#-1 ; Adjust stack pointer STR R0,R6,#0 ; The actual "push" BR SUCCESS OFLOW .BLKW 1 ; neg(min legal top value)
13
Stack! empty [stack of unmatched left shapes] pt first character in string while not at end of string if current character is a left shape Push it onto the stack else (it's a right shape) if stack is empty Error! Unmatched right shape else pop stack to get a left shape if the left and right shapes don't match Error! Left and right shapes don't match end if pt next character in string end while if stack not empty Error! Too many left shapes
15
19
21
25
27
31
Program A
PSR for A
Program A
x ISR for Device B
33
PSR for A
Program A
x ISR for Device B
PSR for A
PSR for B
Program A
x ISR for Device B
ISR for Device C
x
37