Assembly Language
Assembly Language
1
syscalls
• Syscalls are operations defined within the assembler
(not the processor)
• The syscall operation is dependent on the value in
$v0
• Read operations store the value back in $v0
week04-3.ppt 3
04/24/24
syscalls
Integers
li $a0,100
li $v0,1 # print an integer in $a0
syscall
li $a0,’a’
li $v0,11 # print a character in $a0
syscall
.data
str: .asciiz “Hello World”
.text
main:
li $v0, 4 # code for print_str
la $a0, str # argument
syscall # executes print_str
Inclass excercise
li $v0,10 #exit
syscall
Example
• Write an assembly program to prompt the user for two numbers and
print the sum of the two numbers
14
example 1: add two numbers
Assembler directive
starts with a dot
.text # Code area starts here
main:
li $v0, 5 # read number into $v0
syscall # make the syscall read_int
move $t0, $v0 # move the number read into $t0
# end of main
read_string $v0 = 8 $a0 = address to place string, $a1 = max string length reads standard input into address in $a0
$v0= address of allocated memory
sbrk $v0 = 9 $a0 = number of bytes required
Allocates memory from the heap
exit $v0 = 10