C88 of 55
0 XP
  1. Hook
  2. Problems

C8 · Problem set 1

Problem set 1: the instruction cycle, instructions and memory

These problems use lessons 1 to 7: the fetch, decode and execute cycle and the time a program takes, RISC-V instructions, carries and overflow, how instructions are encoded in 32 bits, CISC and RISC, and how memory is addressed and laid out. Addresses are bytes, words are 4 bytes, and the board's memory map is the one from lesson 6.

Check

A program runs 5 million instructions at an average of 1.4 cycles each on a 400 MHz clock.

(a)

How long does it take?

Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.

(b)

How many million instructions does it run per second?

Check

A program's first instruction is at 2000, and it runs straight through with no branches.

(a)

At what address is instruction number 3 (counting the first as 0)?

(b)

How many bytes do instructions 0 to 3 take?

Check

Consider addi x6, x0, 1.

(a)

What is its 32-bit encoding?

(b)

What does x6 hold after it runs?

Check

Encode the R-type instructions below (opcode 0x33, funct3 = 0).

(a)

add x7, x1, x30

(b)

sub x7, x1, x30

Check

An instruction word reads 00203693.

(a)

What register number is in its rs1 field (bits 19:15)?

(b)

What is its funct3 (bits 14:12)?

Check

A program builds a constant with lui t0, 74565 then addi t0, t0, 291.

(a)

What value does t0 hold?

(b)

What did t0 hold after the lui alone?

Check

An array of 4-byte elements starts at 1000.

(a)

What is the address of element 2?

(b)

How far apart are neighboring elements?

Check

The word AABBCCDD is stored at 0x1000 on this little-endian machine.

(a)

What byte is at 0x1000?

(b)

What does lbu from 0x1001 give?

Check

The byte AD is in memory.

(a)

What does lb load?

(b)

What does lbu load?

Check

A region of memory is addressed by the low 16 bits of the address.

(a)

How many bytes does it cover?

(b)

How many 32-bit words is that?

Check

A load uses the address 1004.

(a)

How many bytes past the start of its word is it? (0 means it's aligned for lw.)

(b)

At what address does the word containing it start?

Check

The stack pointer starts at 10000 and a function makes a frame of 4 words.

(a)

What does sp hold inside the function?

(b)

How many bytes is the frame?

Have paper and a calculator ready. Work each problem out by hand, then enter the answer. Your first try on each one counts toward your score.

Practice

Keep practicing

16 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.