Bài tập tổ chức máy tính ,giúp cho sinh viên khoa điện tử viễn thông luyện tập các kiến thức đã học về lệnh assemble và mã lệnh máy . Cung cấp bài tập cơ bản ,các tài liệu tham khảo.Bài tập chương hai .
Trang 1Computer Organization Homework 2
1) For the following C statement, what is the corresponding MIPS assembly code? Assume that the variables i and j are assigned to registers $s0 and $s1, respectively Assume that the base address of the arrays A and B are in registers $s6and $s7, respectively
B[8] = A[i-j];
2) For the following MIPS assembly instructions, what is the corresponding C statement? Assume that the variables f and g are assigned to registers $s0 and $s1, respectively Assume that the base address of the arrays A and B are
in registers $s6 and $s7, respectively
sll $t0, $s0, 2 # $t0 = f * 4
add $t0, $s6, $t0 # $t0 = &A[f]
sll $t1, $s1, 2 # $t1 = g * 4
add $t1, $s7, $t1 # $t1 = &B[g]
lw $s0, 0($t0) # f = A[f]
addi $t2, $t0, 4
lw $t0, 0($t2)
add $t0, $t0, $s0
sw $t0, 0($t1)
3) For the MIPS assembly instructions in Exercise 2, rewrite the assembly code
out the same function
4) Translate the following MIPS code to machine language:
addi $t0, $s6, 4
add $t1, $s6, $0
sw $t1, 0($t0)
lw $t0, 0($t0)
add $s0, $t1, $t0
5) Translate the following C code to MIPS assembly code Use a minimum
number of instructions Assume that the values of a, b, i, and j are in
registers $s0, $s1, $t0, and $t1, respectively Also, assume that register $s2 holds the base address of the array D
for(i=0; i<a; i++)
for(j=0; j<b; j++)
D[4*j] = i + j;
Trang 26) Convert the following machine code program to assembly for MIPS
00011010010000000000000000000011
00100000000000000000000000000000
10101110001010110000000000000000
10101110001010100000000000000010
00100001001010010000000000001000
7) Pseudo-instructions are not part of the MIPS instruction set but often appear
in MIPS programs The assembler then has to convert them into a small set
of real MIPS instructions For each of the following pseudo-instructions, convert them to a very short equivalent sequence of real MIPS instructions
If you need a temporary register, you should use $at
Note that “small” is a constant that fits in 16 bits (i.e small enough for the immediate field of an instruction), and “big” is a constant that is 32 bits (i.e too long for the immediate field)
8) Assume that we would like to expand the MIPS register fi le to 128 registers and expand the instruction set to contain four times as many instructions
a How this would this affect the size of each of the bit fields in the R-type instructions?
b How this would this affect the size of each of the bit fields in
the I-type instructions?
9) Find the shortest sequence of MIPS instructions that extracts bits 16 down to
11 from register $t0 and uses the value of this field to replace bits 31 down
to 26 in register $t1 without changing the other 26 bits of register $t1
10) Show how the value 0xabcdef12 would be arranged in memory of a
little-endian and a big-endian machine Assume the data is stored starting at address 0
The end