Lecture 8 Data Transfer¶
Data Transfer: Load from and Store to¶
- Data typically smaller than 32 bits, but rarely smaller than 8 bits (e.g., char type) – works fine if everything is a multiple of 8 bits
- 8 bit chunk is called a byte (1 word = 4 bytes)
- Memory addresses are really in bytes, not words
Word-Level Transfer¶
lw / sw
load to rsg
C | |
---|---|
1 2 |
|
In RISC-V:
Text Only | |
---|---|
1 2 |
|
- x15: base register (pointing to a)
- 12: offset in bytes
- Offset must be a constant known at assembly time
store to memory
C | |
---|---|
1 2 |
|
In RISC-V:
Text Only | |
---|---|
1 2 3 |
|
(x15 + 12), (x15 + 40) must be multiples of 4
Byte-Level Transfer¶
lb / lbu / sb
- load byte from:
lb
(signal-extend) /lbu
(0-extend) - store byte to:
sb
lb
is 32-bit instruction, but only 8 bits are usedlb
sign-extends the 8-bit value to 32 bitslbu
is the same aslb
, but zero-extends the 8-bit value to 32 bits
???+ note why have sb, but not sbu
Text Only | |
---|---|
1 2 3 |
|
Summary¶
- Memory: byte-addressable (1 byte = 8 bits)
- Register: word-size (1 word = 4 bytes = 32 bits)
exercise: