• Home
  • Textbooks
  • Digital Design and Computer Architecture
  • Architecture

Digital Design and Computer Architecture

David M. Harris, Sarah L. Harris

Chapter 6

Architecture - all with Video Answers

Educators


Chapter Questions

01:25

Problem 1

Give three examples from the MIPS architecture of each of the architecture design principles: (1) simplicity favors regularity; (2) make the common case fast; (3) smaller is faster; and (4) good design demands good compromises. Explain how each of your examples exhibits the design principle.

Manik Pulyani
Manik Pulyani
Numerade Educator
00:53

Problem 2

The MIPS architecture has a register set that consists of 32-bit registers. Is it possible to design a computer architecture without a register set? If so, briefly describe the architecture, including the instruction set. What are advantages and disadvantages of this architecture over the MIPS architecture?

James Kiss
James Kiss
Numerade Educator
00:55

Problem 3

Consider memory storage of a 32-bit word stored at memory word 42 in a byte-addressable memory.
(a) What is the byte address of memory word 42 ?
(b) What are the byte addresses that memory word 42 spans?
(c) Draw the number $0 \mathrm{xFF} 223344$ stored at word 42 in both big-endian and little-endian machines. Your drawing should be similar to Figure 6.4. Clearly label the byte address corresponding to each data byte value.

Vysakh M
Vysakh M
Numerade Educator
02:13

Problem 4

Repeat Exercise $6.3$ for memory storage of a 32 -bit word stored at memory word 15 in a byte-addressable memory.

Ashley High
Ashley High
Numerade Educator
11:57

Problem 5

Explain how the following program can be used to determine whether a computer is big-endian or little-endian:
1 i \$t0, 0xABCD9876
sw $\$ \mathrm{t} 0,100(\$ 0)$
$1 \mathrm{~b} \$ 55,101(\$ 0)$

Chris Trentman
Chris Trentman
Numerade Educator
02:41

Problem 6

Write the following strings using ASCII encoding. Write your final answers in hexadecimal.
(a) $\mathrm{SOS}$
(b) Cool!
(c) (your own name)

Aaron Goree
Aaron Goree
Numerade Educator
02:25

Problem 7

Repeat Exercise $6.6$ for the following strings.
(a) howdy
(b) lions
(c) To the rescue!

Alice .
Alice .
Numerade Educator
07:47

Problem 8

Show how the strings in Exercise $6.6$ are stored in a byte-addressable memory on (a) a big-endian machine and (b) a little-endian machine starting at memory address $0 \times 1000100 \mathrm{C}$. Use a memory diagram similar to Figure $6.4$. Clearly indicate the memory address of each byte on each machine.

Jacquelyn Trost
Jacquelyn Trost
Numerade Educator
02:07

Problem 9

Repeat Exercise $6.8$ for the strings in Exercise $6.7 .$

Gideon Idumah
Gideon Idumah
Numerade Educator
01:17

Problem 10

Convert the following MIPS assembly code into machine language. Write the instructions in hexadecimal.
add $\$ t 0, \$ s 0, \$ s 1$
$1 \mathrm{w} \$ \mathrm{t} 0,0 \times 20(\$ \mathrm{t} 7)$
add $\$ t 0, \$ s 0, \$ s 1$
lw $\$ t 0,0 \times 20(\$ t 7)$
addi $\$ s 0, \$ 0,-10$
addi $\$ 50, \$ 0,-10$

Varsha Aggarwal
Varsha Aggarwal
Numerade Educator
04:42

Problem 11

Repeat Exercise $6.10$ for the following MIPS assembly code:
addi $\$ 50 . \$ 0.73$
sw $\$ t 1,-7(\$ t 2)$
addi $\$ s 0, \$ 0,73$
sw $\$ \mathrm{t} 1,-7(\$ \mathrm{t} 2)$
sub $\$ \mathrm{t} 1, \$ s 7, \$ s 2$
sub $\$ \mathrm{t} 1, \$ \mathrm{~s} 7, \$ \mathrm{~s} 2$

Bobby Barnes
Bobby Barnes
University of North Texas
02:33

Problem 12

