CS232mp2sol - addi $sp, $sp, -4 sw $ra, 0($sp) jal...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
decodeAll: # a0 = base, a1 = offset, a2 = val add $t0, $a0, $a1 lb $t1, 0($t0) # t1 = base[offset] bne $t1, $0, right_rec lb $t1, 1($t0) # t1 = base[offset+1] bne $t1, $0, left_rec # base case move $a0, $a2 addi $sp, $sp, -4 sw $ra, 0($sp) jal decode lw $ra, 0($sp) addi $sp, $sp, 4 jr $ra left_rec: add $a1, $a1, $t1 # a1 = offset + base[offset+1] sll $a2, $a2, 1 # a2 = 2*val addi $sp, $sp, -4 sw $ra, 0($sp) jal decodeAll lw $ra, 0($sp) addi $sp, $sp, 4 jr $ra right_rec: bne $t1, 1, double_rec lb $t1, 1($t0) # t1 = base[offset+1] add $a1, $a1, $t1 # a1 = offset + base[offset+1] sll $a2, $a2, 1 addi $a2, $a2, 1 # a2 = 2*val + 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: addi $sp, $sp, -4 sw $ra, 0($sp) jal decodeAll lw $ra, 0($sp) addi $sp, $sp, 4 jr $ra double_rec: lb $t1, 0($t0) # t1 = base[offset] lb $t2, 1($t0) # t2 = base[offset+1] add $t2, $a1, $t2 # t2 = offset + base[offset+1] add $a1, $a1, $t1 # a1 = offset + base[offset] sll $a2, $a2, 1 # a2 = 2*val addi $sp, $sp, -16 sw $a0, 0($sp) sw $t2, 4($sp) sw $a2, 8($sp) sw $ra, 12($sp) jal decodeAll lw $a0, 0($sp) lw $a1, 4($sp) lw $a2, 8($sp) lw $ra, 12($sp) addi $sp, $sp, 16 addi $a2, $a2, 1 # a2 = 2*val + 1 addi $sp, $sp, -4 sw $ra, 0($sp) jal decodeAll lw $ra, 0($sp) addi $sp, $sp, 4 jr $ra...
View Full Document

Page1 / 2

CS232mp2sol - addi $sp, $sp, -4 sw $ra, 0($sp) jal...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online