Skip to content

Instantly share code, notes, and snippets.

@wit543
Created October 19, 2015 12:38
Show Gist options
  • Save wit543/fd11569791ce4f9e9880 to your computer and use it in GitHub Desktop.
Save wit543/fd11569791ce4f9e9880 to your computer and use it in GitHub Desktop.
.data
helloworld: .asciiz "Hello World"
line: .asciiz "\n"
.text
main:
j looping
print_hello_world:
la $a0, helloworld
li $v0, 4 # 4 print_string
syscall
la $a0, line
li $v0, 4
syscall
read_and_print_int:
li $v0, 5 # 5 read_int
syscall
move $a0, $v0
li $v0, 1 # 1 print_int
syscall
read_add_and_print:
# input 1
li $v0, 5 # 5 read_int
syscall
move $t0, $v0
# input 2
li $v0, 5
syscall
move $t1, $v0
# add them together
add $t3, $t0, $t1
sub $t4, $t0, $t1 # t0 - t1
mul $t5, $t0, $t1 # t0 * t1
div $t6, $t0, $t1 # t0 / t1
# print
move $a0, $t3
li $v0, 1
syscall
if_else:
# input 1
li $v0, 5 # 5 read_int
syscall
move $t0, $v0
# input 2
li $v0, 5
syscall
move $t1, $v0
# if (t0 > 25 || t1 > 30)
li $t9, 25
bgt $t0, $t9, if
bgt $t1, $t8, if
j else
if:
la $a0, helloworld
li $v0, 4
syscall
j endif
else:
# blah
endif:
# blah blah
looping:
li $t0, 1
loop:
bgt $t0, 30, loop_end
li $v0, 1
move $a0, $t0
syscall
li $v0, 4
la $a0, line
syscall
add $t0, $t0, 1
j loop
loop_end:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment