CompOrg Fall 2000 - Test #2 Review


Topics

Instruction Sets (Chapter 3)

  • MIPS Instructions:
    • Aritmetic: add, sub, addi, addu, subu, mult, div
    • Memory: lw, sw, lb, sb, lbu
    • Conditional Branch: beq, bne, slt, slti
    • Jump, subroutine calljr, j, jal
    • Logical: or, and, ori, andi, sll, srl, sra
  • Subroutines:
    • Call and return (jal and jr
    • Calling conventions ($a0, $a1, ..., $v0, $v1).
    • Using the stack to save/restore values.
    • Recursion
  • Dealing with strings (bytes).
  • Machine code and Instruction formats
    • You don't need to memorize these, just be able to recognize them and tell what fields are used for what
  • SPIM/MIPS:
    • Given some MIPS assembly language, you should be able to describe what it does and/or comment the code
    • Given an English description or some C code, you should be able to write MIPS assembly language
    • Know how to write a subroutine!

Computer Arithmetic (Chapter 4)

  • Know twos-complement representation inside-and-out!
  • Be able to do binary addition using signed numbers
  • Understand the basic structure of a Ripple-Carry Adder
  • Be able to recognize a Carry-Lookahead Adder, and be able to provide the equation/logic for generating the first couple carrys (the LS carrys)
  • Know what LS stands for (also MS).
  • Signed Multiplication: The traditional algorithm and Booth's Algorithm
  • Be able to do pencil-and-paper Binary Division
  • Be able to tell the decimal equivalent of a binary IEEE floating point number.
  • Be able to give the IEEE floating point representation given a decimal floating point number.
  • Be able to describe how to do multiplication and addition with binary floating point numbers.

Datapath and Control

  • Be able to derive Figure 5.33 (just kidding!)
  • Understand that all datapath components can be described using Boolean Logic.
  • Understand how a register file works.
  • Be able to create a simple datapath given a couple of simple instructions.
  • Be able to augment the datapath described in lectures and the book to support additional instructions.
  • Be able to describe how control signals are generated (boolean functions of what?).
  • Understand what a microprogrammed control unit is (the general idea is all that is necessary).
  • Understand what components in a datapath hold state and what components are purely combinational.
  • Understand the tradeoffs between a single-cycle and multi-cycle datapath implementation.
  • Understand how a multi-cycle motorcycle works.

Sample Questions

Write a MIPS Assembly language subroutine that reverses a null-terminated string. The address of the string is passed in $a0. No return value is needed, the string (the memory) is replaced with the reversed string.

	

# reverse takes the address of the string in $a0
# and reverses the string in memory.

reverse:
	move $t0,$a0        # $t0 is the address of the string


# first find the end of the string
lp1:		
	lb $t1,0($t0)         # get the next char from the string
	beq $t1,$zero,found   # if it's zero - we found the end
	addi $t0,$t0,1        # increment the pointer
	j lp1                 

found:	
# we found the end of the string, $t0 now points to the terminating null.
# if this is the first character, there is no string so quit!
	beq $t0,$a0,done
	
# at least one character - do the reversal
	move $t1,$a0		# t1 is the start of the string
	sub  $t0,$t0,1		# t0 is the last char

loop:	
	beq $t0,$t1,done	# if the pointers are the same, done
	slt $t5,$t0,$t1
	bne $t5,$zero,done	# if t0 < t1 we are done
# reverse the 2 character positions

	lb $t2,0($t1)		# get the first char
	lb $t3,0($t0)		# get the last char
	sb $t2,0($t0)		# store the first at the end
	sb $t3,0($t1)           # store the last at the beginning

	add $t1,$t1,1		# increment the "first" pointer
	sub $t0,$t0,1           # decrement the "last" pointer
	j loop                  # go do it again
	
done:		
	jr $ra			# return

Write a MIPS assembly language subroutine that computes the sum of the first n integers (starting at 1). If n is 4, the subroutine should return 1+2+3+4 = 10.

Your subroutine will accept the number n in register $a0 and return the answer in register $v0.

IMPORTANT! Your subroutine must be recursive! It must call itself to compute the answer. If we call the function your subroutine computes f(n) then we can express the answer as f(n) = n + f(n-1) with the base case f(1)=1. So if your subroutine is called with the value 4, it should call itself to compute f(3) and add 4. If your subroutine is called with the value 1, you can just return 1.


# recursive subroutine to calculate the sum of the first n
# positive integers. 
# n is passed in as $a0, we return the sum of the first n
# integers in $v0

sum:
	addi $sp,$sp,-8     # Make room for 2 regs. on the stack
	sw $ra,0($sp)       # save return address
	sw $a0,4($sp)       # save original $a0 (n)

	li $t1,1            # check to see if n==1
	bne $t1,$a0, compute

# n==1, so return the answer 1
	li $v0,1
	j done

# n > 1
compute:
	addi $a0,$a0,-1    # $a0 is now n-1
	jal sum            # compute the sum of the first n-1 ints.
	lw $a0,4($sp)      # get our original value of n
	add $v0,$v0,$a0    # and add to the result returned

done:	
	lw $ra,0($sp)      # restore the return address
	addi $sp,$sp,8     # restore the stack pointer
	jr $ra             # return


Given the datapath in figure 5.17 (page 358), consider what changes would need to be made to support the addi instruction. Draw in any additional components needed and describe and additional controls that will be necessary. Also describe the how each component in the datapath will be used (those that are used) by the addi instruction.

Repeat the above question for the jal instruction.


Show the 8-bit twos-complement representation for the following decimal values:

  • 17
  • 100
  • -100
  • 0

17 is 16+1: 00010001

100 is 64+32+4: 01100100

-100 is 100 inverted , then add 1: 01100100 -> 10011011 -> 10011100

0 is 00000000


What is the decimal value of the binary floating point number 11.011?

3 + (3/8) = 3.375

What is the binary representation of 13.75?

1101.11

What is the normalized binary floating point representation of 13.75?

1.10111 x 2^8

What is the decimal value of the following IEEE 32 bit floating point number?

1 10000001 01000000000000000000000

-5 (see page 280).


Show the pencil-and-paper division of the binary values 00000111 divided by 00000010 (7 divided by 3).

Show how to use Booth's algorithm to compute the product of -6 and 13 (use 8 bit signed integers).

Show how to use the traditional binary multiplication algorithm to compute the product of -6 and 13 (use 8 bit signed integers).


Why is the range of the MIPS beq instruction limited?

What is the range of the MIPS beq instruction? (how many instructions away can you jump?

What limitations are there on the range of the MIPS j instruction?

What limitations are there on the range of the MIPS jr instruction?

What does sign extention mean and when is it used?

.

Why doesn't a single-cycle datapath use a microprogrammed control unit?