

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Assignment; Class: Assembly Language and Computer Organization; Subject: Computer Science/Computer Engineering; University: University of North Texas; Term: Unknown 1989;
Typology: Assignments
1 / 2
This page cannot be seen from the preview
Don't miss anything!


2.2 By lookup using the table in Figure 2.5 on page 62, 7fff fffahex = 0111 1111 1111 1111 1111 1111 1111 1010two = 2,147,483,642ten. 2.3 By lookup using the table in Figure 2.5 on page 62, 1100 1010 1111 1110 1111 1010 1100 1110two = cafe facehex.
sll $t0, $t3, 9 # shift $t3 left by 9, store in $t srl $t0, $t0, 15 # shift $t0 right by 15 2.15 Hence, the results from using if-else statements are better. 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< lw $a0, 40($sp) # restore parameter (num) lw $ra, 44($sp) # restore return address lw $fp, 48($sp) # restore frame pointer addi $sp, $sp, 52 # restore stack pointer jr $ra # return compare: addi $sp, $sp, -8 # move stack pointer sw $fp, 4($sp) # save frame pointer sw $ra, 0($sp) # save return address addi $fp, $sp, 4 # establish frame pointer jal sub # can jump directly to sub slt $v0, $v0, $zero # if sub(a,b) >= 0, return 1 slti $v0, $v0, 1 lw $ra, 0($sp) # restore return address lw $fp, 4($sp) # restore frame pointer addi $sp, $sp, 8 # restore stack pointer jr $ra # return sub: sub $v0, $a0, $a1 # return a-b jr $ra # return
add $t0, $zero, $zero # initialize running sum $t0 = 0 loop: beq $a1, $zero, finish # finished when $a1 is 0 add $t0, $t0, $a0 # compute running sum of $a sub $a1, $a1, 1 # compute this $a1 times j loop finish: addi $t0, $t0, 100 # add 100 to a * b add $v0, $t0, $zero # return a * b + 100