Anda di halaman 1dari 6

EE 2310 Worksheet #5 Test #2 Review

MIPS Registers
.data
n: .word
p: .word
q: .word
r: .word
s: .word
t: .word
u: .word
v: .word
w: .word
x: .word
y: .word
z: .word
str:
.asciiz
"hello
world\n"

R0 (r0):
0x00000000
R1 (at):
0x10010000
R2 (v0):
0x00000000
R3 (v1):
0x0000000c
R4 (a0):
0x00000023
R5 (a1):
0x10010010
R6 (a2):
0x0000000a
R7 (a3):
0x00000050

R8 (t0):
0x00000000
R9 (t1):
0x0000ffff
R10 (t2):
0x00000000
R11 (t3):
0x10010020
R12 (t4):
0x10010030
R13 (t5):
0x10010020
R14 (t6):
0x80000010
R15 (t7):
0xffff0000

R16 (s0):
0xff00ff00
R17 (s1):
0x00000000
R18 (s2):
0x00000023
R19 (s3):
0x10010000
R20 (s4):
0x00400020
R21 (s5):
0x00000000
R22 (s6):
0x800c1001
R23 (s7):
0x00000010

R24 (t8):
0x00000000
R25 (t9):
0x00000000
R26 (k0):
0x00000000
R27 (k1):
0x00000000
R28 (gp):
0x10008000
R29 (sp):
0x7fffeff0
R30 (s8):
0x00000000
R31 (ra):
0x00400060

Data
[0x10000000]...[0x1000fffc] 0x00000000
[0x10010000] 0x5350494d 0x20697320
[0x10010010] 0x2073696d 0x756c6174
[0x10010020] 0x6561726e 0x5350494d
[0x10010030] 0x68656c6c 0x6f20776f
[0x10010040] 0x726f6772 0x00000000
[0x10010050] 0xf7f7f7f7 0xf7f7f7f7
[0x10010060]...[0x10020000] 0x00000000

0x61207573
0x6f722066
0x4d495053
0x726c640a
0x00000000
0xf7f7f7f7

0x6566756c
0x6f72206c
0x20617373
0x00000000
0x6e642063
0xf7f7f7f7

Use the data declaration, SPIM memory dump, and MIPS register readouts above as
directed in the problems starting on the following page. Note: If a register or memory
location is changed in any problem, the change DOES NOT CARRY OVER to another
problem!
1. After: lw $t0, w, what are the contents of $t0?

0x 6561 726e

2. After: sw $s0, w, (a) what are the contents of memory location w?

0x ff00 ff00

(b) at what real memory address is w?

0x 1001 0020

3. After: lw $t0, 12($a1), what are the contents of $t0?

0x 6f72 206c

4. After: srl $t0, $ra, 12, what are the contents of $t0?

0x 0000 0400

5. After: sra $t0, $s6, 16, what are the contents of $t0?

0x ffff 800c

6. After: rol $t0, $t7, 20, what are the contents of $t0?

0x 000f fff0

7. After: lw $t6, 16($t4); ror $t6, $t6, 16, what are the contents of $t6? 0x 6772 726f
8. After completion of: jr $s4, what are the contents of the PC? 0x 0040 0020 (or 24)
9. After: ror $t0, $sp, 14; sra $t0, $t0, 6 what are the contents of $t0?

0x feff 07ff

10. After: lw $t0, w; lw $t1, x; slt $t2, $t1, $t0 what is in $t2?

1____

11. After: sgt $t0, $a0, $t6 what is in $t0?

1____

12. After: bgt $v1, $a2, go is the branch to go taken?

Yes___

13. After: lw $t7, 80($s3); bgtz $t7, go is the branch to go taken?

No

14. The program at the right inputs a number from


the keyboard, prints it to the console, stores it in
location data1, and halts. Unfortunately, it is
broken. Fix the two incorrect instructions next to
the current line of text in each case, and explain
below what you did if more information is
required to make that clear.
Errors:
(1) Should be li $v0, 5
(2) Should be li $v0, 1

.data
data1: .space 4
#
.text
main: li $v0, 1
syscall
sw $v0, data1
move $a0, $v0
li $v0, 4
syscall
done: li $v0,10
syscall

(1)

(2)

15. Compose a short program in the space on the


right that will square a number (data1) and check
to see that it is between 255 (0xff) and 65535 (0x
ffff). If between 0xff and 0xffff, it stores the
number in data2 and jumps to go. If greater
than 0xffff or less than 0xff, it stores 0 in data2
and jumps to go. The number data1 is stored
in the proper location by another routine you do
not have to be concerned with.

.data
data1: .word 0
data2: .word 0
.text
main: lw $t0, data1
mul $t0, $t0, $t0
bgt $t0, 0xffff, zero
blt $t0, 0xff, zero
sw $t0, data2
j done
zero:
done:

16. Another program stores an asciiz character in char.


Devise a short program to do the following: (1)
determine whether the character is the letter a
(which is ASCII 0x 61), (2) if it is an a, simply
leave in location char and jump to done. If it
is not letter a, store a 0 in byte location char
and jump to done. For this programming
exercise, specifically use a set instruction to
indicate in $t1 whether the character is an a, and
then branch on the condition in $t1 to complete the
function and jump to done.

17. Loop Problem: In the space to the right, write a brief


loop program that will search through the ASCII
sequence hello world\n and capitalize all the letters,
then print it out.

char:
main:

over:

sw $0, data2
j go

.data
.space 1
.text
lb $t0, char
seq $t1, $t0, 0x61
bnez $t1, over
sb $t1, char
j done

.text
main: la $t0,str
go:
lb $t1,($t0)
beqz $t1,print
beq $t1,0x20,nxt
beq $t1,0x0a,nxt
sub $t1,$t1,0x20
sb $t1,($t0)
nxt:
addi $t0,$t0,1
j go
print:

str:

la $a0,str
li $v0,4
syscall
li $v0,10
syscall
.data
.asciiz hello world\n

18. Program Analysis:


Program Data
Declaration
.data
n: .word
p: .word
q: .word
r: .word
s: .word
t: .word
u: .word
v: .word
w: .word
x: .word
y: .word
z: .word
str: .space 16

MIPS Register Readouts


R0 (r0):
0x00000000
R1 (at):
0x10010000
R2 (v0):
0x00000000
R3 (v1):
0x0000000c
R4 (a0):
0x00000023
R5 (a1):
0x10010010
R6 (a2):
0x0000000a
R7 (a3):
0x00000050

R8 (t0):
0x00000000
R9 (t1):
0x0000ffff
R10 (t2):
0x00000000
R11 (t3):
0x10010020
R12 (t4):
0x10010030
R13 (t5):
0x10010020
R14 (t6):
0x80000010
R15 (t7):
0xffff0000

R16 (s0):
0xff00ff00
R17 (s1):
0xff03f77a
R18 (s2):
0x00000023
R19 (s3):
0x10010000
R20 (s4):
0x00400020
R21 (s5):
0x000000ff
R22 (s6):
0x800c1001
R23 (s7):
0x00000010

R24 (t8):
0x00000000
R25 (t9):
0x00000000
R26 (k0):
0x00000000
R27 (k1):
0x00000000
R28 (gp):
0x10008000
R29 (sp):
0x7fffeff0
R30 (fp):
0x00000000
R31 (ra):
0x00400060

Data Memory
[0x10010000]
[0x10010010]
[0x10010020]
[0x10010030]
[0x10010040]
[0x10010050]

0x5350494d
0x2073696d
0xc561726e
0x00000000
0x726f6772
0xf7f7f7f7

0x20697320
0x756c6174
0x9350494d
0x00000000
0x80f9000b
0xf7f7f7f7

0x61207573
0x6f722066
0x4d495033
0x00000000
0xfef00006
0xf7f7f7f7

The program at the right is a loop that loads data words


starting at the location indicated tests them. For certain
values of data, the 32-bit word is output to the console.
For some values, the data is discarded. When the
program encounters a certain condition in the data, it
stops. Please answer the following questions about the
program:
What range of values is the program outputting?
-- Numbers < 0.

0x6566756c
0x6f72206c
0x20617373
0x00000000
0x00000000
0xf7f7f7f7

.text
main: la $t0,s
loop: lw $a0,($t0)
beqz $a0,done
bgtz $a0,add1
li $v0,1
syscall
add1: addi $t0,$t0,4
j loop
done: li $v0,10
syscall

From what memory location is the first data word


loaded (in hex)?
-- 0x 1001 0010.

What causes the program to halt?

What does the program do when it encounters a positive number?


-- Skips it and gets the next word.

How many data words are output?

-- Encountering a 0.

-- Two.

Sequential Logic
19. The counter below counts in an unusual cycle, so simply finding m-1 wont help you in this case.
Using the K-maps and count charty, find the Boolean expressions for Ty and Tx (clearly, Tz = 1).
With those, you can determine the Ts at count 0, then let the clock tick. You can then determine the
Ts at count 1 and repeat, etc. using this method, you can find the count cycle. You will eventually
discover some dont cares.

yz

Ty
x

00
0 0

01
0

1 1

11
0

0X 1X

Ty xz yz

and

yz

Tx

10
1

Tx y z

x
0
1
1
0
0
0
0
Etc.

00
0 1

01
0

1 1

11
0

y
0
0
0
1
1
0
0

Count
z Tx Ty
0
1
0
1
0
0
0
0
1
1
0
0
0
1
1
1
0
0
0
1
0

Tz
1
1
1
1
1
1
1

10
0

0
0X
X

The counter counts mod-6 BACKWARDS.

20. Develop a timing diagram for the MUX on the chart shown below. Plot the timing of FFs x, y, and z,
and also the MUX Out signal.

"1"
T

z
C

y
C

x
C

MUX Out

Reset
Clock

Actual
Counting
Cycle

A
B

MUX Out

Stage x
Stage y
Stage z

Clock

10

11

12

13

14

Actual
1
Counting
Cycle

Anda mungkin juga menyukai