C8 Computer organization · Practice
From C to assembly
Problems dealt one at a time, with new numbers every time. The kinds you miss come back more often, and you can keep going as long as you like.
Check
How many instructions does sum run for an array of 75 elements, from its first instruction to its ret?
Check
An array whose elements are 8 bytes each starts at 0x1578. What's the address of element 6?
Check
Translate this C, with x in a0 and y in a1:
y = x;
if (y < 0) {
y = -y;
}RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
Translate this C, with n in a0 and f in a1:
int f = 1;
for (int i = 0; i < n; i++) {
f = f * 2;
}RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
a0 points to struct { int id; int count; }. Add a1 to s->count, store it back, and leave the new count in a2.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
Check
int m[10][8] is stored row by row from address 0.
(a)
At what address is m[3][7]?
(b)
How many bytes apart are m[i][j] and m[i + 1][j]?
Check
Element 9 of an array of 8-byte items at 0x1B14?
Check
A loop's body is 5 instructions; each pass adds a test and a jump back. It runs 8 passes and leaves on one last test. Instructions?
Check
Translate if (a > b) m = a - b; else m = b - a; with a in a0, b in a1, m in a2.
RISC-V RV32IM (base integer plus multiply and divide). End your program with ebreak. Tab indents; press Esc and then Tab to move on.
A kind of problem counts as solid once you've got it right on the first try twice in a row. Back to the lesson · Practice every topic in C8