You are on page 1of 228
a Solution 1.1 4.41.4. Computer used to rum large problems and usually accessed via a network: S supercomputers 11.2 10" or 2© bytes: 7 petabyte 1.1.3 Computer composed of hundreds to thousands of processors and terabytes of memory: 3 servers 4.1.4 Today's science fiction application that probably will be available in near future: 1 virtual worlds 4.1.5 A kind of memory called random access memory: 12 RAM 1.1.6 Part of a computer called central processor unit: 13 CPU 4.1.7 Thousands of processors forming a large duster: 8 datacenters 4.18 A microprocessor containing several processors in the same chip: 10 multi= ‘core processors 1.1.9 Desktop computer without screen or keyboard usually accessed via a net- ‘work: 4 low-end servers 4.4.40 Currently the largest class of computer that runs one application or one setof related applications: 9 embedded computers 1.1.44. Special language used to describe hardware components: 11 VHDL 1.1.22 Personal computer delivering good performance to single users at low ‘cost: 2 desktop computers 1.1.43 Program that translates statements in highelevel language to assembly language: 15 compiler Chapter. Sokitions 1.4.14 Program that translates symbolic instructions to binary instructions: 21 assembler 1.4.45 High-level language for business data processing: 25 cobol 1.4.46 Binary language that the processor can understand: 19 machine language 1.4.47 Commands that the processors understand: 17 instruction 1.4.48 High-level language for scientific computation: 26 fortran 1.4.19 Symbolic representation of machine instructions: 18 assembly language 1.4.20 Interface between user's program and hardware providing a variety of services and supervision functions: 14 operating system, 1.4.21 Sofiware/programs developed by the users: 24 application software 1.4.22 Binary digit (value 0 or 1): 16 bit 1.4.23 Software layer between the application software and the hardware that includes the operating system and the compilers: 23 system software 1.4.24 High-level language used to write application and system software: 20C 1.4.25 Portable language composed of words and algebraic expressions that ‘must be translated into assembly language before run ina computer: 22 high-level language 1.1.26 10” or 2 bytes: 6 terabyte Solution 1.2 1.21 Sbitsx 3 colors=24 bits/pixel = 4 bytes/pixel. 1280 x 800 pixels = 1,024,000 pixels, 1,024,000 pixels x4 bytes/pixel = 4,096,000 bytes (approx 4 Mbytes). 1.2.2 2GB=2000 Mbytes. No. frames = 2000 Mbytes/4 Mbytes = 500 frames. 1.2.3 Network speed: | gigabit network => 1 gigabit/per second = 125 Mbytes! second. File size: 256 Kbytes = 0.256 Mbytes. Time for 0.256 Mbytes = 0.256/125 = 2.048 ms. 1.2.4 2 microseconds from cache => 20 microseconds from DRAM, 20 micro seconds ftom DRAM ==> 2 seconds from magnetic disk 20 microseconds from. DRAM => 2ms fiom flash memory, Solution 1.3 4.3.4. P2 has the highest performance performance of PI (instructions/sec) Performance of P2 instructions/sec) performance of P3 (instructions/sec) 1.3.2 No.cyeles= time x clock rate ycles(P1) = 10x 2x 10°=20x 10s. ycles(P2) = 10x 15x 10° = 15 x 10’s ycles(P3) = 10 3x 10° =30x 10"s, time = (No instr. x CPD)/clock rate, then No. instructions = No. cycle CPI instructions(P1) = 20 x 10°/1.5 = 13.33 x 10” 1.3.3 timeyg,= time gg 07 CPL= CPLx 1.2, then CPI(PI) = 1.8, CPI(P2) = 1.2, CPI(P3) = 3, f=No. instr. x CPI/time, then APL) = 13.33 x 10° x 8/7 A(P2) = 15 x 10? x 1.2/7 AP3) = 12x 1093/7. 1.344 IPC= /CPI= No. instw/(time x dock rate) PCL) = 142 IPC(P2)=2 IPOP3) = 3.33 1,35 Timejy/Timegg=7/10=0.7-0 fyey= fei 07 1.3.6 Timengy/Timegg=9/10=0.9. So Instructions,.y = Instructions,,jX 0.9 \GH2/0,7 = 2.14 GHz. 10x 10” x09 = 27 x 10”, Chapter. Sokitions Solution 1.4 ‘141 P2 lass A: 10° instr, lass B: 2% 10? instr lass C:5 x 10° instr Gass D: 2 10° instr Time =No. inst, x CPVdock rate “Time class Time class C Time class. ‘Time class B: ‘Time class Time dass ‘Total time P2= 11 x10 21.4.2 CPI=time x dock rate/No. instr, CPI(P1) = 18.65 x 10 1.5 10/10°: CPI(P2) = 11 x 104 x 2x 10°/10° = 2.2 79 18x 1+ 2% 1X 24+5%105X3-42% 107 X4=28 X10 PX 2+2% 1X 245 1X 2+ 2x 10x 3=22K 10° (OX 1+ 50X54 100X5 + S0X2)X05x 107 =E75nS 14.5 CPI=time x dock rate/No. instr. (WrIs675 x10 x2 x10 700=1.82 146 Tine = GO0X 1+ 50X5 + 505+ 50% 2) X05X 10> 55018 Spoadup = 675 ns/SEDs = 1.22 (P1=550% 10° x2 10'/T00= 157 Solution 1.5 154 1G, 0.756 S/S b, | 1G,1.56 mss 15.2 ‘a. | F216 1.3 tres taste than PL bi. | PLis 1.08 times faster then P2 15.3 ‘| 2b LAL tres taste than PL B, | PLS 1,00 tines faster then PD 154 a | 20505 b. | 2935 15.5 a | O7tis | 0.8655 15.6 ‘@ | 130 tines faster | La0 tines fier Solution 1.6 1.6.1 Pete conpaer hor : m a : is on Chapter. Sokitions 1.6.2 =m 16.3 a ; a om 1.6.4 : Ea Sia : een Sia 146.5 Speed-up, PI versus P2: ‘& | OSSTI0ERES B | O7SOESIES 1.6.6 ‘@ | S2ON0SIESS wb, | R2IeDIeDIS Solution 1.7 74 Geometric mean clock rate ratio = (1.28 1.56 0,74)"7=2.15 ‘Geometric mean power ratio = (1.24 x 1.20 2.06 2.88 x 2.59 x 1.37 x 0,92)! = 162 v4 x 3,03 x 10.00 x 1,80 1.7.2 Largest clock rate ratio = 2000 MHz/200 MHz = 10 (Pentium Pro to Pentium 4 Willamette) Largest power ratio= 2: 2.1 W/10.1 W = 2.88 (Pentium to Pentium Pro) 17.3 Clock rate: 2.667 x 10°/12.5 x 10°= 212.8 Power: 95 W/3.3 W = 28,78 1.7.4 C=PN?x dockrate 80286: .0105 x 10° 80386: C = 0.01025 x 10-6 80486: .00784 x 10° .00612 x 10° 0133 10-6 Pentium 4 Willamette: C= 0.0122 x 10° Pentium 4 Prescott: C = 0.00183 x 10-¢ Core 2: C=0.0294 x 10° 17.5 33/1) 1.78 (Pentium Pro to Pentium 4 Willamette) 1.7.6 Pentium to Pentium Pro: 3.3/5 = 0.66 Pentium Pro to Pentium 4 Willamette: 1. Pentium 4 Willamette to Pentium 4 Presco Pentium 4 Prescott to Core 2: 1.1/125 =088 Geometric mean = 0.68 0.53 125/1.75=071 Solution 1.8 4.8.1 Power, =V? xdlock rate C, Power= 0.9 Power, Cy,= 08 xP KOS XAT BP XAX IP = 1.08 1.8.2 Power,/Power, = V7 x dock rate,/V 7 dock rate; Power Pover, = 087 = Reduction of 13% 18.3 Ponerg= Vix 1x 10? x08 G,=06%Poner, Power, = 5? x 0.5 x 10°C Vx 1x AWxOBXC, = 06 xPXO5% 10" C1 Vg=(OGXS? x05 x 10°YA.x 10? x08) /?= 3080 Chapter. Sokitions 1x Gua Vaal 11.8.6 Voltage = 1.1 x 1/27! = 0.92 V. Glock rate = 2.667 x 2"? = 3.771 GHz Solution 1.9 191 V4)2 5 dock rate x 2!? = Powerg. Thus, ‘a | 1749%100= 2% wb. | 46/120 x100 = 57.5% 1.9.2 & [a= 33208 be | bau = 45/11 = 409 19.3 ‘a | Ponera/Poveran = 1/49= 0.02 ba | Ponerg/Povetyn = 45/57 = 08 LBA Powers/Power,,=0.6 => Powery = 0.6 XPoweln, ‘am | Ponerg= 06 x40W=24W be }exaW=18W 19.5 a 24/0B= SDA 19.6 2 ee ee ee ee Solution 1.10 1,101 pe ree [teers | eet | : ; = = 2 = = : = = [| reeomere | namctons perpen | Talim | : = = ; = = 2 = = : = = 1.10.2 oT : 5 = 2 as Z = 1 “A006 2 3205 4 Bae4 3 35m Chapter. Solutions 1.10.3 —2h————— Eee 5376 258 1a ara — LEE eee ‘S376 3a78 3564 3a82 1104 4.00 Bar 125 Ors Emre 400 200 1.00 (050 a3 | 110.5 ey ‘core | Power (W) per core | Power(W) | Power (W) Ei Et Eri 0625 15 0625 025 025 025 ‘core | Power (W) per core Eis 0825 0m 0m 0m 125 25 a3 Het sph fale et) Ea 0825 125 25 1.10.6 Sa : = : = : is ; 225 i g i ala|a|a|—=|s|a]a]e EH Ba) a) a Chapter. Sokitions Solution 1.11 1.41.4 Wafer area =x (d/2)?? be 1113 ‘a | Dies per vater= 1.1 x90= 99 Defects per area = 1.15 x 0,018 = 0.021 detects/an? fer aed Dies per wafer = 176,7/29 = 1.78 cx? LALA Yield =1/(1 + (defect per area x die area)/2) ‘Then defect per area = (2/die area)(y“Y/— 1) Replacing values for T] and T2 we get ‘TI: defects per area = 0.00085 defects/mm? = 0.085 defects/am? ‘T2: defects per area = 0.00060 defects/mm? = 0.060 defects/am? ‘T3: defects per area = 0.00043 defects/mm? = 0.043 defects/am? ‘T4: defects per area = 0.00026 defects/mm? = 0.026 defects/am* 1,45 nosolution provided Solution 1.12 1.12.1 CPI= dock rate x CPU time/instr. count dlock rate = L/eyde time = 3 GHz. ‘a | Pibeand = 3x 10? x 500/218 x 10 =0.7 (Pint) = 3 10? x 1200/336 x 10" = 10.7 ref. time/execution time, (AxTE= 1219 1.424 CPU time =No. instr.x CPV dock rate If CPL and dock rate do not change, the CPU time increase is equal to the increase in the number of instructions, that is, 10%. 1.12.5 CPU time(before) = No. instr. CPI/clock rate CPU time(after) = 1.1 x No. instt.x 1,05 x CPW clock rate CPU times(after)/CPU time(before) = 1.1 x 1.05 = 1.155. Thus, CPU time is, increased by 155% (1.12.6 SPECratio= reference time/CPU time SPECratio(after)/SPECratio(before) = CPU time(before CPU time(afier) = 1/1.1555 = 0.86. That, the SPECratio is decreased by 14%. Solution 1.13 4.43.1 CPI=(CPU timex clock rate)/No. instr, ‘a | 1= 450% 4 x 107/085 X2118 x 107) = 0.98 bb, | 1 1150 4x 10°/(0.85 x396x 107) = 16.10 Chapter. Sokitions 1.43.2 Clock mate ratio= 4 GHa/3 GHz= 1.33, @ | Pi@acre= 099,091 @3 Gre= 0.7 ratio= 11 b, | PlesGr= 161,01 @3GH= 10,7 ratio= 150 ‘They are different because although the number of instructions hasbeen reduced by 15%, the CPU time has been reduced bya lower percentage. 1.13.3 ‘@ | 490/500 = 0.90. CPU time reduction: 10%. bb, | 1150/1200 = 0.958, CPU tine reduction: 42, 1.43.4 No. instr. =CPU time x dock rate/CPI. ‘| No. inst = 8200.9 4% 108/0.96 = S075 x10 wa | No. inst, = 58009 x4 x 107/2.94= T1010 1613.5 Clock rate =No. instr. x CPYCPU time. (Clock rate jy =No. instr. x CPI/0.9 x CPU time = 1/0.9 dlock rate =3.33 GHz. 1.43.6 Clock rate=No. instr. x CPYCPU time. Clock rate = No. instr. x 0.85 x CPI/0.80 CPU time = 0.85/0.80 dock rategyy = 3.18 GHz. Solution 1.14 1.14.1 No. instr. = 10° TaulPD= AP XL 25/4 AP = ORISA PE A? neMUCIONS Tea (P= OSI XAT S P2:Tep/P2) = NXO.75/3 x 10? then N= 1.26 x 108 1.143 MIPS= Clock rate x 10°/CPL MPSP1)=4 x10? x 107/125 =200 MPSF2)=3% 10? x 10/075 = 4000 MPSP1) 10°/.01 x 10° x 10°) =2.97 x 108 “The Second progam has te higher Peomance and the higher MFLOPS fare, GUL the frst rrogram: has the higher MPS figure, Solution 1.15 145.1 T= 35 XO.8= 285, T= 28 +85 + 50+ 30 = 195 5, Rechelion 35K 50 XOB= 405, T= 40 + 80 + 50 + 30= 2005, Redo 4.7% Chapter. Sokitions 1.15.2 & | Wa =200 x08: Tip Ty} Taann = 215 & Tyg = 45 & Reaction tine NT 7% By | T= 210 XOB= 16S Tip Tye Then = 1508 Tyg SSS Reduction tre NISRA 1.15.3 & | Ta =200X08= 1605 Ty Tia * ra 4708 NO Be | T= 2i0x08: ST Tia * ys 2608. NO 1.154 Glock eyles = CPIjp X No. FP instt, + CPline X No. INT instr, + CPI. No. US instr. + CPlyyanch X No. branch instr. Tau = dock cytles/clock rate = clock cycles/2 x 10? bb | 8 processors: Goo QUES = 10245 Ty =O5I2 5 ‘To half the number of clock cycles by improving the CPI of FP instructions: (Phingroved fp * No- EP instr. + CPling X No. INT instr. + CPhy, x No. L/S instr. + (Planch % No. branch instr, = clock eycles/2 (Plingroved p= (lock cycles/2 = (CPI, X No. INT instr. + CPI, No. U/S instr. + (Plana, X No. branch instr,)No, EP instr. ‘a [1 OCeSSOr CPlrraasy = (4096 — 762/560 <0 not POSS Ba | 8 rOCeSEOTS: OM grams y= G12 ~944)/E0 MOL pOSSEIE 1.15.5. Using the clock cycle data from 1.15.4: ‘To half the number of dock cycles improving the CPI of L/S instructions: (Ply x No. FP instr. ++ CPlizy % No. INT instr: + CPlinprened is * No. L/S instr. + (CPlppanch X Nos branch instr. = clock eycles/2 (CPlinprosed is = (dock eycles/2 — (CP ly x No, FP instr, + CPlig X NowINT inst + (CPhiyaneh * No. branch instr.))/No. L/S instr. si7 1 process Proud a= 096 = 9072/1280 = 08 1 PROCESSIONS: Praed 1,156 Clock cyles= CPlj, No, FP instt,+ CPlizy No. INT instr, CPly,%No, L/S instr: + (CPleyarcs Noe branch instr Tey = lock cycles/clock rate = dock cycles/2 x 10° CPI) =0.6% 1 = 06; CPI,,= 07 x4=. ' PFOOSSGONS Ty (BETO MOK) = OSI 6; Ty (GNF MIPIOM) = 0.542 5 Solution 1.16 1.16.1. Without reduction in any routine: {tal time 2 proc = 185 ns ‘otal tine 16 proc = 34 ns Reducing time in routines A, C and E: 2 proc: WA)= 17 ns, TO) = 85s, TE) = 4 ns, tal time = 78.Gns —> veda = 29% 16 proc: TA)= 3.48, TO = 1.16.2 2 pr00: NE) = 72s, Ota ine = 177 ns —> eon =A 16 pros: TS) = 12.6 ns total ire = 325s => redoion =A 116.3 2 PROC: NO) = GSS, (al tine = 17ENS => ATINN=S-7H 516 roo! ND) = 10S rs, Wal tne =S2.8re — reac = 3S Chapter. Solutions 1.164 Cad ‘# Processors — | Computing time oO Routing time ratio 2 176 a 95 055 1s, 49 Ost aL 16 2 Ost 12 2 4 oar 205) oe 65 06 Ls 1.46.5 Geometric mean of computing time ratios = 052, Multiply this by the ‘computing time for a 64-processor system gives a computing time for a 128 processor system of 3.4 ms. Geometricmean of routing time ratios = 1.19, Multiply this by the routing time for a 64-processor system gives a routing time for a 128-processor system of 30.9 ms. 1.46.6 Computing time = 176/0.52 = 338 ms. Routing time = 0, since no com= munication is required. F Solution 2.2 Chapter 2 Sokitions 2.2.2 F z a [a7 234 23.5 Solution 2.4 244 24.2 243 B 244 Chapter 2 Sokitions 245 & | nochange tt | nochange 24.6 a | 5.25 writen, Sminenaaty 1b | 2.25 writen, 2mineneaty Solution 2.5 2.5.1 a ‘Aokress Data temp = ArrayE3; 2 1 arrayl3] = Arrayl2 I; 8 6 arrayl2] i 4 4 arrayll] 3 ° 2 arraylO] be ‘aouress Data emp = Arrayl41s 16 1 arrayl4] 2 2 array[O] = temp: 8 3 tem = Array[31: 4 4 arrayl3] = ArrayLL: ° 5 ArrayEi] = temps 252 a ‘Access Data temp = Array[3s Tw $10, 12¢856) 2 1 Array[3] = Arrayl2]; | Iw $ti, 8CSs6) 8 6 array[2] = Arrayl1]; | sw $tl, 12¢6s6) 4 4 ArrayLl] = Array[O]; | Iw $ti, 4Css6) ° 2 Array] = temp: sn St, 8Cs6) Tw $tl, OCSs6) Stl, 4¢$s6) $10, C856) be accress Data tem = ArrayL4]; $00, 16(556) 16 1 arrayl4] = ArrayLOl: Stl, c$s6) 2 2 arrayLO] = temps sw $tl, 16(556) 8 3 sw $10, O¢$s6) 4 4 temp = ArrayL3]: 0 5 arrayl3] = ArrayLil; | Iw $00, 12¢$56) arrayl1] = temps Tw $ti, 4¢$s6) sw $tl, 12¢856) sh $10, 4($56) 25.3 a] Ades Daa | tam - Arraylal: Tw $0, ‘Sips nstrucns, +4 2 1 Arrayl3] = Arrayl21: Tw stl, a mips ist for every nary 8 6 Arrayl2] = Arrayl11i sw $tl, 1 ato offset h/sW Bair 4 4 ArrayLi] = ArraylO1: Tw stl, 4 ‘Cimips inst.) ° 2 Arrayl0] = temps sw $tl, ai Tw stl, ai sw $tl, 4 si $t0, 0} BAe oats | cen = Arrayl; Tw $0, i ‘Bmips nstrucons, +4 16 1 Arrayl4] = Arrayl01s Iw $tl, a mips fst for every nary 2 2 array] = temp: sw $tly I ato offset h/sW Bair 8 3 sw $0, 0 ‘Cimips inst.) 4 a enp = ArrayL3]5 ° 5 Arrayl3] = Arrayl11s Iw $0, 12¢ arraylil = temp: Tw $tly 4 si $tl, 1 SH $0, 4 254 @ | 205418806 ws | suse0ran2a 25.5 a pattess Daa reess: Dat 2 2 2 B 8 a 8 ES 4 56 4 a ° 78 o 2 B notte Daa reess: Data 2 be 2 og 8 a 8 0 4 © 4 a ° oa o be Solution 2.6 264 alin sub add wb | acd lw add lw Chapter 2 Sokitions 2.6.2 2.6.3 2.6.6 adi $50, $50, $51 a a ripe [0 | 36 | a9 | 16 » P| te | ee acai $56, 56, <2] we | 8 | 2 | 2 20 adi_i56, #6, tsi [Rape | oO | 2m | 7 | 2 ww $50, 0650 | roe | 5 | 2 | 16 a 273 wb | FFFFS: a | FFF b [a 27.6 b | FFF Solution 2.8 284 a | TFFFFFFF, 1 b 00, averfiow Chapter 2 Sokitions 2.8.2 a 0 Overton & [ 0, no overtion 2.8.3 ‘a | EFFFFFFF, overfion 284 ‘| overtiow we | ne cverion 28.5 ‘@ | no orton we | ne cverion 28.6 ‘@ | overiow & [no wvemon Solution 2.9 294 ‘| overtiow we | ne cverion 2.9.2 ‘@ | overtiow we | ne cverion 2.9.3 ‘@ | mvertiow | ovation 294 ‘@ | moveriow b. [ moveriow 2.10.3 ‘@ | At0so004 ws, | ancaoo40 Chapter 2 Sokitions = REOB, 7 OO, PSSOKI3, OS, inm=OxA ‘2920022012 2366177216 2.41.3 sw $13, -4(850) be Tw $00, ~64Cst0) 2414 Rare Fee a [add $vi, Sat, # b [sw Sal, 4(850) 241.6 | oxanssao04 Solution 2.12 2424 ee a[me[ os ]sf]3 ifs 6 total its = 26 a total its = 32. welts = 28 8/5 wavs = 26 ‘@ | ssregsiers > ss its par NStUCtIN — could recuoe ove Sa ess regsters — more regter spills mare instructions ia | smater constants — more ki nstrucions — could naease Oxde See | ‘Selle Constants ~ smaller noades —> smal Oxde Swe 2124 ‘| 17367056 | 23e6n77208 Chapter 2 Sokitions 212.6 a | Rape 02030, 0-8 Be | type, 09-003, =O Solution 2.13 243.4 a | OS77S577B wb. | OxFEFFFEDE 2.43.2 ‘a | cxSS555560 wa | OxEADFEEDO 2.13.3 a | OXGFEFFFFF Solution 2.14 2441 a |] ad std, $0 srl stl, 5 andi Stl, OxOOltf tt b | add st, $0 si] stl, 10 andi StL, Oxf fF #8000 2.14.2 ‘@ | add sti, st, $0 andi $tl, $t1, Oxooodoor [add Stl, $00, $0 srl $tl, Stl, 14 andi $t1, $t1, 0x0003c000 2.14.3 a] add sti, sto, $0 sr] $tl, $t1, 28 [add Stl, $00, $0 srl Stl, $tl, 14 andi $t1, $t1, x0001c000 2144 a] add $t2, $00, $0 srl $t2, $2, and $t2, $t2, Ox0ggo003t and Stl, Stl, Oxfffff cd ori Stl, $t1, $02 Badd $12, sto, $0 sl] $t2, $t2, 3 and $t2, $t2, Oxoofcood and $t1, $t1, oxtffosrtt ori Sti, $ti, $t2 2445 ‘a [acd $12, $00, 60 and $2, $t2) dxoooooar and $tl, §tl, Oxfrrrrred ori Stl, stl, st2 [add $12, $10, $0 sll $t2, $t2, 14 and $12, $2, Qx0007000 and $tl, $l, Oxrrrasrrr ori Stl, Stl, st2 am [add $12, $00, 0 srl $12, $12, 29 and $12, $12, Oxooggo003 and $11, St, OxfFrrfrrc ori_ Stl, stl, $12 be [add $12, $00, $0 srl $t2, $12) 15 and $2, $2) dxooddc000 and $tl, §tl, Oxfrrrarrr ori Stl, stl, st2 Solution 2.15 245.4 ‘@ | oxoondase) | @xoorrsa66 2.15.2 ‘a [nor Stl, $12, $12 and__$tl, $tl, $3 wm pxor Stl, $i, Sta nor __$tl, $ti, $tl 2.15.3 and tl, stl, $t3_| Goaa00 a1001 01 @ [nor Stl, $12, $t2 ] 000000 01010 1010 Gl00] 00000 100 1901 00000 100100 be [xor Sti, $12, $03 | Go0000 O10I0 ox nor _$ti, sti, st1_| coaaa0 i001 01 2154 ‘am | x00000220 we | oxco003234 2.15.5 Assuming Stl =A, $2=B, $s1 =base of Array C a Tw $51) and 2, 8 B beq Stl, $0, ELSE add $tl, $02, $0 beq $0,°80, END ELSE: Iw $02, O¢$s1) EN: 2.15.6 a Tw $03, Yooo!1 10001 lari cooqaeqcq0qa0000 and $tly (009000 o1G10 aiai1 a1o01 aaada 100100 B beq Stl, ‘a0a700 1001 co000 coooaaqGca0q0I0 add tly ‘090000 1610 cocda a1001 aaa00 1G0000 beq $0, ‘00100 Go000 coGe0 acocacaacaa0a001 ELSE: Iw §t2, 100011 10001 1010 cooeaoacacaaca0a EN: ‘@ | all, 16000 10 OTF ba, | 06000 DORE 216.3 @ [1um—9, teen B. [ jum—n9,tee—n0 Chapter 2 Sokitions 2.164 = [so=2 | m [so22 J = [se=0 | wm [sons J [ioe beav0 | ty [homes bares J Solution 2.17 247A. The answer is really the same for all All of these instructions are either supported by an existing instruction, or sequence of existing instructions. Looking for an answer along the lines of, “these instructions are not common, and we are only making the common case fast’ 2.47.2 ‘| could be either ype of ype sub $12,$zer0,813 f= - 3 ble §t3,$zero,dane if if 13 €0, result is t2 add $12,8t3,8zero if 13> G, result is 13 DONE: b [ste Stl, 903, 512 2474 a [2 AB >| inca Dal=0 +2 sta, $0, 0 $0,” $0, "TEST $50, $50, $51 sta, sta, 1 siz, sta, 10 st2, $0," LoaP $12, $50, 10 St2, $0, DONE 513, $51, $50 S12, $50, 2 SUZ, $52, $12 513, 12) $50, $50, 1 J Loo? oon 2.18.3 ‘| Sinstuctons to mplementand 44 structions executed 1b | Sinstuctons to mplementand 2 nstrclons excuted 2.18.4 @ [ot b [SOL 2.18.5 am | forci=i00; DO; i==71 result += MenArraylsOl: so wb. | fori: TAM, 2d" result == MenirraytsO + 11; result == MemirraylsO = i + ) 2.18.6 a addi $t1, $50, 400 Lop: Iw $51, 0¢$s0) add $52, $52, §s1 addi $50, $50, 4 Ine $50, $1, Loop | ready reduced to minimum insructons Solution 2.19 ssp, $50, sro, O¢SSp) Ow sub $y0, $20, $a in ra we | fetter ‘061 $5p. Sp, —1 sw §ra, 12Césp) sw $50, a¢Ssp) sw $51, 4¢6sp) Sw $52, O¢SSp) add $50, $20, $0 dd. $51) Sal; $0 dd $52) $22) $0 add $10, $51, $0, ne $52) $0,"exit add $20, $50, $51 add Sal $50, $0 add $02) $52) fal . - Iw O¢$sp) Ww 4C$sp) Ww acssp) Ve audi in Chapter 2 Sokitions ssp, acssp) $20, $a 80,1 80, exit 80, $10 $0, exit 80, $0 sti, $0 ocssp) ssp. 4 Sra, ssp, sra not possible for the MTF err “4 contents of register $ra after cating function sub: old §sp=> @rrrrrre “4 of register $ra ssp 8 of register $ra_ firetum to ’ | after calling function fi_iter: old §sp> Gxsfrfrrre “4 of register $ra of register $50, of register $51 ssp > of register $52 $5p,55p,-8 $ra,4($5p) $50,0¢5sp) $50,522 tune $20, 5v0 $21,530 fune $ra,4(Ssp) $50,0(5sp) $5p,55p48 $ra 219.5 “@ | We can use the till optimization for the secend call © func, but ten wemustresior Sa nt Sep befare that call, We seve only one instruction (Sra). wb | We can NOT use the tal call optimization here, because the vale reumed from f 1S not equal {0 te vale retried by the last call © FUNC. 2.19.6 Register $ra is equal to the return address in the caller function, registers ‘$sp and $s3 have the same values they had when function f was called, and register ‘$t5 can have an arbitrary value, For register $t5, note that although our function does not modify it; function func is allowed to modify it so we cannot assume. anything about the of $t5 after function f unc has been called. Solution 2.20 $sp+ §5p, Sra, 4C$5p) $20, a¢$sp) $50, $0, $20 $0, $20, 510, 60, $v0, $0, 1 Ssp, §5p, 8 $ra $20, $a, -2 Fact $v0, $50, $¥0 $20, 0¢$sp) Sra, 4¢$5p) Ssp, $5p, 8 sra Chapter 2 Sokitions Ssp, ~8 ACS5p) ‘acssp) 50, $20 $20, 2 80, "LI $0, 1 $sp, 8 $20, -1 $50, $0 acssp) ACSsp) ssp, 8 ‘a | 25.MPS nstrucions to cove nonrecurSNeWS. 45 nsYUCtONS to excowte(coTeCted versIN| oprecursion Nenrecursve version: addi §sp, $sp, ~4 sw $ra, 4(S5p) add acd sTti $10, ine $10, mul $52, addi $50, J Loo" add $0, Ww Sra, addi §sp, or $ra 1. | 25MPS insiuctions to excovte nonreoursive vs. 45 instructions io excoute(coected version ‘preousion Nenrecursve version: addi $sp, Ssp. -4 sw $ra, 4C55p) add $50, $0, $20 add $52, $0, $1 Log: siti sua, $50, 2 ine $00, $0,’ DONE mul $52, §s0, $52 addi $50, $50; -1 J Loop’ DONE: add $v0, $0, $52 Ww Sra, acésp) addi §sp, Ssp, 4 or __$ral 2.20.3 ‘@ | Recursive version FacT: addi $sp, $sp, sw $ray 4($5p) sw $a, O¢Ssp) add $50, $0, $20 HERE: siti $t0, $a0, 2 beq $0, $0,°L1 addi §¥0, $0, 1 addi §sp, $sp. 8 ir $ral Liz addi $30, $20, jal FACT mul $40, $50, $0 Tw $20, 0¢S5p) Tw $ray 4($sp) addi §5p, $sp. 8 ir $ral old $59 >" Oxnnnonnnn ~ ssp > ay old $59 >" Oxnnnonnnn ~ ay 72 ssp > ne ‘at label HERE, after calling function old §sp >” Oxnmnannnn ssp > old $sp > ssp > ‘Oxonnnnnna ~ ay 72 ne 20 ‘at label HERE, after calling function FACT with input of 42 r $ra ter $20, s of regis! ts of regis ‘at label HERE, after calling function FACT with input of 3: of regist of regis of regis of regis of regis of regis ‘at label HERE, after calling function FACT with input of 1 of regist of regis of regis of regis of regis of regis of regis of regis Chapter 2 Solutions | Recursive version FACT: addi $sp, si Sra, su Sa, add HERE: siti beg addi addi in li: addi dal fact Mul $¥0, $50, $¥0 Tw $20, OCs) Tw Sra, 4(Ssp) addi $5p. $sp. 8 ir $ral old §sp =>" Oxnnnannnn ssp > 3 old §sp =>" Oxnnnannnn 3 2 ssp > a6 Sta $59 => Oxnnmnnnn 3 2 6 20 ssp > 24 old §sp =>" Oxnnnannnn 3 2 6 20 24 5 $sp > = fat label HERE, after calling function FACT with input of contents of register $ra contents of register $20 fat label HERE, after calling function FACT with input of Tabel HERE, after calling function FACT with input of s of regist 5 of regi 5 of regi 5 of regi 5 of regi 5 of regi fat label HERE, after calling function FACT with input of 2.204 @ fis: addi Sp, = acs5p) 4CSsp) acssp) $20, 3 80," 80, 1 uy $20, -1 $0, $0 $30, -1 $40, $51 exit: ocssp) 4(Ssp) 5p) $sp, 12 $sp, ~12 C559) 4C5sp) acssp) $20, 3 80," 80, 1 uy $20, -1 $0, $0 $20, -1 $00, $51 EXIT: Iw $20, 0¢$sp) Tw $51, 4(5sp) Tw $ray 8(5sp) addi §5p, $sp, 1 Chapter 2 Sokitions 2.20.5 er FIB: addi SH addi addi siti ine add $sp, Sra, ssi, $52, sta, 510, $53, ssi, $52, $20, Loo add Ww addi ar $0 Sra, Ssp, Sra ‘a | 23MPS istuntions to ecaute nonrecurshe vs. 73 nsiUctons lo excoWte (coTeCtEd VES oprecursion Nonrecursve version Ssp. ~ sp) $0, 2 $0) 1 $20, 3 50,’ ExT ssi, $0 sl, $52 $53, $0 $20, -1 sl, $0 sp) ssp, 4 er Fis: acd addi acai siti ine add acd acd acd ssp, Sra, ssi, $52, $20, L008 add Ww acdi ar 80, Sra, ssp, sra ’b | 23MPS instutions © @caile nenrecurShevS. 73 netuctons excoute carected vas recursion Nenrecursve version: 2.20.6 calling function FI8 with inpy calling function FI8 with inpy FIB: addi $5p, $sp, =: sw $ra, (5p) sw $51, 4(Ssp) sw $a, O(Ssp) siti $0, $20, 3 beq $0, $0,°L1 addi §¥0, $0, 1 3 ext addi $20, $a0, “1 jal FIB| addi $51, $¥0, $0 addi $20; $40) =1 jal FI ’dd $40, $40, $52 Iw $20, 0¢$sp) Tw $51, 4(Ssp) Tw $ray 8¢Ssp) addi §sp, $5p, 12 ir $ral ‘at Tabel HERE, aft old $5p ‘Oxonnnnnna “1 = ssp > w | recursive version FIB: addi $5p, $5p. ~ sw $ray (S50) sw $51, 4(Ssp) sw $a, OCSsp) HERE: siti $00, $20, 3 beq $0, §0,°L1 addi §¥0, $0, 1 3 ExT Lis addi $0, $20, -1 jal FIB addi $51, $40, $0 addi $20, $30, -1 jal FI add $40, $¥0, $51 EXIT: Iw $20, 0¢$5p) Tw $51, 4(Ssp) Tw $ray (sp) addi §5p, $5p, 12 ir $ral ‘at Tabel HERE, aft old $5 (Oxnnnnnnnn “4 4 Chapter 2 Sokitions Solution 2.21 221 @ | after entering function main: ald $sp Gurrffrre 222 after entering function leaf_function old $5 wrrrrffc =A $sp 8 Sp => “4 contents of regist of regist of regist er er er sra sra Sra (rewum to main) By | after entering function main: eld $5 axerrrrte ssp “4 after entering function my f eld $sp averrrttc “4 “5 ssp = global_pointers ‘@x1o008000 00 my_ global of regist of regist of regis’ sra sra Sra return to main) 2.21.2 a | Hal ‘addi $5p, sw $ra, addi $20, Jal LEAF Ww Sra, (sp) addi $sp, Ssp, 4 dr fra addi $5p, $sp, sw $ra, AC$5p) sw $50, OC$5p) addi $50, $20, 1 siti $2, 5, $20 ine $12, $0, DONE add $20, $50, $0 Jal LEAF add $v, $50, $0 Ww $50, Oc$p) Ww $ra, A¢$sp) addi Ssp, Ssp, 8 ar fra sa7 Wal $5p. (Ss) ($50) assume $50 has global variable base $v0 $0 (ssp) $5p, 4 FUN sub $¥0, $a0, Sal $5p. (Ss) 80,1 (ssp) $5p, 4 $sp, 4(359) acssp) $20, 1 5, $20 $d, DONE ss0, $0 $50, $0 Css) 4C5sp) $5p, 8 has global variable base Chapter 2 Sokitions 224 Register $30 fs used to od a temporany result Without saving $S0 frst TO comect this Breblam, S10 (or $40) shculd be used in place Of $50 the rst two sructions, Note tat a ‘Subgptinal SOMtCN WOuld Le 1 ConUTWe USI $S0, DU ac Code to seve/TeSIEE “The MOadd NSTTUCIONS move the slad< Ponte the wong dection. Note at the MPS: caling corvention requres te S120« to ggOW down. Even if We Siac gro UP, is caKe WOU be incorect because Sra and $80 are saved acooring 0 te Stac-grO"s down COTMETTION. 2.21.6 ‘& | The function retums 842 (which is 2 (1 =30) + 1000 = 100) 1b | The function retums 1500 (ga, b) is 500, s0 it etums 500 + 1000) Solution 2.22 2.224 @ | 65 20 98 121 116 101 mp SD igi 114 2.22.2 ‘@ | u0041, u+0020, Us0062, U0079, U0074, U+0065 h | U0063, U+06r, U+006d, U+0070, U+0075, U+0074, U+0065, U+0072 2.22.3 @ | add tb | shit Loge: DONE: FIRST: sp, ~4 (sp) 80, 030 50, 0x39 # 19" 50, $0 sa, $0 cso) Sel, $16 80, DONE St7, $1 80, DONE sel, $6 80, FIRST $50, 10 $50, §t1 st0, 1 $50, $0 (sb) $5p, 4 Loo HEX: ec: Dan FIRST: $5p, (sp) 80, Qx41 i tat 50, O45 i 1FY 50, 030 # 10" 50, 039 #19" sly 80,’ FIRST $50, 10 $50, $12 st0, 1 add $v0, $50, $0 Tw $ray ($59) addi S5p, Sp, 4 ir $ra Chapter 2 Sokitions Solution 2.24 2.24.1 ‘@ | cxoo000012 wb [ onzrrrere 2.24.2 ‘a | 00000080 wm | 20000000 2.243 b [ oaTsss655 Solution 2.25 2.25.4. Generallyall solutionsare similar: ui sta, ori stl, $1 2.25.2 Jump can go up to OXOFFFFFFC, a [© ® [r0 2.25.3 Range is 0x604 + Ox FFFC = 0x0002 0600 to 0x604 — 0120000 = OxEFFE 0604. by fies 2.25.4 Range is 0x0042.0600 to 0003E 0600, » [ro 2.25.5 Generally, all solutions are similar: add Stl, zero, $zero clear $t1 addi $12, $zero, tomAbits set top 8b sl] $12, $02, 24 isnift left 24 spots or Stl, Stl, $12 place top 8b into $t1 addi $12, $zero, mxtl@pits iset next 8b sll $12, $12, 16 isnift left 16 spots or Stl, Stl, $12 place next & into $t1 addi $12, $zero, mxt2 pits iset next 8b sl] $12, $12, 24 isnift left 8 spots or Stl, Stl, $12 place next & into $t1 ori $tl, $tl, bo@bits — ior in bottom 8b 2.25.6 a | ox12345678 by | oxiz340000 2.25.7 @ | 20 = (Oxi234 << 16) |] Oxs678: be | cd = (00 || Oxs678); 0 owiell ie Solution 2.26 2.26.1. Branch range is 0x00020000 to OxFFFED004. @ | oebench by | thee branches 2.26.2 by | can't be done 2.26.3 Branch range is 0x00000200 to OxFFFFFEO4. eit branches B ‘S12 branes | Chapter 2 Sokitions 2.264 trench range is 16% loner be branch range is 16xsmaler 2.26.5 a no cree be “ump to aciresses 010 2” instead of 0 to 2 assuming the PO=0" condition for te mer loop is AeC-ed. ‘This conan is Crected atoll oF 5 tines (whenever snap Is called, psa total of 10 res {0 ext the Emer logp once n each eration oF re cuter Keon), so We execute 55 MSHUGIONS fever. Solution 2.33 2.331 ‘@ | ind: move $v0,$zer0 eq $v0,5a1 done sl $t0,5v0,2 add $t0, 500,520, lw $t0,a¢st0 be $t0,522,skip ir $ra addi $¥0,$¥0,2 b 1009 2 1i $y) irra we | count: move $¥0,$zer0 ‘addi 00, $0, b Toop ir_sra 2.33.2 ‘a | int findGint *a, int ny int 01 for(p=azp!maenip+4) fp) B | ine count(int *a, int ny at int ress; 2.33.3 & [inc nove $00,500 etl stls$ai.2 StI/stl;sa0 $10, Steere si2iacsioy $12,802, skip $10" $10,820 $10"80,2 & sia, szero sia;sa0 sulisen.2 StI/stl;sa0 $10, Steere si2iacsioy $12,802, skip $10,80001 sto;siosa oop sre 2.33.4 EE Eee = 7 5 be 8 6 2.33.5 EE eee = ri 3 be 2 3 2.33.6 Nothing would change. The aode would change to save all tregisters we use to the stack; but this change is outside the loop body. The loop body itself ‘would stay exactly the same. Solution 2.34 2341 a addi $50, $0, 10 Loge: add. $50; $50, $51 $50, $50, -1 $50, $0, Lo0e b SI] $51, $52, 28 srl $52) $52) 4 or $51) $51) $52 2.342 ‘@ | ADD, SUBS, MO/—oll ARM registeregister instruction forme ENELan ARM branch instrucon format a | RoR an AR regisiowegisir suction format 2.34.3 a curd, rl BHI FARAWAY B ADDO, ry Fz 2.344 ‘@ | Oven ARM resisieregster instruction fomat EMILan ARM branch nstuctin format bb [ ADD—en Ar registerregister instruction format Solution 2.35 2.351 ‘@ | egsier operand wa | resister + offset and update register Chapter 2 Sokitions 2.35.3 a addi $50, addi $51, xor $52, ADDLP: Tw $54, addi $52, addi $50, addi $51, $51, «1 ine $51, $0, ADDLP & ST $51, $52, 28 srl $52, $52, 4 or $51, $51, $52 2.35.4 ‘a | BARNS BMPS reTUCIONS by [ LaRWS. 3 MPS structions 2.35.5 ‘| ARMOR? tines fact as MPS wa | ARW 2 tines fast as MPS Solution 2.36 2.36.4 = si $51, $51, 3 add_$53, $52, $51 b si] $54, $51, 2 srl $51, $51; 3 or $51, $51; $54 add_$53, $52, $51 2.36.2 ‘| adi $53, $52, wb | addi $53, $52, 2.36.3 a sl $l, $1, 3 add $53, $52) $51 & Su $54, $51, srl $51, $51, 3 or $51, $51, $54 add $53, $52) $51 2.364 [add 13, 02, b [add 13, 72, ox@000 Solution 2.37 237.1 a mov ed, Lesind¥ebx] echemnenory(ests4*ebx) wb | staRT: mov ax, 001011005 nar ax = 0010110005 mov cx, 000000115 nar bx = 121200005, mov bx, 11110000) nar ex = QOQ0OOLIb: and ax, bx ax = ax Bk bx; or ax, ox ax = ax | os 2.37.2 a SI $52, $52, 2 add $34, $54, $52 Iw $53, (sd) wb | START: addi $50, $0, Ox2 addi $52, $0, 0x03, addi $51, $0, Oxfo and $50, $50, $51 or $50, $50, $52 2.37.3 @ | nov edx, [esisttebx] SLES b | add eax, 0x12345678 4,4,1,32 2374 ‘@ | addi $00, $0, 2 sl} $20, a0, $t0 add $20; $20; $al Tw $v0, 0320) wb | tui $20, Oaaae ori $20, Ox5678 Solution 2.38 2.38.1 ‘Tis insructin copies ECX bytes rom an are pointed to by ESI to an aray pointer by EDL. ‘example C litany function that can easily be implemented using this instruction fs memcpy. “This insruction copies EOX elanents, where each leet is 4 bytes nSize, roman aray parted toby ESI to an aay porter by EDI Chapter 2 Solutions 2.38.2 am | loon wm | Toop: Tw $t0,0¢baz) sw $t0,0¢5ai) ‘addi $20, $30,-1 addi $21,414 addi $22,824 bnez $20, 1000 i SS ———— EE ee a] f: add $00,520,521 MPS:2%4=8 bes Sr__$ra 286: Li pfs: [fw $t0,0Csa0) MPS: 6x4 =24 bes Ww $t1,0¢$a1) 286: 19 bes add $10, $11 Sa 'ocsa0) sw $00,0¢$a1) sr__$ral 2.38.5 In MIPS, we fetch the next two consecutive instructions by reading the next 8 bytes from the instruction memory. In x86, we only know where the second instruction begins after wehaveread and decoded the first one, so itis more dificult +0 design a processor that executes multiple instructions in parallel. 2.38.6 Under these assumptions, using x86 leads to a significant slowdown (the speed-up is well below 1): a = 2 Fry 0.8 ] & é 19 02 | Solution 2.39 2.39.1 ‘@ | oss seconds ba. | ax7eseomas 2.39.2. Answer is no in all cases. Slows down the computer. CCT = dock cycle time ICa= instruction count (arithmetic) ICls= instruction count (load/store) 10>= instruction count (branch) new CPU time= 0.75 x old ICa x CPla x 1.1 x oldOCT + oldICs x CPils x 1.1 x oldCCT + oldICb x CP Ib x 1.1 x oldCCT “The extra clock cycle time adds sufficiently to the new CPU time such thatiit is not quicker than the old execution time in all cases. 2.39.3 @ | 13.16% LAs | s0886% 10.64% 2.394 als ba | oxrieccscar Chapter 2 Sokitions Solution 2.40 2.40.1 ‘a | Ine frst Reation S10 is Oand the Wy felches a{0} After that $10 1, the hvuses a nore aligned access tegers a bus ercr, 1b | In he fst eatin $10 and $e point to [0] EO} so the Iv and sw structions acoess AO), YO, and then a{0] as intended. Inthe secand iteration $10 and $e point tothe res byte a{0] end bf] respective instead of pointing toa] and bE]. Thus the frst hy uses a nore aligned address ard causes a bus mar. Note that fe computation for $12 (ackess fala) oes not cause a us eer becaLke thet address isnt actualy used to access menor. 2.40.2 ‘a | Yes, assuming that is asigrederded bye valve between 128 and 127. xis simply be ‘ale betveen 0 and 255, the function proved only veri if nether xnor array a contain values outside the rarge of 0.127. | f? move $v0,szer0 mmave $10,$2er0 Le SIT $t1,$t0,2 — ; We must muttiply the index by 4 before we add $11,$t1,$20 add it to af] to form the address for Iw Ww $tl,0csi1) me §11,$22,5 ‘addi $¥0,$¥0,2 St addi $10,800,1 ine §10,Sal, ir __tra we | F move $00, $20 move §t1,$a1 ST] §t2,$32,2 ; We must multiply n by 4 to get the address add $12,$t2,$20 ; of the end of array a Li lw st3,0cstoy Ww §ta,acsti) add $13,$13,504 sw §13,0(10) addi $10,$t0,4 —; Move to next element in a addi $U1,8t1,4 Move to next element in b ine $10,512, irra 20.4 At the exit fiom my_a] loc, the Ssp register is moved to “free” the men that isretumed tomain, Then my_in t) writes to this memory to initialize it, Note that neither my_int nor main access the stack memory in any other way until sort () iscalled, so the values at the point where sort () iscalledare sill the same as those written by my_ini t: ala G2 0 0 0 als & 3 2 7 2.40.5. In main, register $s) becomes 5, then my_a110C is called. The address of the array y “allocated” by my_a110c is Oxffe8, because in my_a110¢ $sp was saved at Oxffic, and then 20 bytes (4% 5) were reserved for array arr (Ssp was dec- remented by 20 to yield Oxfle8). The elements of array v retumed to main are thus al0] at Oxffe8, a[1] at Oxffec, a[2] at Oxf, a[3] at Oxf, and a[4] at Oxfff8. After My_al 1oc returns, $sp is back to 0x10000. The value retumed from my_a110c is Oxffe8 and this address is placed into the $sl register. The my_init function does not modify $sp, $50, $1, $82, or $3. When Sort () begins to execute, $sp is (x1000, $30 is 5, $s] is Oxffe7, and $52 and $33 keep their original values of -10 and 1 respectively. The sort (0 procedure then changes $sp to Oxffec (0x1000 minus 20), and writes $80 to memory at address Oxffec (this is where af1] is, so al] becomes 5), writes $s1 to memory at address OxfHf0 (this is where a[2] is, so a[2] becomes Oxffe8), writes $s2 to memory address Oxffl4 (this is where al3] is, soa[3] becomes, -10), writes $s3 to memory address Oxfif8 (this is where a[4] is, soa[4] becomes 1), and writes the return address to Oxfifc, which does not affect values in array v.Now the values of array V are: al 0 5 ote 7 1 Gtfea 7 1 pl so 2.40.6 When the sort ( ) procedureentersits main loop, the elements of array v are sorted without any interference from other stack accesses. The resulting sorted Unfortunately, this is not the end of the chaos caused by the original bug in mya] loc. When the sort () function begins restoring registers, Sra is read the (luckily) unmodified location where it was saved. Then $80 is read from memory at address Oxtfec (this is where a[1] is), $s1 is read from address Oxff0 (this is where al2] is), $52 is read from address Oxfi¥4 (this is where a[3] is), and $33 is tead from address Oxfff8 (this is where a[4] is). When sort() returns to ma in( ), registers $60 and $s1 are supposed to keep n and the address of array V.As a result, after sort ( retums to ma in( ), mand v are: a [mis S0Visa Lelementaray of ntessrs hat begns at address 5 B | 55 Sovisa Selement array of tesers that begns at address 5 If we were to actually attempt to access (e.g. print out) elements of array v in the main() function after this point, the first hy would result in a bus error due to non-aligned address, If MIPS were to tolerate non-aligned accesses, we would print ‘out whatever values were at the address v points to (note that this is not the same address to which my_init wrote its values), a | 7620 3606 31.2 a | 72 wb, | 3625 3.1.3 a [277 we b, | 205 108 314 = | 730 , | 1560 315 = | 730 wb, | 1560 316 ‘a | 101110010 b, | oxonto100110 | ‘The attraction is that each octal digit contains one of 8 different characters (0-7). Since with 3 binary bits you can represent 8 different patterns, in octal each digit requires exactly 3 binary bits. You can write down the conversion directly. $70 Chapter 3 Sokitions Solution 3.2 wb. | 4765 A877 ‘The attraction is that each hex digit contains one of 16 different characters (0-9, A-E). Since with 4 binary bits you can represent 16 different patterns, in hex each digit requires exactly 4 binary bits. And bytes are by definition 8 bits long, so two hex digits are all that are required to represent the contents of 1 byte. S71. Solution 3.3 331 ‘@ | Urderiow 21) b, | Neier 8) 1258, which does not ft into an Bit SM format) :146, which does not ft into an SM format) a | Neher 2) b [Nein £ R a [2108-47 ‘a | 200+ 105= 255 (305) we, | 247 237 = 255 (BA) Chapter Solution 3.4 341 50x23 soe |__| serie | meres |e tials 20000101000 | 000000000000, + [Prad= od-riand | cian | c00 00101 000 | 00000101 c00| (sifted qxooun | c00.001010000 | 00000 401 c00 Fea Wer oxoo1 | c20.01 010000 | 00000 101 co0 2 [ea rross wean | 06x00 | 000001010 00 | ooo 0088 000 (shitvard eoioo1 | c00010100000 | ovo 444. c00 Fea Wer 0x00 | c00 10100000 | ooo 144. o00 3 [iw= 0.000 aaox00 | —a00 010100000 | 00004000, tshitMand 0300 [000 101000000 | coon 144. c00 Fe wer ‘ooo | 000 101 000000 | ooo 444. o00 4 [iw=O.n000 xno [0003101 000000 | 00001 444. o00 tshitvand caooio | co1 010000000 | ooo 144 c00 Rewer ‘ooo | 001 010000000 | ono 4. 000 3 [ed Fred's and | 00001 | ~oo1 010000 o00 | oxox 344.000 cswtvend xno | 010100000000 | ooo 414. c00 Tener aa0000 | 010100000000 | oon 1,000. © [i@= 0.0000 x00 cot ox0000000 | ono 444 c00 cswtvend ‘0000 | 101 000000000 | oonona x44. c00 Fe Mer x0000 | 101 000000000 | oon 44. 000 Bb. 66x 04 OES ee [anv coox00 | ccooooi01i0 | 00000000000, + [= On0% «0300 | c09000110 110 | 00000000000, Lshitvand «aa0x00 | c00 01 101 100 | 00000000000, Ft er ‘ooo | c00.01 101 100 | 00000000000 2 [i@=0.n000 xooio [009001101 100 | 00000000000, sitar ‘ooo coo 11 011 000 | 00000000000, Few wer ‘ooo | c00.11 011 000 | 00000000000

You might also like