# CS232mp2sol - addi \$sp \$sp-4 sw \$ra 0(\$sp jal decodeAll lw...

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

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

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

View Full Document
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

## This note was uploaded on 04/28/2011 for the course CS 232 taught by Professor Kumar during the Spring '08 term at University of Illinois, Urbana Champaign.

### Page1 / 2

CS232mp2sol - addi \$sp \$sp-4 sw \$ra 0(\$sp jal decodeAll lw...

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

View Full Document
Ask a homework question - tutors are online