Data Transfer
Instruction
·
Load: lw
copy data from memory to registers
·
Store: sw copy data from registers to memory
Data transfer
|
load word
|
lw $1,(100)$2
|
$1 = Memory[$2+100]
|
Data from memory to register
|
store word
|
sw $1,(100)$2
|
Memory[$2+100] = $1
|
Data from memory to register
| |
load upper immediate
|
lui $1,100
|
$1 = 100 * 216
|
Load constant in upper 16bits
|
·
To transfer a word of data, need to specify two things:
–Register: specify this by
number (0 - 31)
–Memory address:
1. Think of memory as a 1D array
2. Address it by supplying a
pointer to a memory address
3. Offset (in bytes) from this pointer
4. The desired memory address is
the sum of these two values,
e.g., 8($t0)
5. Specifies the memory address
pointed to by the value in $t0, plus 8 bytes (why “bytes”,
not “words”?)
6. Each address is 32 bits
\
i.) Data Transfer : from
memory to register
·
Load Instruction Syntax:
1 2 3 4
lw
$t0,12($s0)
1) operation name
2) register that will receive value
3) numerical offset in bytes
4) register containing pointer to memory
·
Example: lw $t0,12($s0)
– lw (Load word, so a word (32 bits) is
loaded at a time)
– Take
the pointer in $s0, add 12 bytes to it, and then load the value from the
--memory
pointed to by this calculated sum into register $t0
Notes:
– $s0 is
called the base register, 12 is
called the offset
– Offset is generally used in
accessing elements of array: base register points to the beginning
of the array
iii.) Data Transfer : from
register to memory
·
Example: sw
$t0,12($s0)
–sw (meaning Store word, so 32 bits or one word
are loaded at a time)
–This instruction will take
the pointer in $s0, add 12 bytes to it, and then store the value from register $t0 into the
memory address pointed to by the calculated sum.
By : Lua Xin Lin B031210345
0 comments:
Post a Comment