Specifications

The instruction INC Rl increases the contents of Rl by 1 and the instruction
CLR RO zeroes the register RO
2. Saving and restoring registers on the stack-This subroutine pushes
RO-R5 onto the stack. It is called by:
SAVE:
JSR R5, SAVE
MOV R4, -(SP)
;R5 was pushed by the JSR
MOV R3, -(SP)
;R5 will be at the bottom
;of the stack
\
MOV R2, -(SP)
;R4, R3, R2, Rl, and RO
;in order
MOV Rl, -(SP)
;will be above it
MOV RO, -(SP)
;RO is at the top of the
;stack
JMP R5 ;R5 holds ‘the return ad-
;dress
The TST operation is equivalent to comparing the operand with 0, i.e.,
TST opr = CMP opr, #0
The only effect is to set the appropriate condition codes.
The following example illustrates a subroutine
stack.
to restore RO-R5 from the
REST: TST (SP) +
MOV (SP)+, RO
MOV (SP)+, Rl
MOV (SP)+, R2
MOV (SP)+, R3
MOV (SP)+, R4
RTS R5
;this increments the SP by 2
;the registers are restored
:in reverse order to that in
which
;they were put on the stack
;R5 is loaded into the PC
and the old R5 restored
The operation TST (SP)+ removes the top element on the stack. At the time
it is used, the top element holds the contents of R5 that were saved by the
call to REST. Since R5 is to be loaded with the value saved on the stack
by SAVE, this information is not needed.
3. Stacks, recursion, and
nesting
-The following subroutine converts
an unsigned binary integer to a string of typed ASCII characters. In
the routine, the remainders of successive divisions by 10 are saved
and then typed in reverse order.
The operation of the subroutine is to call a part of itself (begin-
ning with DECREM) repeatedly until a zero quotient is calculated
by an integer divide subroutine, IDIVR. At each iteration, the dividend
is divided by 10, the resulting quotient replaces the dividend, and
the remainder is pushed onto the processor stack. The processor
stack thus holds interleaved data (remainders) and control informa-
tion (return addresses from calls to DECPNT and DECREM) when
the quotient finally comes up as 0 and the branch is made to
DECTIY. The portion of the routine beginning at DEClTY then pops
a remainder from the stack, converts it to an ASCII character, types
it and then returns control to DECTTY (with RTS PC) until the stack
is reduced finally to its state immediately after the call to DECPNT.
29