C8 Computer organization · Practice
Structs, unions and data layout
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.
0 solved
0 in a row
0 of 10 kinds solid
Check
A struct starts with 3 chars, then a short, then an int.
(a)
At what offset does the short start?
(b)
What's its size?
Check
An array of 12-byte structs starts at 0x2000 (8192). A field sits at offset 6.
(a)
At what address is element 3's field?
(b)
How far does p++ move a pointer to these structs?
Check
recs holds four struct { int id; int value; }. Put the sum of the value fields in a0.
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
A union holds char c[5], an int i and a short s.
(a)
What's its size?
(b)
i is set to 11223344. What does c[0] read on a little-endian machine?
Check
A big-endian 16-bit field arrives as the bytes 5 then 44.
(a)
What value did the sender mean?
(b)
What does lhu read from it on RV32?
Check
A loop reads one 4-byte field from each of 1000 records of 16 bytes, with 64-byte cache lines.
(a)
How many lines does it touch as an array of structs?
(b)
And with the field in its own array?
Check
A status word in a0 holds a 6-bit field in bits 11:6. Put the field's value in a1.
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
The next free offset is 5. Where does a field with alignment 2 go?
Check
20-byte structs start at 4096. Where does element 2 start?
Check
A big-endian halfword arrives as bytes 10, 3. What does a little-endian lhu read?
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