Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

CS 271 Homework 2: Array Comparison Exercises, Assignments of Computer Architecture and Organization

Solutions to various exercises from cs 271 homework 2, including exercises related to array comparison and addressing in mips assembly language. The document also discusses a limitation of pc-relative addressing and a potential solution.

Typology: Assignments

Pre 2010

Uploaded on 08/18/2009

koofers-user-j7b
koofers-user-j7b 🇺🇸

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 271 Homework 2
Fall 2008
IPFW
Exercises 2.2, 2.6, 2.20, 2.30, 2.38
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.6
sll $t0, $t3, 9 # shift $t3 left by 9, store in $t0
srl $t0, $t0, 15 # shift $t0 right by 15
2.20 Figure 2.21 shows decimal values corresponding to ACSII characters.
2.30
sll $a2, $a2, 2 # max i= 2500 * 4
sll $a3, $a3, 2 # max j= 2500 * 4
add $v0, $zero, $zero # $v0 = 0
add $t0, $zero, $zero # i = 0
outer: add $t4, $a0, $t0 # $t4 = address of array 1[i]
lw $t4, 0($t4) # $t4 = array 1[i]
add $t1, $zero, $zero # j = 0
inner: add $t3, $a1, $t1 # $t3 = address of array 2[j]
lw $t3, 0($t3) # $t3 = array 2[j]
bne $t3, $t4, skip # if (array 1[i] != array 2[j]) skip $v0++
addi $v0, $v0, 1 # $v0++
skip: addi $t1, $t1, 4 # j++
bne $t1, $a3, inner # loop if j != 2500 * 4
addi $t0, $t0, 4 # i++
bne $t0, $a2, outer # loop if i != 2500 * 4
The code determines the number of matching elements between the two arrays and returns this
number in register $v0.
2.38 The problem is that we are using PC-relative addressing, so if that address is
too far away, we won’t be able to use 16 bits to describe where it is relative to the
PC. One simple solution would be
here: bne $s0, $s2, skip
j there
skip:
there: add $s0, $s0, $s0
This will work as long as our program does not cross the 256MB address boundary described in the
elaboration on page 98.

Partial preview of the text

Download CS 271 Homework 2: Array Comparison Exercises and more Assignments Computer Architecture and Organization in PDF only on Docsity!

CS 271 Homework 2

Fall 2008

IPFW

Exercises 2.2, 2.6, 2.20, 2.30, 2.

2.2 By lookup using the table in Figure 2.5 on page 62,

7fff fffahex = 0111 1111 1111 1111 1111 1111 1111 1010 two

= 2,147,483,642ten

sll $t0, $t3, 9 # shift $t3 left by 9, store in $t srl $t0, $t0, 15 # shift $t0 right by 15

2.20 Figure 2.21 shows decimal values corresponding to ACSII characters.

sll $a2, $a2, 2 # max i= 2500 * 4 sll $a3, $a3, 2 # max j= 2500 * 4 add $v0, $zero, $zero # $v0 = 0 add $t0, $zero, $zero # i = 0 outer: add $t4, $a0, $t0 # $t4 = address of array 1[i] lw $t4, 0($t4) # $t4 = array 1[i] add $t1, $zero, $zero # j = 0 inner: add $t3, $a1, $t1 # $t3 = address of array 2[j] lw $t3, 0($t3) # $t3 = array 2[j] bne $t3, $t4, skip # if (array 1[i] != array 2[j]) skip $v0++ addi $v0, $v0, 1 # $v0++ skip: addi $t1, $t1, 4 # j++ bne $t1, $a3, inner # loop if j != 2500 * 4 addi $t0, $t0, 4 # i++ bne $t0, $a2, outer # loop if i != 2500 * 4

The code determines the number of matching elements between the two arrays and returns this

number in register $v0.

2.38 The problem is that we are using PC-relative addressing, so if that address is

too far away, we won’t be able to use 16 bits to describe where it is relative to the

PC. One simple solution would be

here: bne $s0, $s2, skip j there skip: … there: add $s0, $s0, $s

This will work as long as our program does not cross the 256MB address boundary described in the

elaboration on page 98.