Suppose that the data segment starts at address 0x10010000 and
you have the following code:
- What is the address of the label value?
- What is the address of the label num?
- What is the address of the label chars?
- Assume that $t0 contains the starting address of the data segment.
What instruction will load the address of chars into $t1?
- Assume that $t0 contains the starting address of the data segment.
Write an instruction to store the contents of $t2 into num.
- Assume that $t0 contains the starting address of the data segment.
Write an instruction to load the fourth byte of chars into $t3.
- 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.
Given the following data segment:
.data
length: .word 25
width: .word 45
area: .word
- Write the MIPS statements that are equivalent to the following Java
statement, using the variable names: area = length * width;
- Write the MIPS statements to print area, using the variable name.
- Write the MIPS statements that are equivalent to the following Java
statement, without using the variable names: area = length * width;
- Write the MIPS statements to print area, without using the variable name.
- Trace the following code by keeping track of the values of
the variables one, two, three, four, and five, and registers
$t0 through $t5, $s0 through $s4, and $v0 and $a0. What is output by
the code if the user enters 3, 4, and 5?
.data
one: .word 0
two: .word 0
three: .word 0
four: .word 0
five: .word 0
prompt: .asciiz "\nenter three numbers: "
result: .asciiz "\nthe number is: "
.globl main
.text
main:
lui $t0, 0x1001
move $t1, $t0
addi $t2, $t0, 4
addi $t3, $t0, 8
addi $t4, $t3, 12
addi $t5, $t4, 23
li $v0, 4
move $a0, $t4
syscall
li $v0, 5
syscall
sw $v0, 0($t1)
li $v0, 5
syscall
sw $v0, 0($t2)
li $v0, 5
syscall
sw $v0, 0($t3)
lw $s0, 0($t1)
lw $s1, 0($t2)
mult $s0, $s1
mflo $s2
sw $s2, 12($t1)
lw $s3, 0($t3)
mult $s2, $s3
mflo $s4
sw $s4, 12($t2)
li $v0, 4
move $a0, $t5
syscall
li $v0, 1
lw $a0, 12($t0)
syscall
li $v0, 4
move $a0, $t5
syscall
li $v0, 1
lw $a0, 8($t3)
syscall
- Trace the following code by keeping track of the values of
the array nums, and registers
$t0 through $t3, $v0 and $a0. What is output by
the code?
.data
# create an array of 5 ints and initialize the array elements
# nums[0] = 5 nums[1] = 10 nums[2] = 15 nums[3] = 20 nums[4] = 25
nums: .word 5, 10, 15, 20, 25
blanks: .asciiz " "
result: .asciiz "the array contains: "
.globl main
.text
main:
lui $t0, 0x1001
ori $t1, $t0, 0
li $t2, 5
one: beqz $t2, two
lw $t3, 0($t1)
add $t3, $t3, $t2
sw $t3, 0($t1)
addi $t1, $t1, 4
addi $t2, $t2, -1
b one
two: ori $t1, $t0, 0
li $t2, 0
li $t3, 5
li $v0, 4
addi $a0, $t0, 22
syscall
three: bge $t2, $t3, four
lw $a0, 0($t1)
li $v0, 1
syscall
addi $a0, $t0, 20
li $v0, 4
syscall
addi $t1, $t1, 4
addi $t2, $t2, 1
b three
four:
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: "
- Write the code to read 100 ints into nums.
- 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.
- Assume that you have already written the code to read 100 ints
into nums. Write the code to print out every array element.
- 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]).
- 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.
- 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]).
- Write the code to read 100 chars into mychars.
- Assume that you have already written the code to read 100 chars into
mychars. Write the code to print out every array element.
- 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.