MIPS Assembly Language System Calls
MIPS Assembly Language System Calls
MIPS Assembly Language System Calls
LAB 4 Week-09
System call is used to communicate with the system for reading from keyboard or writing
to the screen. A System call requires some parameter to be passed in a particular register and a
request/function number (or service code) to be passed in register $v0.
.data
mesg1: .asciiz “My Name is \n“ # fill the blank with your name
.text
.globl main
main:
li $v0, 4 # Load immediate $v0 with value 4
la $a0, mesg1 # $a0 points to base address of string array mesg1
syscall
li $v0, 10 # prepare to exit
syscall # Exit to OS
Run this program by pressing GO (F5). Show the execution of your program to the Instructor
and get your handout marked.
What do you see in the CONSOLE window?
My Name is Sidra Malik
Show the execution of your program to the Instructor and get your handout marked.
$v0.
Since we have provided the code for Exercise 3 to you, the grading of this exercise will be done
by testing your understanding of the given program through a viva. You are also required to
show your .asm/.s code and its PSCPIM execution to the Instructor during the lab and get
your handout marked.
Sample Code:
(Taken from the book: “MIPS Assembly Language Programming” by Robert L. Britton)
#######################################################################
# Cross References:
# v0: N, t0: Sum
#######################################################################
.data
Prompt: .asciiz “\n Please Input a value for N = (−1 to end): “
Result: .asciiz “\n The sum of the integers from 1 to N is: ”
Bye: .asciiz “\n **** Good bye – Have a good day****”
.text
.globl main
main:
Li $v0, 4 # system call code for print string
la $a0, Prompt # load address of string Prompt into $a0
syscall # print the prompt message
li $v0, 5 # system call code for Read Integer
syscall # reads the value of N into $v0
ble $v0, $zero, End # branch to end if $v0 <= 0
Li $t0, 0 # clear register $t0 to 0
Loop:
add $t0, $t0, $v0 # sum of integers in register $t0
addi $v0, $v0, −1 # summing integers in reverse order
bne $v0, $zero, Loop # branch to loop if $v0 is != 0