C834 of 55
0 XP
  1. Hook
  2. Problems

C8 · Midterm exam

Midterm exam: instructions, programs and the machine around them

Twelve problems from the first half of the course: the instruction cycle, RISC-V instructions and their encoding, memory and data layout, branches, functions and the stack, C and pointers, integer and fixed-point arithmetic, interrupts and I/O, linking and performance. Two of them ask you to write assembly. Give yourself two hours, work without the lessons open, and write out your reasoning before checking each answer. "Another set" deals a different exam.

Check

A program runs 4 million instructions at an average CPI of 1.25 on a 120 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)

What is its MIPS rate?

Check

Consider addi x9, x0, 12 (opcode 0x13).

(a)

What is its encoding?

(b)

What is the word with only its immediate field filled in, everything else 0?

Check

The word DEADBEEF is stored at 0x2000 on this little-endian machine.

(a)

What byte is at 0x2000?

(b)

What does lb from 0x2003 load, as a signed number?

Check

A loop's branch at 1130 jumps back 4 instructions; elsewhere, jal ra, f at 1130 + 8 calls f at 1B58.

(a)

What offset does the branch hold?

(b)

What does the jal put in ra?

Check

struct sample { int t; short v; short flags; } is 8 bytes: t at offset 0, v at 4, flags at 6. An array of them starts at 1000.

(a)

At what address is s[3].v?

(b)

How far is s[3] from s[0]?

Check

A recursive function saves ra and 4 s registers in a frame rounded up to 16 bytes, and recurses 10 levels deep. sp starts at 0x10000.

(a)

How big is each frame?

(b)

What is sp at the deepest point?

Check

A control register holds 5B.

(a)

What does it hold after r ^= (1 << 0)?

(b)

What would r &= ~(1 << 0) give instead?

Check

0.55 and 0.25 are stored in Q15 and multiplied.

(a)

What integer stores 0.55?

(b)

The integer product is shifted right arithmetically by 15. What results?

Check

Signed integer division on RISC-V.

(a)

What does div give for −25 ÷ 2?

(b)

What does rem give for −25 and 2?

Check

Samples arrive at 48000 per second on a 96 MHz processor whose interrupts cost 50 cycles.

(a)

What load would an interrupt per sample put on it? (Over 100% means impossible.)

(b)

With DMA in double-buffered blocks of 512, how long does the processor have per block?

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

Check

Firmware has 22 kB of code, 3 kB of constants, 5 kB of initialized globals, 20 kB of zeroed globals and a 2 kB stack.

(a)

How much flash?

(b)

How much RAM?

Check

A fraction 0.8 of a program's time is in a routine made 4 times faster.

(a)

What is the overall speedup?

(b)

What is the most any speedup of that routine could give?

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.