Documente Academic
Documente Profesional
Documente Cultură
Homework #4
1. Describe the difference between CISC and RISC architectures and compare the two
architectures based on:
- The number of machine instructions generated by a compiler from a high-level
program
- The number of microinstructions per machine code
- CPI
- Clock.
- List at least two microprocessors implementations that are from each architecture
type.
CISC RISC
The number of Large number of instructions Small number of fixed length
machine instructions instruction
generated by a
compiler from a high-
level program
1. Problem 2.14 Provide the instruction type, assembly language instruction, and
binary representation of instruction described by the following RISC-V fields:
R-Format
Func7 Rs2 Rs1 Funct3 Rd Opcode
0010100 00101 00111 000 00110 0110011
Binary: 001010000101001110000011001100112
Hex: 2853833316
Decimal: 67656171510
2. Problem 2.15 Provide the instruction type, assembly language instruction, and
binary representation of instruction described by the following RISC-V fields :
I-Format
Imm[11:0] Rs1 Funct3 Rd Opcode
000000000100 11011 011 00011 0000011
Binary: 000000000100110110110001100000112
Hex: 4DB18316
Decimal: 509171510
ld x3, 27(x3)
3. Problem 2.16 Assume that we would like to expand the RISC-V register file to
128 registers and expand the instruction set to contain four times as many
instructions.
a) How would this affect the size of each of the bit fields in the R-type
instructions?
Expanding the register file to 128 bits adds 2 bits to rs , rt, rd. It will increase
them to 7 bits each. The instruction expands by 2 bits – 8 bits total. And the
opcode reserves the values that could accommodate this without expansion.
b) How would this affect the size of each of the bit fields in the I-type
instructions?
by reducing the instances in which the register contents “spill” into other
registers/ memory and by allowing more complex operations to be
implemented in one instruction vs requiring multiple instructions. They
could increase the size of a program by requiring adding bits to the opcode
and register fields, there by increasing memory width.
4. Problem 2.18 Find the shortest sequence of RISC-V instructions that extracts bits
16 down to 11 from register x5 and uses the value of this field to replace bits 31
down to 26 in register x6 without changing the other bits of registers x5 or x6.
(Be sure to test your code using x5 = 0 and x6 = 0xffffffffffffffff.
Doing so may reveal a common oversight.)
jalx0, LOOP
DONE:
a) Assume that the register x6 is initialized to the value 10. What is the final
value in register x5 assuming the x5 is initially zero?
X5=20
b) For the loop above, write the equivalent C code. Assume that the registers x5
and x6 are integers acc and i, respectively.
acc=0;
i=10;
while(i!=0)
acc+=2;
i - - j
c) For the loop written in RISC-V assembly above, assume that the register x6
is initialized to the value N. How many RISC-V instructions are executed?
4N + 1 Instructions
d) For the loop written in RISC-V assembly above, replace the instruction “beq
x6, x0, DONE” with the instruction “blt x6, x0, DONE” and write the
equivalent C code.
acc=0;
i=10;
while (i>=0)
acc + = 2
i - - j
6. Problem 2.27 Translate the following loop into C. Assume that the C-level integer
i is held in register x5,x6 holds the C-level integer called result, and x10
holds the base address of the integer
MemArray.
addx5, x5, x7
__start:
li A0,10
j loop
mov A0,V0
li V0,2
syscall
la A0,11
syscall
NOT1:sub A0,A0,1
j loop
mov s0,v0
sub a0,a0,1
j loop
add v0,v0,s0