I/O with syscalls in SPIM

  • Reading an integer
            li      $v0, 5
    	syscall
    	move    $s0, $v0
    

    Result is stored in $s0.

  • Printing an integer
            li      $v0, 1
    	move    $a0, $s0
    	syscall
    
  • Reading a string
                    .data
    string:         .byte   0:20
    		.text
    		li      $v0, 8
    		la      $a0, string
    		li      $a1, 20
    		syscall
    

    Result is stored in the memory pointed to by 'string'.
    The result includes all characters until a newline is encountered or until 19 characters have been read. (The final character is used for null termination, like in C.)

  • Printing a string
    		.data
    string:		.asciiz "Hello World"
    		.text
                    li      $v0, 4
    		la      $a0, string
    		syscall