next up previous
Next: Example: MAL/TAL Differences Up: TAL Previous: Load/Store Instructions

I/O Instructions

None of the MAL I/O instructions are implemented as instructions in TAL. The operating system of the computer provides all input and output functions through a set of procedures. A system procedure is executed using the TAL syscall (system call) instruction.

Parameters are used to tell the O/S what function syscall is to perform. The system procedures use register $2 ($v0) to specify the type code for the function. Additional parameters are passed in registers $a0-$a3 and $f12. System procedures which return values use $v0 and $f0 for floating point results.

The type codes and parameters are system dependent. In the SPIM simulator, the following system procedures are defined.

tabular191

To perform the MAL puti function, register $v0 is loaded with type code 1 and the integer to be printed is placed in $a0: The MAL instruction:

        puti    $12

would be synthesized in TAL as:

        addi    $v0, $0, 1   # type code = puti
        add     $a0, $12, $0 # move $4, $12
        syscall              # call system procedure

The MAL instruction:

        geti    $12

would be synthesized in TAL as:

        addi    $v0, $0, 5   # type code = geti
        syscall              # call system procedure
        add     $12, $v0, $0 # move result to $12

To print or read a string, the address of the string is passed as a parameter. The following MAL code uses puts to print "Hello World":

        .data
Hello:  .asciiz "Hello World\n"
        .text
        puts    Hello

The puts instruction is implemented using syscall as:

        addi    $v0, $0, 4  # type code = puts
        la      $a0, Hello  # address of string
        syscall             # call system procedure

The MAL done macro is also implemented as a system procedure as follows:

        addi    $v0, $0, 10 # type code = done
        syscall             # call system procedure

Note that the use of $v0 for the type code precludes the use of $v0 ($2) in any MAL I/O instruction. For example,

        puti    $2

will always print the value 1, which is the type code for the puti instruction.

Refer to the SPIM Simulator Reference Manual for additional information on the use of system procedures.



CS 301 Class Account
Mon Dec 1 23:34:28 AST 1997