# as -o hello.o hello.s ; ld -o hello hello.o .equ SYSCALL_EXIT,1 .equ SYSCALL_WRITE,4 .equ STDIN,0 .equ STDOUT,1 .equ STDERR,2 .globl _start _start: br $27,0 # fake branch, to grab the location # of our entry point ldgp $gp,0($27) # load the GP proper for our entry point # this does automagic stuff... # gp is used for 64-bit jumps and constants # so if you use "la" and the like it will # load from gp for you. lda $17,hello_string br $26,write_stdout #================================ # Exit #================================ exit: clr $16 # 0 exit value mov SYSCALL_EXIT,$0 # put the exit syscall number in v0 callsys # and exit #================================ # WRITE_STDOUT #================================ # $17 has string # $1 is trashed write_stdout: ldil $0,SYSCALL_WRITE # Write syscall in $0 ldil $16,STDOUT # 1 in $16 (stdout) clr $18 # 0 (count) in $18 str_loop1: addq $17,$18,$1 # offset in $1 ldbu $1,0($1) # load byte addq $18,1,$18 # increment pointer bne $1,str_loop1 # if not nul, repeat subq $18,1,$18 # correct count callsys # Make syscall ret $26 # return #=========================================================================== .data #=========================================================================== hello_string: .ascii "Hello World\n\0"