Docsity

Data Transfer Instructions: Load, Store, Byte Operations and Machine Code, Study notes of Computer Architecture and Organization

Toggle sidebar
bg1
Instructions: Data Transfer
load and store architecture
MIPS: can access memory only to transfer data to or from registers
CISC: may allow, for example, add to memory location, store in register
load
: copy the data from memory into a register.
store
: copy the data from a register to memory.
lw $rt, offset($rs)
Load word from memory location to register
sw $rt, offset($rs)
Store word from register to memory location
Offset is a 16-bit 2C value (immediate); all are I-type
semantics of
lw
Addr <-- R[s] + (IR15
)16
::IR15-0
R[t] <-- M
4
[ Addr ]
compute address
- add the contents of register s (base) to the sign-extended offset
- offset is immediate
- non-aligned address: hardware exception
get data
- copy 4 bytes located at memory address starting at
Addr
to register t.
- CPU fetches the four bytes based on the endianness of the machine
sw
similar to
lw
but the 4 byte quantity is copied from the register to memory.
M
4
[ Addr ] <-- R[t]
stored in the endianness of the machine
pf3
pf4
pf5

Partial preview of the text

Download Data Transfer Instructions: Load, Store, Byte Operations and Machine Code and more Study notes Computer Architecture and Organization in PDF only on Docsity!

Instructions: Data Transfer

load and store architecture MIPS: can access memory only to transfer data to or from registers CISC: may allow, for example, add to memory location, store in register load: copy the data from memory into a register. store: copy the data from a register to memory.

lw $rt, offset($rs) Load word from memory location to register

sw $rt, offset($rs) Store word from register to memory location

Offset is a 16-bit 2C value (immediate); all are I-type semantics of lw

Addr <-- R[s] + (IR 15 ) 16 ::IR (^) 15- R[t] <-- M 4 [ Addr ] compute address

**- add the contents of register s (base) to the sign-extended offset

  • offset is immediate
  • non-aligned address: hardware exception get data
  • copy 4 bytes located at memory address starting at** Addr **to register t.
  • CPU fetches the four bytes based on the endianness of the machine** sw similar to lw but the 4 byte quantity is copied from the register to memory.

M 4 [ Addr ] <-- R[t] stored in the endianness of the machine

Instructions: Data Transfer

Byte operations lb $rt, offset($rs) Load sign-extended byte from memory location to register lbu $rt, offset($rs) Load zero-extended (unsigned) byte from memory location to register sb $rt, offset($rs) Store the least significant byte of a register to memory location What about sbu? For lb , the address is computed the same way as lw , but the address does not have to be word aligned. Addr <-- R[s] + (IR 15 ) 16 ::IR (^) 15- R[t] <-- (M 1 [ Addr ] 7 ) 24 ::M 1 [ Addr ] Since the value is interpreted as 2C, the fetched byte is sign-extended to 32 bits. lbu is just like lb except the byte is zero-extended in the register sb is similar to sw: M 1 [ Addr ] <-- R[t] (^) 7- The least significant byte of register t is copied to the address in memory. Do we really need to have separate instructions to load, store bytes?

Instructions: Data Transfer

Halfword operations (short int) short int is usually 16 bits lh $rt, offset($rs) Load halfword from memory location to register Data is sign-extended in register lhu $rt, offset($rs) Data is zero-extended in register sh $rt, offset($rs) Store halfword from register to memory location

Loading constant lui $rt, immed Semantics: R[t] = IR (^) 15-0 0 16 load the lower halfword of immed into upper halfword of $rt lower bits of $rt are set to 0 $rs is ignored

Data transfer: summary

R-type I-type

Load Word lw

Halfword lh Halfword unsigned lhu Byte lb Byte unsigned lbu Constant lui

Store Word sw

Halfword sh Byte sb

This document was created with Win2PDF available at http://www.daneprairie.com. The unregistered version of Win2PDF is for evaluation or non-commercial use only.