Consider I-type instructions.
(a) Which instructions from Exercise $6.10$ are I-type instructions?
(b) Sign-extend the 16-bit immediate of each instruction from part (a) so that it becomes a 32 -bit number.

Narayan Hari
Narayan Hari
Numerade Educator
01:21

Problem 13

Repeat Exercise $6.12$ for the instructions in Exercise $6.11$.

Narayan Hari
Narayan Hari
Numerade Educator
05:01

Problem 14

Convert the following program from machine language into MIPS assembly language. The numbers on the left are the instruction addresses in memory, and the numbers on the right give the instruction at that address. Then reverse engineer a high-level program that would compile into this assembly language routine and write it. Explain in words what the program does. \$a is the input, and it initially contains a positive number, $n . \$ v 0$ is the output.
$\begin{array}{ll}0 \times 00400000 & 0 \times 20080000 \\ 0 \times 00400004 & 0 \times 20090001 \\ 0 \times 00400008 & 0 \times 0089502 A \\ 0 \times 0040000 C & 0 \times 15400003 \\ 0 \times 00400010 & 0 \times 01094020 \\ 0 \times 00400014 & 0 \times 21290002 \\ 0 \times 00400018 & 0 \times 08100002 \\ 0 \times 0040001 C & 0 \times 01001020 \\ 0 \times 00400020 & 0 \times 03 \mathrm{E} 00008\end{array}$

Shelby Mohamed
Shelby Mohamed
Numerade Educator
04:17

Problem 15

Repeat Exercise $6.14$ for the following machine code. $\$ \mathrm{a} 0$ and $\$ a 1$ are the inputs. $\$ a 0$ contains a 32 -bit number and $\$ a 1$ is the address of a 32 -element array of characters (char).
$\begin{array}{ll}0 \times 00400000 & 0 \times 2008001 F \\ 0 \times 00400004 & 0 \times 01044806 \\ 0 \times 00400008 & 0 \times 31290001 \\ 0 \times 0040000 C & 0 \times 0009482 A \\ 0 \times 00400010 & 0 \times A 0 A 90000 \\ 0 \times 00400014 & 0 \times 20 A 50001 \\ 0 \times 00400018 & 0 \times 2108 F F F F \\ 0 \times 0040001 C & 0 \times 0501 F F F 9 \\ 0 \times 00400020 & 0 \times 03 E 00008\end{array}$

Shelby Mohamed
Shelby Mohamed
Numerade Educator
01:46

Problem 16

The nori instruction is not part of the MIPS instruction set, because the same functionality can be implemented using existing instructions. Write a short assembly code snippet that has the following functionality: $\$ \mathrm{t} 0=\$ \mathrm{t} 1 \mathrm{NOR}$ $0 \times F 234$. Use as few instructions as possible.

James Kiss
James Kiss
Numerade Educator
05:26

Problem 17

Implement the following high-level code segments using the s $1 \mathrm{t}$ instruction. Assume the integer variables $g$ and $h$ are in registers $\$ s 0$ and $\$ s 1$, respectively.
(a) if $(g>h)$
$$
\begin{aligned}
g &=g+h: \\
g &=g-h:
\end{aligned}
$$
(b) if $(g>=h)$
$$
\begin{aligned}
g &=g+1: \\
h &=h-1:
\end{aligned}
$$
(c) if $(g<=h)$
$$
g=0 \text {; }
$$
else
$$
h=0 \text {; }
$$

WZ
Wen Zheng
Numerade Educator
01:21

Problem 18

Write a function in a high-level language for int find 42 (int array[]. int size). size specifies the number of elements in array, and array specifies the base address of the array. The function should return the index number of the first array entry that holds the value 42 . If no array entry is 42 , it should return the value $-1$.

Adriano Chikande
Adriano Chikande
Numerade Educator
02:34

Problem 19

The high-level function strcpy copies the character string src to the character string dst (see page 360 ).
(a) Implement the stropy function in MIPS assembly code. Use s 0 for i .
(b) Draw a picture of the stack before, during, and after the strcpy function call. Assume $\$ s p=0 x 7 F F F F F 00$ just before strcpy is called.

Ernest Castorena
Ernest Castorena
Numerade Educator
03:30

Problem 20

