Last active
February 1, 2019 01:12
-
-
Save simonewebdesign/e8962bdb6792b3ecbc97e27db73e1e09 to your computer and use it in GitHub Desktop.
add 1 and 2 in MIPS Assembly https://www.cs.ucsb.edu/~franklin/64/lectures/mipsassemblytutorial.pdf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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