Homework: Memory Access

 

  1. Write the assembly instruction to set $t1 to the value 0x10010000
  2. Suppose $t1 contains the value 0x10010000. Write an instruction to change the value in $t1 to 0x1001000C.
  3. Write the assembly instructions to set $t1 to the value 0x1001002C

Suppose that the data segment starts at address 0x10010000 and you have the following code:

     .data
value:   .word   15
num:     .word   50
chars:   .space  10
  1. What is the address of the label value?
  2. What is the address of the label num?
  3. What is the address of the label chars?
  4. Assume that $t0 contains the starting address of the data segment. What instruction will load the address of chars into $t1?
  5. Assume that $t0 contains the starting address of the data segment. Write an instruction to store the contents of $t2 into num.
  6. Assume that $t0 contains the starting address of the data segment. Write an instruction to load the fourth byte of chars into $t3.
  7. Assume that $t0 contains the starting address of the data segment. Write the instructions to copy the value from num to $t3, add 1 to it, and then copy the result back into num.


  8. Given the following data segment:
              .data
    length:   .word     25
    width:    .word     45
    area:     .word
    
  9. Write the MIPS statements that are equivalent to the following Java statement, using the variable names: area = length * width;
  10. Write the MIPS statements to print area, using the variable name.
  11. Write the MIPS statements that are equivalent to the following Java statement, without using the variable names: area = length * width;
  12. Write the MIPS statements to print area, without using the variable name.


  13. Given the following data segment:
              .data
    nums:     .space    400        # space for an array of 100 ints
    max:      .word
    count:    .word
    mychars:  .space    100        # space for an array of 100 chars
    prnums:   .asciiz   "Enter a number: "
    prch:     .asciiz   "Enter a character: "
    
  14. Write the code to read 100 ints into nums.
  15. Write the code to read positive ints into nums. Stop reading when the user enters 0. Keep track of how many ints you read (not including the zero) and store that value in count.
  16. Assume that you have already written the code to read 100 ints into nums. Write the code to print out every array element.
  17. Assume that you have already written the code to read 100 ints into nums. Write the code to print out every other array element (nums[0], nums[2], nums[4], ..., nums[98]).
  18. Assume that you have already written the code to read 100 ints into nums. Write the code to find the largest int and store it in max.
  19. Assume that you have already written the code to read 100 ints into nums. Write the code to print nums backward (print nums[99], nums[98], ..., nums[0]).
  20. Write the code to read 100 chars into mychars.
  21. Assume that you have already written the code to read 100 chars into mychars. Write the code to print out every array element.
  22. Assume that you have already written the code to read 100 chars into mychars. Write the code to count the number of times the character 'a' appears in the array, and print that count.

Email Me | Office Hours | My Home Page | Department Home | MCC Home Page

© Copyright Emmi Schatz 2009