The difficult part of this assignment is to add code to the incomplete kernel (in ~cs354-1/public/kernel.11) to implement getc, putc, and puts.
Several sample runs of the program might look like:
Enter a string : abcde The string forward : abcde The string backward: edcba Enter a string : 9 3 zzz The string forward : 9 3 zzz The string backward: zzz 3 9
~cs354-1/bin/handin11 filenamewhere filename is the file containing the source code.
Consider the following MAL program:
.data prompt: .asciiz "enter a letter: " .text la $9, prompt puts $9 getc $10 add $10, $10, 1 putc $10 .....After converting the MAL code using syscall instructions, the MAL program will look like:
.data prompt: .asciiz "enter a letter: " .text la $9, prompt li $2, 4 move $4, $9 syscall # puts $9 li $2, 12 syscall move $10, $2 # getc $10 add $10, $10, 1 li $2, 11 move $4, $10 syscall # putc $10 .......The syscall instruction is similar to a procedure call. Like a procedure call, arguments and results are passed in registers; and, after the syscall has finished, execution begins at the next instruction following the syscall.
A syscall is a request for service from the operating system. The section of the operating system which handles a syscall is known as the kernel.
A syscall differs from jal in a number of ways. There is no address specified in a syscall. The address of the subroutine called by a syscall is fixed at 0x80000080. Unlike a jal instruction, the return address of a syscall is stored in the EPC (exception program counter) rather than a general purpose register. It is also important to remember that registers $k0 and $k1 ($26 and $27) are reserved for the kernel and may be changed by a syscall.
Each syscall service is assigned an operation code. The operation codes for the syscall instructions which you will be implementing during the course of this assignment are:
syscall Operation code. instructions (value in $2) puts 4 putc 11 getc 12 done 10
The syscall instruction makes use of the general purpose registers to pass information to and return information from the kernel. The value of the operation code of the instruction to be executed by syscall is placed in register 2. Depending upong the instruction, a value is returned in $2 (as in the case of getc), or an additional value is passed in $4 (as in the cases of putc and puts).
For example,
To execute the syscall instructions on this simulator, you will need to add the file ~cs354-1/public/kernel.11 in the file with your MAL code.
This can be done using the UNIX cat command.
e.g. cat ~cs354-1/public/kernel.11 MAL_code > final_code.where MAL_code is the file with your MAL code, and final_code will be the resulting file.
The kernel.11 contains the code that will be run
whenever a syscall is executed. However, the