go to previous page   go to home page   go to next page hear noise


This is how the program returns control to the operating system without expecting to get control back.

Print String

The exit service is normally used when the program is finished. A real computer is always running, and control has to go somewhere, so this is how control is sent back to the OS. The OS then goes about its own tasks, possibly starting another user program. (On SPIM, the exit service stops all execution.)

The print string SPIM exception handler service prints a null terminated string to the simulated monitor. The address of the string is loaded into register $a0. Typically the string is in the data section of memory.

li      $v0,4       # code 4 == print string
la      $a0,string  # $a0 == address of the string
syscall             # Ask the operating system to 
                    # perform the service.
    . . . .

string: .asciiz      "Hello SPIM!\n"

The print string service sends bytes to the simulated monitor one by one starting with the byte pointed to by $a0. It continues until it hits a null byte. It does not check that the bytes are ASCII. You will print garbage if you point $a0 at the wrong location.

If you want to advance to a new line, use the newline character '\n' inside or at the end of the string.

Bug Alert: notice how the la instruction is used to load the address of the first byte of the string to be printed.

Bug Alert: values in t registers may be altered by the operating system service, for this and other services.


Fill in the blanks.

  $v0,4       # code 4 == print string
  $a0,message # $a0 == address of the string
              # Ask the operating system to 
                       # perform the service.
    . . . .

message: .asciiz      "Intruder Alert!\n"