Convert the high-level function from Exercise $6.18$ into MIPS assembly code.

James Chok
James Chok
Numerade Educator
01:00

Problem 21

Consider the MIPS assembly code below. funcl, func2, and func 3 are non-leaf functions. funce is a leaf function. The code is not shown for each function, but the comments indicate which registers are used within each function.
$0 \times 00401000$
$0 \times 00401020$ funcl: $\ldots$ jai func2 $\quad$ #? uncl uses $\$ s 0-\$ s 1$
(a) How many words are the stack frames of each function?
(b) Sketch the stack after func 4 is called. Clearly indicate which registers are stored where on the stack and mark each of the stack frames. Give values where possible.

James Kiss
James Kiss
Numerade Educator
02:13

Problem 22

Each number in the Fibonacci series is the sum of the previous two numbers. Table $6.16$ lists the first few numbers in the series, $f i b(n)$.
(a) What is $f i b(n)$ for $n=0$ and $n=-1$ ?
(b) Write a function called $\mathrm{fi} \mathrm{b}$ in a high-level language that returns the Fibonacci number for any nonnegative value of $n$. Hint: You probably will want to use a loop. Clearly comment your code.
(c) Convert the high-level function of part (b) into MIPS assembly code. Add comments after every line of code that explain clearly what it does. Use the SPIM simulator to test your code on $f i b(9)$. (See the Preface for how to install the SPIM simulator.)

Sriram Soundarrajan
Sriram Soundarrajan
Numerade Educator
03:19

Problem 23

Exercise 6.23 Consider C Code Example 6.27. For this exercise, assume factorial is called with input argument $n=5$.
(a) What value is in v 0 when factorial returns to the calling function?
(b) Suppose you delete the instructions at addresses 0 \times 98 and 0 \times B C that save and restore r a. Will the program (1) enter an infinite loop but not crash; (2) crash (cause the stack to grow beyond the dynamic data segment or the $\mathrm{PC}$ to jump to a location outside the program); (3) produce an incorrect value in $\$ v 0$ when the program returns to loop (if so, what value?), or (4) run correctly despite the deleted lines?

Florencia Cuzmar
Florencia Cuzmar
Numerade Educator
04:22

Problem 24

Ben Bitdiddle is trying to compute the function $f(a, b)=2 a+3 b$ for nonnegative $b$. He goes overboard in the use of function calls and recursion and produces the following high-level code for functions $f$ and $f 2 .$

Bharat Bairagi
Bharat Bairagi
Numerade Educator
00:40

Problem 25

Convert the following beq, $j$, and $j$ a 1 assembly instructions into machine code. Instruction addresses are given to the left of each instruction.
(a)
$\begin{array}{lc}0 \times 00401000 & \text { beq \$t0. \$s1, } \\ 0 \times 00401004 & \cdots \\ 0 \times 00401008 & \cdots \\ 0 \times 0040100 C & \text { Loop: } & \cdots\end{array}$
(b)
$0 \times 00402040$ done: $\ldots$ $0 \times 00403100$ back: $\ldots$ $0 \times 00405000$ $\ldots$ beq \$t9. \$s7. back
(c) jat func
(d)
$0 \times 00403000$
$\cdots$
$0 \times 0041147 \mathrm{C}$
func:
(e)
$0 \times 00403004$ back: ...
$0 \times 0040400 c \quad j \quad$ back

James Kiss
James Kiss
Numerade Educator
01:46

Problem 26

Consider the following MIPS assembly language snippet. The numbers to the left of each instruction indicate the instruction address.

James Kiss
James Kiss
Numerade Educator
01:14

Problem 27

Consider the following C code snippet.

James Kiss
James Kiss
Numerade Educator
00:31

Problem 28

Consider the following high-level function.

William Cornejo
William Cornejo
Numerade Educator
View

Problem 29

What is the range of instruction addresses to which conditional branches, such as beq and bne, can branch in MIPS? Give your answer in number of instructions relative to the conditional branch instruction.

James Kiss
James Kiss
Numerade Educator
01:17

Problem 30

The following questions examine the limitations of the jump instruction, $j$. Give your answer in number of instructions relative to the jump instruction.
(a) In the worst case, how far can the jump instruction (j) jump forward (i.e., to higher addresses)? (The worst case is when the jump instruction cannot jump far.) Explain using words and examples, as needed.
(b) In the best case, how far can the jump instruction (j) jump forward? (The best case is when the jump instruction can jump the farthest.) Explain.
(c) In the worst case, how far can the jump instruction (j) jump backward (to lower addresses)? Explain.
(d) In the best case, how far can the jump instruction (j) jump backward? Explain.

James Kiss
James Kiss
Numerade Educator
01:09

Problem 31

Explain why it is advantageous to have a large address field, addr, in the machine format for the jump instructions, $j$ and jal.

Adam Conner
Adam Conner
Numerade Educator
01:30

Problem 32

Write assembly code that jumps to an instruction 64 Minstructions from the first instruction. Recall that 1 Minstruction $=2^{20}$ instructions $=$ $1,048,576$ instructions. Assume that your code begins at address $0 \times 00400000$. Use a minimum number of instructions.

James Kiss
James Kiss
Numerade Educator
03:30

Problem 33

Write a function in high-level code that takes a 10 -entry array of 32 -bit integers stored in little-endian format and converts it to big-endian format. After writing the high-level code, convert it to MIPS assembly code. Comment all your code and use a minimum number of instructions.

James Chok
James Chok
Numerade Educator
05:34

Problem 34

Consider two strings: string1 and string2.
(a) Write high-level code for a function called concat that concatenates (joins together) the two strings: void concat (char string 1[] . char string2 [ ]. char stringconcat []). The function does not return a value. It concatenates stringl and string 2 and places the resulting string in stringconcat. You may assume that the character array stringconcat is large enough to accommodate the concatenated string.
(b) Convert the function from part (a) into MIPS assembly language.

Chris Trentman
Chris Trentman
Numerade Educator
03:36

Problem 35

Write a MIPS assembly program that adds two positive singleprecision floating point numbers held in $\$ s 0$ and $\$ s 1$. Do not use any of the MIPS floating-point instructions. You need not worry about any of the encodings that are reserved for special purposes (e.g., 0, NANs, etc.) or numbers that overflow or underflow. Use the SPIM simulator to test your code. You will need to manually set the values of $\$ s 0$ and $\$ s 1$ to test your code. Demonstrate that your code functions reliably.

Shelby Mohamed
Shelby Mohamed
Numerade Educator
03:28

Problem 36

Show how the following MIPS program would be loaded into memory and executed.
(a) First show the instruction address next to each assembly instruction.
(b) Draw the symbol table showing the labels and their addresses.
(c) Convert all instructions into machine code.
(d) How big (how many bytes) are the data and text segments?
(e) Sketch a memory map showing where data and instructions are stored.

Shelby Mohamed
Shelby Mohamed
Numerade Educator
02:13

Problem 37

Repeat Exercise $6.36$ for the following MIPS code.

Ashley High
Ashley High
Numerade Educator
01:30

Problem 38

Show the MIPS instructions that implement the following pseudoinstructions. You may use the assembler register, $\$$ at, but you may not corrupt (overwrite) any other registers.
(a) addi \$to. \$s2, imm_31:0
(b) $1 \mathrm{w} \$ \mathrm{t} 5, \mathrm{imm}_{31: 0}(\$ \mathrm{~s} 0)$
(c) ro1 \$t0. \$t1, 5 (rotate \$t1 left by 5 and put the result in \$t0)
(d) ror $\$ s 4, \$ \mathrm{t} 6,31$ (rotate $\$ \mathrm{t} 6$ right by 31 and put the result in $\$ s 4$ )

James Kiss
James Kiss
Numerade Educator
01:40

Problem 39

Repeat Exercise $6.38$ for the following pseudoinstructions.
(a) beq $\$ t 1, i m m_{31: 0}, L$
(b) ble $\$ \mathrm{t} 3, \$ \mathrm{t} 5, \mathrm{~L}$
(c) bgt $\$ t 3, \$ t 5, L$
(d) bge $\$ t 3, \$ t 5, L$

Bahar Tehranipoor
Bahar Tehranipoor
Numerade Educator