bash
.data ! We will call the c function printf, we need strings to feed it. msg0: .ascii "The number is '%d'\n\0" .text ! all c programs mush have a main .global printf .global main
main: ! Save the registers from the calling routine ! more on this later as well save %sp, -64, %sp
! here is the program, c = a + b set 3,%l0 ! a = 3 set 4,%l2 ! b = 4 add %l0,%l2, %l3 ! c = a+b
! ! This section calls the c printf routine. ! printf("The number is '%d'\n\0", number); ! We will talk more about subroutine calls eventually ! For now, ! o0 contains the first parameter ! o1 contains the second parameter ! Call calls the routine ! There is a bds following the call ! set msg0, %o0 ! make msg0 a parameter to printf mov %l3, %o1 ! make the value of r4 a parameter to printf call printf ! call printf nop ! branch delay slot
! again, we will talk about what is going on here later, for now do this. mov 1, %g1 ! get ready to quit ta 0 ! exit
$ gcc -o one one.s
$ one