Beruflich Dokumente
Kultur Dokumente
Addressing Modes I
2
Data Formats: Memory
Data is stored using big-endian scheme
Operands are assumed to be aligned based on their size:
—16-bit operands aligned on 0-modulo-2 addresses
—32-bit operands aligned on 0-modulo-4 addresses
Operands can be misaligned; however, this leads to performance degradation 3
Byte Transfers
31 15 7 0
Byte 1
move.b 0x1230,%d0
4
Word Transfers
31 15 7 0
Byte 1 Byte 2
move.w 0x1230,%d0
Longword Transfers
31 15 7 0
Byte 1 Byte 2 Byte 3 Byte 4
move.l 0x1230,d0
6
Instruction Format
An Instruction consists of
– operation code (which function to perform)
– location of every operand for the function
– extension word(s) with values of the operand(s)
Effective Address
Operand location can be specified using
1. The register field within the instruction
2. The instruction’s effective address field
3. The instruction’s definition (implied specific register);
other fields within instruction specify whether the register
is an address or data register and how it should be used.
D1 0x12345678
D2 0xFEDCBA98 0x000200 0x78 0x9A
A2 0x010000
A3 0x011000
0x00FFFE 0x11 0x22
and the contents of memory are: 0x010000 0x33 0x44
0x010002 0x55 0x66
10
Data Register Direct
Generation EA = Dn
Assembler Syntax Dn
EA Mode Field 000
EA Register Field Register number
Number of Extension Words 0
11
Before D1 0x12345678
D2 0xFEDCBA98
12
Address Register Direct
Generation EA = An
Assembler Syntax An
EA Mode Field 001
EA Register Field Register number
Number of Extension Words 0
13
Before D1 0x12345678
A3 0x00011000
17
Generation EA = (An)
Assembler Syntax (An)
EA Mode Field 010
EA Register Field Register number
Number of Extension Words 0
18
Address Register Indirect
A2 0x00010000
19
Before D1 0x12345678
D2 0xFEDCBA98 0x010000 0x33 0x44
A2 0x00010000 0x010002 0x55 0x66
A3 0x00011000
20
Absolute Addressing: Short
Generation EA given
Assembler Syntax xxx.W
EA Mode Field 111
EA Register Field 000
Number of Extension Words 1
21
Generation EA given
Assembler Syntax xxx.L
EA Mode Field 111
EA Register Field 001
Number of Extension Words 2
22
Absolute Addressing
The instruction uses the actual absolute address for
accessing data in memory
Absolute short: After 0x1000 0x12 0x34
move.l %d1, 0x1000 0x1002 0x56 0x78
Absolute long:
move.b %d1, 0x00010000 After 0x10000 0x78 0x44
0x10002 0x55 0x66
Before D1 0x12345678
23
0x00000000
Size of assembled instructions
0x00007FFF
move.b 0x7fff, %d0 ;2 words
0x00008000
move.b 0x00007fff,%d0 ;3 words
25
Immediate Data
26
10 words = 20 bytes 0x11000 0x12000
2010 = 1416 = 0x14
0x11012 0x12012
28
Example 1: pseudo-code
addr1 = 0x11000
addr2 = 0x12000
for(i = 0; i < 10; i++)
{
Read a word from addr1
Write the word to addr2
increment addr1
increment addr2
}
29
Loop:
CODE BLOCK2 * Loop internals
30
Example 1: fill in remaining code (1/2)
Start: movea.l #0x11000,%a0 * a0 points at start of block 1
movea.l #0x12000,%a1 * a1 points at start of block 2
Loop:
CODE BLOCK2 * Loop internals
31
32
Variable Length Operands Memory
23 0 PL N
P PU PM PL PM N+1
Example 2: Add two words
PU N+2
P and Q of 24 bits (3 bytes) Q QU QM QL QL N+3
and to store the result in R QM N+4
R RU RM RL
QL N+5
RL N+6
Note: For simplicity, we are using 3x8=24 bit
RM N+7
operands to illustrate the principle of multiple RU N+8
precision arithmetic. In reality, it might be 64 or
8-bits wide
128 bits.
ADDX %Dn,%Dm [ Dm ] ← [ Dm ] + [ Dn ] + X
SUBX %Dn,%Dm [ Dm ] ← [ Dm ] - [ Dn ] – X
NEGX %Dn [ Dn ] ← 0 - [ Dn ] – X
34
35
Note: For simple illustration only – MFC5270 does NOT have byte sized arithmetic operators.
36
AR Indirect with Displacement
• The effective address of the operand is given by the contents
of an address register plus a displacement/ offset
• Syntax (d16,%An)
• The 16-bit offset d16∈ [-32768,+32767] is sign extended and
added to the address register
• Often used to access items in a table
A1 Memory
e.g. If [a1] = 0x1000 0x00001000 0x1000
move.w (0x10,%a1),%d0 0x1002
0x1004
[d0] ← [M(0x10+[a1])] Offset = 0x10 0x1006
0x1008
[d0] ← [M(0x1010)]
0x1010
37 16-bits wide
40
AR Indirect with postincrement
move.b (%a2)+,%d2 After D2 0xFEDCBA33
A2 0x00010001
move.w (%a2)+,%d2 After D2 0xFEDC3344
A2 0x00010002
move.l (%a2)+,%d2 After D2 0x33445566
A2 0x00010004
42
AR Indirect with predecrement
move.b -(%a2),%d2 After D2 0xFEDCBA44
A2 0x0000FFFF
move.w -(%a2),%d2 After D2 0xFEDC3344
A2 0x0000FFFE
move.l -(%a2),%d2 After D2 0x11223344
A2 0x0000FFFC
0x11012 0x12012
45
Memory Memory
ARRAY1 ARRAY2
ARRAY1+8 ARRAY2+8
+16 +16