A Sample Program Using the Runtime Stack
The following program shows how to use the runtime stack by reversing a string.
The memory addressing mode str( $t1 )
means
address = address of str
+ content of $t1
Therefore, you can use this method to access each byte of the string str
starting from $t1=0
till str($t1) == 0
.
Reverse and Output a User-Supplied String |
|
An Execution Example |
12345
54321
|
†Note that there is a blank line between the input and output.
It is because according to the definition of the
read_string service of
syscall
:
If fewer than n
-1 characters are in the current line, it reads up to and including the newline (integer 10) and terminates the string with a null character.
So the newline is part of input.