! + Syscalls have number in %g1, options in %o0,%o1,... ! Result returned in %o0 ! Linux syscall is called by "ta 0x10" .equ SYSCALL_EXIT,1 .equ SYSCALL_WRITE,4 .equ STDOUT,1 .globl _start _start: set data_region,%i0 set 0xae60,%g4 ld [ %i0 + 0x4 ], %g3 inc %g3 cmp %g4,%g3 ble less_equal nop ba greater nop less_equal: set lessequal_string,%o1 ba write_stdout nop greater: set greater_string,%o1 #================================ # WRITE_STDOUT #================================ # %o1 has string write_stdout: set SYSCALL_WRITE,%g1 ! Write syscall in %g1 set STDOUT,%o0 ! 1 in %o0 (stdout) set 0,%o2 ! 0 (count) in %o2 str_loop1: ldub [%o1+%o2],%l0 ! load byte cmp %l0,%g0 ! compare against zero bnz str_loop1 ! if not nul, repeat # BRANCH DELAY SLOT inc %o2 ! increment count dec %o2 ! correct count ta 0x10 ! run the syscall exit: mov 0,%o0 ! exit value mov SYSCALL_EXIT,%g1 ! put the exit syscall number in g1 ta 0x10 ! and exit !=========================================================================== .data !=========================================================================== data_region: .int -1,-1 greater_string: .ascii "Greater\n\0" lessequal_string: .ascii "Less Equal\n\0"