Skip to content

Instantly share code, notes, and snippets.

@giuscri
Created June 27, 2017 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giuscri/07b2f2bd17d8afeed0345c343497a464 to your computer and use it in GitHub Desktop.
Save giuscri/07b2f2bd17d8afeed0345c343497a464 to your computer and use it in GitHub Desktop.
.data
A:
.space 16
B:
.space 16
c:
.word 0
.text
main:
# c = 2
la $t0, c
li $s0, 2
sw $s0, 0($t0)
# A[] = {-1, -1, 1, 4}
la $s1, A
li $t0, -1
sw $t0, 0($s1)
li $t0, -1
sw $t0, 4($s1)
li $t0, 1
sw $t0, 8($s1)
li $t0, 4
sw $t0, 12($s1)
# B[] = {-1, 6, -1, -1}
la $s2, B
li $t0, -1
sw $t0, 0($s2)
li $t0, 6
sw $t0, 4($s2)
li $t0, -1
sw $t0, 8($s2)
li $t0, -1
sw $t0, 12($s2)
# t0 = A[c]
add $t0, $s0, $zero
sll $t0, $t0, 2
add $t0, $s1, $t0
lw $t0, 0($t0)
# t0 = B[A[c]]
sll $t0, $t0, 2
add $t0, $s2, $t0
lw $t0, 0($t0)
# t0 = c * (B[A[c]] + c)
add $t0, $t0, $s0
mul $t0, $s0, $t0
# t1 = 2*c - 1
add $t1, $s0, $zero
sll $t1, $t1, 1
sub $t1, $t1, 1
# t1 = A[2*c - 1]
sll $t1, $t1, 2
add $t1, $s1, $t1
lw $t1, 0($t1)
# t2 = &(A[c - 1])
add $t2, $s0, $zero
sub $t2, $t2, 1
sll $t2, $t2, 2
add $t2, $s1, $t2
# *t2 = t0 / t1
div $t3, $t0, $t1
sw $t3, 0($t2)
jr $ra
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment