Professional Documents
Culture Documents
Computer Science 37 HW 6
Computer Science 37 HW 6
th
PROBLE
(10
!#"%$'&%(%"%$')*"%$,+-*!%./10213!4
5!%
67#!8.5%
67#9
: 8/;<=/;>6?/; :@: A%1/BC8$
DFE@GIHJLKNMPOKPQRHSPJUT
OK#QIVJ
VJYMPZIH.Z[
PROBLE
-WLXW
ath \]^FI,
_
`a/P
3b93.2 : .(cde : e!If>!43!g6/; : 196?e>/;4"%$,+)%(%hi3%83jckebhiC1CL91!
L13!g*!913%8#%%e : l%m/ncde%/0!%oqpr<!
6=ts%u%-%v$
a)
b)
c)
d)
$
f/;*.g"%$'"4x
w f/;*.g"%$'u4x H2$
w f/;*.g"%$'&4x H2$
w
.g"%$')4x H2$
Exerci
H2
yFE@GIHJLKNMPOKPQRHSPJUz|{PVH.O
VJYMPZIHlZI[#ZIHlS
W>XIW
\l}^R
PROBLE
`a/P
3b93.2 : .(cde : e!If>!43!g6/; : 196?e>/;4"%$'s%s%(%hi3%83jckebhiC1CL91!
L13!g*!913%8#%%e : l%m/ncde%/0!%oqpr<!
6=ts%&%s%v$
f/;*.g"%$,+"4
a) w f/;*.g"%$,+u4x PH2$
b) w
H2
~FE@GIHJLKNMPOKPQRHSPJUz|{PVH.O
VJYMPZIHlZI[#ZIHlS
PROBLE
W>XIW
\ 10
f/;8.g"%$'%u4x
$45!/19c3!dcde%/<%/;>6/; : h/o!.(%6?521I1%<%e%I20%C%*ob9+-%w h/;%.(%hP13bh*C1C o%H2
!%hin5!Ce!.(%%91!413!g>g.
6 : %m9mcke%/<>/;>6?/. : $ : : 0!/
13!*kcde : e!m*C.-4/.;/5n+-%-%16e!e!Ph/.%43!C8413!g<%840%C%*o!$
3!g%%
o!C8?0!C%h|02e!;#2!.1%4N%!1(9ck
eC1o!4p8//;18!#/ : %198!
1I/.gC1C8%hA*!4e%<gcde8496?e%/;ge%
).
.data
#
!
#
SOURCE:
##$#%#&#'#(#)#*#
"
##$#%#&#'#(#)#*#
"
.
.
.
" ##$#%#&#'#(#)#*#
#
+
+
#
DEST:
.
+ &
.text
main:
addi
sw
sw
addiu
syscall
5 + +-:;+
+ =<+
.
+
7 77
>
#"
+ =< +
+ 7
"
?@ABCADEFGHIJG@KLBMHIGMGMNOBDPABDPLKLBQKJPBFIRMGSFILTGMKGM
HTKUVWKXIPHFKMHDAGMN-Y
+
-Z
%) -X01-hw4-5-lastname-Z
cs37@cs.dartmouth.edu
[
7
+
2.%)\
Standards "
O[PJ>VO,KPOKPQ \l]^F
PROBLE
f/;*.gu%$,+"4x
a) w f/;*.gu%$,+)4 H2.
b) w f/;*.gu%$'%s4x PH2.
c) w f/;*.gu%$' x H2.
d) w f/;*.gu%$'%&4x H2.
e) w f/;*.gu%$'s%-4x H2. xC.2/;9;l/413%8
0!*C%h 0!9;/.Pckeq18 : <%
f) w3%<%/.0%C $
H2.
clarification
:
J W HlO K H H.S#JUJ GZIz [PVJbTHZ HOKPQ
p
% v>3!gf : <%Cg!1 8#<!6%g"!+s
/0%/B*!31!/;$
Loop:
addi
addu
K [#ZQJP y
+(
+(
-4
-%( 8-%( .
+( /.%( % <
1
2
8-%(!p +v
sw
!#"$%&%'()%*$$,+-.$"0/1#+!2"/4325%'5"67$(80$9+!5:0;<=#>
bne
mC%*oblcdC
3
4
?,A@ !3!l/;48496?e%/.ge%mhP3
Loop:
mC%*oblcdC
1
2
3
4
5
6
7
8
$ !5 #$&"2
'8:)" -.2""22( $
#5 6 +8%' ')+;<=4!/ -.$"
!0/45 0$
/42
'8:!$ 5%*$$,+ '/ 8"2$% %'2( $"$"
'/#+!"2$#%* 6 &% %!#"%$'&()*&+
,-/.0 +21 -/32, ) , 1 0 " 0 +)4"5$+76 / 58(85"2(8:9<;=9+ &+! %4 '80(8> %*$+!2( '/423?@ '$8/
A B $ A A
C%
DFE6GEHD/4
< I JLK --------------Loop:
5(8( DFE6GD<E6D s2 J $2" ': *85%&*% ! !$G( $- $ 8 *42"25 M *$
</
DFE6EHD/4
<I
JLK
--------------M%
D
< 6 -4($s1) JLK --------------5(8( D < 6GD4< 6D/ B J 5(8( 4@ *$ 85N% *42"25 '$9-."2$6 !8"2$%&4% '8:
</
D
< 6 -4($s1) JLK --------------- !0$ 2" ': *85% %'$$+$83
5(8G( D/4< 6OD/4< 6 -8 J ad !/ 6 2GP $%*$$L+ *8(#
!8
D/4
< 6DQ2"2$ 6R9$$+
Seb/;to!4
v!*3!e%Ca13%N%>29;/I9.Ife%18b13!g,!%/.T ,? xN <%<!C1!gple : 23!
e%<%<!/#%m!%e1!1/e!18!.v$
0
M
u
x
Add ALU
result
Add
RegDst
Branch
4
Instruction [31 26]
Control
Shift
left 2
PCSrc
MemRead
MemtoReg
ALUOp
MemWrite
ALUSrc
RegWrite
PC
Read
address
Instruction
[310]
Instruction
memory
Read
register 1
Instruction [15 0]
0
M
u
x
1
Read
data 1
Read
register 2
Registers Read
Write
data 2
register
0
M
u
x
1
Write
data
16
Instruction [5 0]
Sign
extend
32
ALU
control
Zero
ALU ALU
result
Address
Write
data
Read
data
Data
memory
1
M
u
x
0
33
PCWriteCond
PCSource
PCWrite
ALUOp
IorD Outputs
ALUSrcB
MemRead
ALUSrcA
MemWrite Control
RegWrite
MemtoReg
IRWrite
Op
[50]
RegDst
0
26
Instruction [250]
PC
0
M
u
x
1
Instruction
[31-26]
Address
Memory
MemData
Write
data
Instruction
[2521]
Read
register 1
Instruction
[2016]
Read
Read
register 2 data 1
Registers
Write
Read
register data 2
Instruction
[150]
Instruction
register
Instruction
[150]
Memory
data
register
0
M
Instruction u
x
[1511]
1
0
M
u
x
1
B
4
Write
data
16
Sign
extend
0
M
u
x
1
32
Instruction [50]
Shift
left 2
Shift
left 2
28
Jump
address [31-0]
PC [31-28]
Zero
ALU ALU
result
0
1 M
u
2 x
3
ALU
control
ALUOut
1 u
x
2