Assn4Soln - CDA 3101 Assignment 4 Solution Due in class on...

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

View Full Document Right Arrow Icon
CDA 3101 Assignment 4 Solution Due in class on Thursday, Oct. 5 Turn hardcopy in class, stapled, with your name and “CDA 3101 Assignment 4” clearly written on it. For programs, submit a printout with your hardcopy, in class. Also, submit the program for Problem 4 below electronically, via WebCT Assignment Tool. You must use the WebCT Assignment Tool to submit your code; you cannot submit your code using email. 1. (15 points) Problem 2.15 from the textbook. set_array: addi $sp, $sp, -52 # move stack pointer sw $fp, 48($sp) # save frame pointer sw $ra, 44($sp) # save return address sw $a0, 40($sp) # save parameter (num) addi $fp, $sp, 48 # establish frame pointer add $s0, $zero, $zero # i = 0 addi $t0, $zero, 10 # max iterations is 10 loop: sll $t1, $s0, 2 # $t1 = i * 4 add $t2, $sp, $t1 # $t2 = address of array[i] add $a0, $a0, $zero # pass num as parameter add $a1, $s0, $zero # pass i as parameter jal compare # call compare(num, i) sw $v0, 0($t2) # array[i] = compare(num, i); addi $s0, $s0, 1 bne $s0, $t0, loop # loop if i<10 lw $a0, 40($sp) # restore parameter (num) lw $ra, 44($sp) # restore return address lw $fp, 48($sp) # restore frame pointer
Background image of page 1

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

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

Page1 / 5

Assn4Soln - CDA 3101 Assignment 4 Solution Due in class on...

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