Skip to content

Instantly share code, notes, and snippets.

@simonewebdesign
Last active February 1, 2019 01:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simonewebdesign/e8962bdb6792b3ecbc97e27db73e1e09 to your computer and use it in GitHub Desktop.
Save simonewebdesign/e8962bdb6792b3ecbc97e27db73e1e09 to your computer and use it in GitHub Desktop.
.text
main:
li $t1, 1 # load immediate value 1 into $t1
add $t0, $t1, 2 # $t1 + 2 and put result into $t0
li $v0, 10 # 10 is the the exit syscall num
syscall
# spim
# load "add.asm"
# run
# (spim) print $t1
# Reg 9 = 0x00000001 (1)
# (spim) print $t0
# Reg 8 = 0x00000003 (3)
# (spim) print $t2
# Reg 10 = 0x00000000 (0)
# (spim) exit
# A program that computes and prints the sum
# of two numbers specified at runtime by the user.
# Registers used:
# $t0 - used to hold the first number.
# $t1 - used to hold the second number.
# $t2 - used to hold the sum of $t1 and $t2.
# $v0 - syscall parameter.
# $a0 - syscall parameter.
main:
li $v0, 5 # read_int syscall
syscall
move $t0, $v0
li $v0, 5 # read_int syscall
syscall
move $t1, $v0
add $t2, $t0, $t1
move $a0, $t2
li $v0, 1 # print_int syscall
syscall
li $v0, 10 # exit syscall
syscall
# Example usage
# (spim) load "add2.mips"
# (spim) run
# 1
# 2
# 3(spim) run
# 4
# 5
# 9(spim) exit
# Hello World!
# Registers used:
# $a0 - syscall param -- the string to print.
# $v0 - syscall param and return value.
# Example:
# (spim) load "hello.asm"
# (spim) run
# Hello World
.text
main:
la $a0, hello_msg # load the addr of hello_msg into $a0
li $v0, 4 # print_string syscall
syscall
li $v0, 10 # exit syscall
syscall
# Data for the program:
.data
hello_msg: .asciiz "Hello World\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment