- Assembly code goes in a file with the extension .s
- one.s
- There is some stuff here that we will eventually get to, but not yet
- Comments start with a ! and completes the line
- The first part
.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
- The start of the program
main:
! Save the registers from the calling routine
! more on this later as well
save %sp, -64, %sp
- Some acutal calculations
! here is the program, c = a + b
set 3,%l0 ! a = 3
set 4,%l2 ! b = 4
add %l0,%l2, %l3 ! c = a+b
- Call the printf function
!
! 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
- Exit the program
! 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
- The entire code is here
- Compile the program
$ gcc -o one one.s
- If everything worked out, you should be able to run the program now
$ one