User:Doruletz72/ONBA/Address Modes

DIRECT
The content of the registers must be treated as values not pointers/addresses.

With data register Dn
Copies the content of the register D1 to register D0. When instruction is executed both registers will contain the same information. When copying a byte or a word, the upper part of the register will remain unchanged.
 *  = Dn
 * Syntax: Dn where n is 0 ... 7
 * Details: The operand is in a data register. The effective address  specifies this register.
 * Comments: It is very common in use. Size of the operand can be byte, word or long word.
 * Example:

With address register An
Copies the whole register A1 to register D0. When instruction is executed both registers will contain the same information. When a word operand is transferred to an address register, the bit 15 of the operand (sign bit) will be copied through the whole upper word of the register (bits 31 .. 16). If wasn't so a negative number will become positive.
 *  = An
 * Syntax: An where n is 0 ... 7
 * Details: The operand is in an address register. The effective address  specifies this register.
 * Comments: It is very common in use. Size of the operand can be word or long word. If you have a byte value extend the value to the word. All values will be treated as signed values.
 * Example:

INDIRECT
The content of the registers must be treated as pointers/addresses not values.

Address register (An)
Copies the long word stored in memory at address specified by register A0 to register D0. When you refer a word or a long word the address of the location must be an even number.
 *  = (An)
 * Syntax: (An) where n is 0 ... 7
 * Details: The operand is in memory. The effective address  refers the address of this location.
 * Comments: Classically C pointer. Size of the operand can be word or long word. If you have a byte value extend the value to the word. All values will be treated as signed values.
 * Example:

Address register with postincrement (An)+
Copies the long word stored in memory at address specified by register A1 to register D0. Then increment value stored in A1 by 4 because of long operand specified in instruction suffix.
 *  = (An); An = An + sizeof(operand)
 * Syntax: (An)+ where n is 0 ... 7
 * Details: The operand is in memory. The effective address  refers the address of this location. After the operand is used, the value stored in  is incremented with size of the operand.
 * Comments: Very used in stacks management among with complementary mode -(An). Also is the quickest way to parse forwardly the elements of an array of chars or a string. If the register is the program stack pointer A7/SP, and the operand size is a byte, the address is incremented by two to keep the stack pointer aligned to a word boundary.
 * Example:

Address register with predecrement -(An)
First, value contained by the register A0 is decremented with the 4, size of the long operand, then copies the long word stored in memory at this address to register D0.
 * An = An - sizeof(operand);  = (An)
 * Syntax: -(An) where n is 0 ... 7
 * Details: The operand is in memory. First, value contained by the address register is decremented with the size of the operand. The effective address  refers the address of new location.
 * Comments: Very used in stacks management among with complementary mode (An)+. Also is the quickest way to parse backwardly the elements of an array of chars or a string. If the register is the program stack pointer A7/SP, and the operand size is a byte, the address is decremented by two to keep the stack pointer aligned to a word boundary.
 * Example:

Address register with displacement (d16, An)
Copies the long word stored in memory at address pointed by register A1 altered (increased in this case) with 4 to register D0.
 *  = (An) + d16
 * Syntax: x(An) where n is 0 ... 7 and x is a word
 * Details: The operand is in memory. The effective address  refers the address stored to register An altered with the value of displacement. The displacement is sign extended to 32 bits prior to be used in effective address calculation.
 * Comments: Very used to address the global variables using A5 register as reference and the local variables using A7 or A6 register as reference.
 * Example:

Address register with index (d8, An, Xi)

 *  = (An) + (Xi) + d8
 * Syntax:
 * x(An,Dn.L) where n is 0 ... 7 and x is a byte
 * x(An,Dn.W)
 * x(An,An.L)
 * x(An,An.W)

Copies the long word stored in memory at address A1 + A2 + 10 to register D0.
 * Details: The operand is in memory. The effective address  refers the address stored to register An altered with the value stored to index register Xi, and finally altered with the value of displacement. The displacement is sign extended to 16 bits prior to be used in effective address calculation.
 * Comments: Very used to address the elements of an array or the members of a structure.
 * Example:

Program counter with displacement (d16, PC)

 *  = (PC) + d16
 * Syntax: x(PC) x is a word
 * Details: The operand is in memory (inside of the CODE SEGMENT). The effective address <ea> refers the address stored to PC altered with the value of displacement. The displacement is sign extended to 32 bits prior to be used in effective address calculation. Range of values for displacement -32k to +32k. This is the reason why the CODE SEGMENTS cannot be larger than 32k. If you forgot the PC points the address of the current instruction to be executed, inside the current CODE SEGMENT.
 * Comments: Used to address the locations of the branch labels or the routine labels inside of the CODE SEGMENT.

Program counter with index (d8, PC, Xi)

 * <ea> = (PC) + (Xi) + d8
 * Syntax:
 * x(PC,Dn.L) where n is 0 ... 7 and x is a byte
 * x(PC,Dn.W)
 * x(PC,An.L)
 * x(PC,An.W)


 * Details: Is similar with (d8, An, Xi).
 * Comments: Used to address the locations of the branch labels or the routine labels inside of the CODE SEGMENT.

ABSOLUTE
The given parameters must be treated as pointers/addresses not values.

Short/Near Abs.W
Copies the long word stored in memory at address $1000 to register D0.
 * <ea> = given value
 * Syntax: x where x is 16-bits constant
 * Details: The operand is in memory. The effective address <ea> of this location is the given value.
 * Comments: The 16-bits address is sign-extended to 32-bits, means the near addressing can only be used on the first 32Kb. Take care when you use this type of addressing because you can read/write directly the value of any address into the real memory, not only of your application.
 * Example:

Long/Far Abs.L
Copies the long word stored in memory at address $10000 to register D0.
 * <ea> = given value
 * Syntax: x where x is 32-bits constant
 * Details: The operand is in memory. The effective address <ea> of this location is the given value.
 * Comments: Take care when you use this type of addressing because you can read/write directly the value of any address into the real memory, not only of your application.
 * Example:

IMMEDIATE #data
Copies the value $10002000 to register D0.
 * <ea> = none
 * Syntax: #x where x is 8, 16 or 32-bits constant
 * Details:
 * Comments: Commonly used for initialization. If you copy a word to an address register the word will be sign-extended.
 * Example:

IMPLIED SR/CCR
Set both carry flag (C) and zero flag (Z). The others flags will remain unchanged.
 * <ea> = none
 * Syntax: SR or CCR
 * Details: Used to read/write the status or condition code register.
 * Comments: The only allowed instruction to access SR/CCR are: MOVE to CCR, MOVE from CCR, ANDI to CCR, ORI to CCR, EORI to CCR, MOVE from SR, MOVE to SR, ANDI to SR, ORI to SR, EORI to SR. If the length is a byte the CCR will be changed. If it is a word, whole SR will be changed, but to do this S-bit (bit 13 from SR) must be set first.
 * Example: