Review for Final Exam.

Cs 354-1

 

The following questions were created to help you review for the final exam in cs354. To receive extra credit (up to 5 points on your exam such that your total exam score does not exceed 100 points), you must first contact Laura to sign-up to answer a particular section.  Based on your answers’ correctness and completeness you can receive up to 5 points on your exam.  Follow the handin instructions at the bottom of this page.  This assignment is due Tuesday, August 2nd at 8:30am.

 

Chapter 9

Part1:

  1. Describe the difference between jal and jr.

 

  1. Give an example using jal.

 

  1. Outline the general format of activation records (stack frames).

 

  1. Describe MIPS procedure for passing parameters to/from procedures.

 

  1. What is the purpose for procedures in a high-level language? Is there a point to having a procedure mechanism in assembly language?

 

  1. Explain the difference for passing parameters using registers, the stack or some in the register and some in the stack. What are the pros and cons?

 

  1. Outline what is needed in the activation record.

 

Part 2:

1. Detail the format of a basic stack frame.

 

  1. Give an example of a basic activation record creating a procedure addThree that is called from the main and takes three user defined integers passed as parameters to the method and returns their sum.

 

  1. Group the MIPS registers by their common usage. Explain when you would use the different groupings and state their pseudonyms.

 

  1. Which registers are we allowed to use in MIPS in a procedure and in the main body of a program?

 

  1. Describe the purpose of the frame pointer.  Does the frame pointer exist in SAL? MAL? TAL?

 

  1. Give a short example to illustrate the difference between the callee and the caller. Who should save variables, callee or caller?

 

  1. Write a brief MAL program to implement the factorial function recursively. The factorial is recursively defined by                                                                       factorial (0) = 1                                                                                                  factorial (x) = x * factorial (x -1 )

 

Chapter 10

Part 1:

1.      Describe the purpose of CO and C1.

 

2.      What is the purpose of the compiler and assembler and why are they important.

 

3.      Explain the fundamental differences between SAL, MAL and TAL. Why did we learn these three languages in class.

 

4.      What is the difference between add and addi? Is there an advantage to encourage using immediates?

 

5.      What MAL instructions can you not use in TAL? How can you substitute other instructions to make up for the lost instructions?

 

6.      Give two ways that the MAL instruction

 

bgt $3, $18, br_label

 

can be translated into TAL instruction(s).

 

7.      Identify two MAL instructions that would most likely use $1 for their TAL synthesis. Give both the MAL instruction and its TAL synthesis.

Part 2:

1. What is the purpose for syscall in TAL? How and when is it used?

 

2.      Using three registers, give a code example that multiples two numbers and prints out their product, then divides two numbers and prints out their remainder in TAL.

 

3.      Translate the following MAL code segment into TAL (if necessary) and machine code. The starting address for the instructions is 0x0008 8800

 

and $5, $6, $18

beq $5, $0, br1

lui $20, 0x66aa

br1:      lb $9, -8($20)

 

4.      Add comments to the TAL program on page 271 on page 267.

 

5.      Describe the processes for calculating the branch offset illustrated by a small example.

 

 

6.      What should the assembler do if the calculated branch offset is too large to fit into the offset field of an instruction?

 

Chapter 11

Part 1:

  1. Define the vocabulary terms from the chapter.

 

  1. Why is spin-waiting a bad idea for input/output programming?

 

  1. What would happen on a computer system that used a spin-wait loop to print a character if a printer jammed?

 

  1. Is asynchronous I/O a better solution than spin-waiting for very fast I/O devices? Why or why not?

 

  1. Does an assembly language programmer have any control over what type of I/O implementations are offered?

 

  1. When SAL executes a get instruction and nothing has been typed in, the instructions appears not to complete until a character is typed, leading to the notion of an instruction that might take an arbitrarily long time to complete. What are the problems that might result from such instructions? What are possible ways to avoid this problem?

 

  1. Write the MAL code to implement put for a variable declared as .byte.

 

Part 2:

1. Write the MAL code to implement get for a variable declared as .byte.

 

  1. Write the MAL code to implement get for a variable declared as .word.

 

  1. Write the MAL code to implement put for a variable declared as .float.

 

  1. Write the MAL code to implement puts.

 

  1. Write a MAL program that echoes the correct characters to display when characters are typed to the keyboard. Specifically handle the case of BACKSPACE, TAB and NEWLINE.

 

  1. What is the advantage of using DMA?

 

  1. Rewrite the program on page 304 using only a single increment or decrement by taking advantage of the fact that the sum of registers $15 and $16 is constant.

 

Chapter 12

Part 1:

  1. When and why is synchronization important?

 

  1. What happens when there is a synchronization failure and how can this failure be remedied?

 

  1. Explain the difference between an interrupt and a trap.

 

  1. Describe the events that occur when a program causes an exception. How is an exception resolved?

 

  1. Add code to kernel in Figure 12.4 to handle clock interrupts.

 

  1. Modify the kernel in Figure 12.4 to be reentrant.

 

  1. Execution of a simple exception handler can generally be accomplished in a few microseconds. User-interface I/O devices interrupt typically less than once per millisecond. What is the likelihood that the exception handler will be execution when another interrupt occurs? Can you think of nay reason that a trap handler is likely to see multiple interrupts pending concurrently?

Part 2:

1. Is an operating system important for a computer? Why or why not?

 

  1. What is the purpose of the kernel in MIPS?

 

  1. Create a program with a small jump table.

 

  1. Explain the purpose of a jump table and why they are encouraged to handle exception?

 

  1. Why would an interrupt mask be useful? Give an example.

 

  1. Is it possible for the exception handler to return control to a user program while the processor is still in kernel mode? What would be the effect if this were to happen?

 

  1. If a reentrant exception handler did not disable interrupts as it prepared to return control to the interrupted program, and was in the process of restoring the registers to their previous values when another interrupt occurred, could the registers still be restored correctly after the second interrupt was handled? What could go wrong?

 

  1. On a particular computer system, if a user types 256 characters consecutively without typing a newline or return character, the computer stops echoing the characters and responds to each additional character typed by echoing the bell character (^G). Give a plausible reason for what causes this behavior.

 

Chapter 6

Part 1:

  1. Describe the difference between addition and subtraction when dealing with floating point verses integer numbers.

 

  1. What is the importance of the hidden bit? Give an example when remembering the hidden is vital to achieving the correct answer.

 

  1. Explain the changes for the sign bit when adding, subtraction, multiplying and dividing floating point numbers.

 

  1. Give an example illustrating the four steps for multiplication.

 

  1. On some computers floating point multiply is actually faster than floating point addition. Since multiplication is more complex than addition, this is surprising. Can you think of a good reason why it might be faster?

 

  1. Give an example illustrating the four steps for division.

 

Part 2:

1. Give examples illustrating the difference between the four rounding strategies.

 

  1. Which rounding strategy is the best/worst and why?

 

  1. When could overflow occur when performing additive operations?

 

  1. When could underflow occur when performing additive operations?

 

  1. Give the bit patterns for two IEEE single-precision floating point numbers whose addtion would result in a denormalized number.

 

Chapter 13
Part 1:

  1. Show how to build a logical left shift (by 1 bit) function out of the minimal instruction set containing only a subtract and a branch if equal instruction

 

  1. An addition instruction can be synthesized by two subtraction instruction. However, it is not possible to synthesize a subtraction instruction from any number of addition instructions. What is the property of subtraction that makes the instruction inherently more powerful than addition?

 

  1. Produce two pieces of MAL code that perform the same task. One piece is to be shorter, but takes longer to execute than the second piece.

 

  1. Identify a scenario in which the compile time of a program would be an important measure of cost.

 

  1. The MIPS RISC architecture does not have an explicit no-op instruction. Give a single instruction that performs a no-op function.

 

Part 2:

1. The MAL code

li $18, 200

add $20, $21, $18

has a data dependency. Identify what the dependency is and what effect it would have on a pipelined machine.

 

  1. Pipelined instructions are accomplished within five stages. During those stages, when could bubbles be needed? Which stages could be postponed?

 

  1. What is the relationship between the number of pipeline stages and the number of conditional branch instructions in a program?

 

  1. What is the absolute mini8mum number of instructions necessary for a computer, if I/O is included? Design such a minimal instruction set.

 

  1. When is it desired to fill a delay slot, but no instruction is available that can be used, sometimes other, more sophisticated sequences are possible. In the example given on pages 351-352, suppose the delay slot were replaced with the instruction

addi $10, $10, 1

which was moved from the end of the loop. This code now executes correctly when the branch is not taken, but incorrectly when the loop is exited. What instruction could be inserted at endofloop to achieve the same functionality as the original program? Under what circumstances would you expect this code to perform better than before?

 

Chapter 14

Part 1:

  1. What defines a computer’s architecture?

 

  1. What architectural features correspond to a RISC architecture? A CISC architecture?

 

  1. Give an example of a machine for both a RISC or CISC architecture.

 

  1. A computer designed for a special application may have very special instructions that are explicitly designed for that application. Carrying this to an extreme, it is possible to build a computer that has only a single instruction: do_it. Identify an application where such an instruction might be appropriate.

 

  1. What is the importance of the integrated circuit? What is the difference between and integrated circuit and a microprocessor?

 

Part 2:

  1. What is the use and purpose of the Mode and Register sub-fields?

 

  1. Describe memory addressing in the Intel x86 architecture.

 

  1. Design a SAL instruction that permits addition between two equal-length vectors of arbitrary length. How many operands must be specified?

 

  1. Why might the B and T registers of the CRAY-1 computer be preferable to a cache memory? What is the disadvantage of this “explicit cache”?

 

  1. What is the purpose of the register windows in the SPARC?

 

HANDING IN YOUR ASSIGNMENT

To receive extra credit for your assignment, you must name your solution file exCrExam2.txt and submit it through the handin directory:

            cp exCrExam2.txt ~cs354-1/handin/login/ExCrExam2/.

where login is your login name for your CS account.