# system calls for Tiger, when running on SPIM # # $Id: sysspim.s,v 1.1 2002/08/25 05:06:41 shivers Exp $ .globl malloc .ent malloc .text malloc: # round up the requested amount to a multiple of 4 add $a0, $a0, 3 srl $a0, $a0, 2 sll $a0, $a0, 2 # allocate the memory with sbrk() li $v0, 9 syscall j $ra .end malloc .data .align 4 getchar_buf: .byte 0,0 .text getchar: # read the character la $a0, getchar_buf li $a1, 2 li $v0, 8 syscall # return it lb $v0, ($a0) j $ra .data .align 4 putchar_buf: .byte 0,0 .text putchar: # save the character so that it is NUL-terminated la $t0, putchar_buf sb $a0, ($t0) # print it out la $a0, putchar_buf li $v0, 4 syscall j $ra .text # just prints the format string, not the arguments printf: li $v0, 4 syscall j $ra .text exit: li $v0, 10 syscall