Instruction Sets (Chapter 3)
Computer Arithmetic (Chapter 4)
Datapath and Control
|
Sample QuestionsWrite a MIPS Assembly language subroutine that reverses a null-terminated
string. The address of the string is passed in # 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
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 Repeat the above question for the Show the 8-bit twos-complement representation for the following decimal values:
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 What is the range of the MIPS What limitations are there on the range of the MIPS What limitations are there on the range of the MIPS What does sign extention mean and when is it used? .Why doesn't a single-cycle datapath use a microprogrammed control unit? |