Propriété littéraire et scientifique réservée pour Literary and scientific copyrights reserved in all tous les pays du monde. Ce document ne peut countries of the world. This report, or any part of être reproduit ou traduit en tout ou en partie sans it, may not be reprinted or translated without l'autorisation écrite du Directeur général du written permission of the copyright holder, the CERN, titulaire du droit d'auteur. Dans les cas Director-General of CERN. However, permission appropriés, et s'il s'agit d'utiliser le document à will be freely granted for appropriate non des fins non commerciales, cette autorisation commercial use. sera volontiers accordée. If any patentable invention or registrable design Le CERN ne revendique pas la propriété des is described in the report, CERN makes no claim inventions brevetables et dessins ou modèles to property rights in it but offers it for the free use susceptibles de dépôt qui pourraient être décrits of research institutions, manufacturers and dans le présent document; ceux-ci peuvent être others. CERN, however, may oppose any attempt librement utilisés par les instituts de recherche, by a user to claim any proprietary or patent rights les industriels et autres intéressés. Cependant, le in such inventions or designs as may be des CERN se réserve le droit de s'opposer à toute cribed in the present document. revendication qu'un usager pourrait faire de la propriété scientifique ou industrielle de toute invention et tout dessin ou modèle décrits dans le présent document.
This document is a user's guide for programming the Moto rola 68000 microprocessor in assembly language. It describes the programming model» addressing modes and instruction set of the M 68000 as well as the use of the M68mi1 cross macro assembler. Version 3.6 of the assembler has been installed at CERN on CDC, DEC VAX, IBM, Norsk Data and Siemens compu ters. The source code of the assembler is available from CERN on request.
- Ill -
* SOFTWARE SUPPORT FOR MOTOROLA 68000 CERN M68MIL CROSS MACRO ASSEMBLER TABLE OF CONTENTS
CONTENTS
Introduction 1 M 68000 Programming Model 2 Privilege States 2 Memory Addressing Scheme 3 Register Set 4 Addressing Modes 5 Implied Addressing 6 Register Direct Addressing 7 Immediate Addressing 9 Direct Addressing 10 Address Register Indirect Addressing 11 Address Register Indirect 11 Address Register Indirect with Postincrement 12 Address Register Indirect with Predecrement 13 Address Register Indirect with Displacement 15 Address Register Indirect with Index and Displacement 15 Program Counter Relative Addressing 16 Program Counter Relative with Displacement 17 Program Counter Relative with Index and Displacement 18 Machine Instructions 20 ABCD - Add Decimal With Extend 20 ADD - Add binary 20 ADDA - Add Address 21 ADDI - Add Immediate 21 ADDQ - Add Quick 21 ADDX - Add Extended 22 AND - AND Logical 22 ANDI - AND Immediate 23 ASL - Arithmetic Shift Left 23 ASR - Arithmetic Shift Right 23 Bcc - Branch Conditionally 24 BCHG - Test a bit and change 25 BCLR - Test a bit and clear . .-• 25 BRA - Branch always 26 BSET - Test a Bit and Set 26 BSR - Branch to subroutine 26 BTST - Test a Bit 27 CHK - Check Register against Bounds 27 CLR - Clear an Operand 28 CMP - Compare 28 CMPA - Compare address 29 CMPI - Compare Immediate 29 CMPM - Compare Memory 29 DBcc - Test Condition» Decrement and Branch 30 DIVS - Signed divide 30 DIVU - Unsigned Divide 31 EOR - Exclusive OR Logical 31
- V - SOFTWARE SUPPORT FOR MOTOROLA 68000 CERN M68MIL CROSS MACRO ASSEMBLER TABLE OF CONTENTS
EORI - Exclusive OR Immediate 32 EXG - Exchange Régi sters 32 EXT - Sign Extend 33 JMP - Jump 33 JSR - Jump to Subroutine 33 LEA - Load Effective Address 34 LINK - Link and Allocate 34 LSL - Logical Shift Left 35 LSR - Logical Shift Right 35 MOVE - Move Data from Source to Destination 35 MOVE - Special MOVES 36 MOVEA - Move Address 36 MOVEM - Move Multiple Registers 37 MOVEP - Move peripheral data 38 MOVEQ - Move Quick 38 MULS - Signed Multiply 38 MULU - Unsigned Multiply 39 NBCD - Negate Decimal With Extend 39 NEG - Negate 40 NEGX - Negate with Extend 40 NOP - No Operation 40 NOT - Logical Complement 41 OR - Inclusive OR Logical 41 ORI - Inclusive Or Immediate 42 PEA - Push Effective Address 42 RESET - Reset External Devices 43 ROL - Rotate Left (without Extend) 43 R0R - Rotate Right (without Extend) 43 ROXL - Rotate Left with Extend 44 ROXL - Rotate Right with Extend 44 RTE - Return from Exception 44 RTR - Return and Restore Condition Codes 45 RTS - Return from Subroutine 45 SBCD - Subtract Decimal with Extend 45 Sec - Set According to Condition 45 STOP - Load Status Register and Stop 46 SUB - Subtract binary 47 SUBA - Subtract Address 47 SUBI - Subtract Immediate 48 SUBQ - Subtract Quick 48 SUBX - Subtract with Extend 48 SWAP - Swap Register Halves 49 TAS - Test and Set an Operand 49 TRAP - Trap 50 TRAPV - Trap on Overflow 50 TST - Test an Operand 50 UNLK - Unlink 51 Assembler Notations 52 Source Statement Format 52
- VI - SOFTWARE SUPPORT FOR MOTOROLA 68000 CERN M68MIL CROSS MACRO ASSEMBLER TABLE OF CONTENTS
First Column 52 Location Field 52 Operation Field 52 Operand Field 53 Comment Field 53 Comment Statement 53 Statement Continuation 53 Micro Substitution 54 Symbols 54 Identifiers 54 Numbers 54 Character Strings 55 Assembler Symbols 55 Absolute Symbol 55 Relative Symbol 55 External Symbol 56 Undefined Symbol 56 Operators 56 Arithmetic Operators 56 Shift Operators 56 Logical Operators 56 Operator Precedence 57 Expressions 57 Assembler Directives 58 Module Identification 59 IDENT - Module Identification 59 END - End of Module 59 Section Control 59 Absolute Section 59 Relative Section 60 6 (general) Section 60 R (relocatable) Section 61 C (common) Section 62 U (unique) Section 62 "Previous" Section 62 Symbol Definition 63 EQU - Equate Symbol Value 63 SET - Set or Reset Symbol Value 63 Module Linkage 63 ENTRY - Declare Entry Symbols 63 EXTERN - Declare External Symbols 64 Data Generation and Storage Reservation 64 ALIGN - Align on Word Boundary 64 DC - Define Constant 65 DS - Define Storage 66 Conditional Assembly 66 ENDIF - End of IF Range 66 ELSE - Reverse Effects of IF 67 IF - Test Attribute of Symbol 67
- VII - SOFTWARE SUPPORT FOR MOTOROLA 68000 CERN M68MIL CROSS MACRO ASSEMBLER TABLE OF CONTENTS
IFC | IFNC - Compare two Character Strings 68 IFcc - Test Expression against Zero 68 Macro Operations 69 Macro Definition 69 ENDM - End Macro Definition 70 LOCAL - Local Symbols 70 MACRO - Macro Heading 70 MEXIT - End Macro Expansion 71 NARG - Number of Macro Arguments 71 Macro Calls 71 Source Stream Control 72 DISTINCT - Define Handling of Letters in Identifiers 72 DUP | ENDDUP - Duplicate Code Sequence 72 INSERT - Insert Secondary Source 72 SYSTEXT - Insert system text information 73 Listing Control 73 FAIL - Generate an Error Message 73 G - List Assembled Code 74 LLEN - Set Line Length and Format Listing 74 LIST - Select List Options 74 NOL | N0LIST - Cancel Listing 75 NOPAGE - Turn off Paging 76 PAGE - Top of Page 76 PLEN - Define Page Length 76 SPC - Space Between Source Lines 76 TTL - Assembly Listing Title 76 STTL - Assembly Listing Subtitle 76 Object Code Control 77 BL0NG - Use Two-Word Branch 77 BSHORT - Use One-Word Branch 77 FLONG - Force Direct Long Address 77 FSH0RT - Force Direct Short Address 77 N00BJ - Suppress CUFOM Output 78 Date and Time Stamp 78 STAMP - Date and Time Stamp 78 Assembler Maintenance 78 DEBUG - Print Assembler Debug Information 79 Symbolic Debugging 80 SYMDEBUG - Produce Symbol Table Information 80 Programming Convention Support 81 Standard Stack Initialisation 81 Definition of Global Variables 84 Start Main Program and Initialise Stack 85 Standard Subprogram Call 86 Standard Subprogram Entry 89 Formal Parameter Definition 89 Definition of Local Variables 90 Enter a Subprogram 90 Return from Subprogram 91
- VIII - SOFTWARE SUPPORT FOR MOTOROLA 68000 CERN M68MIL CROSS MACRO ASSEMBLER TABLE OF CONTENTS
Example of a Standard Subprogram 91 Switches Controlling the S_macros 94 Implementations 95 Acknowledgements 96 References 97
- IX - SOFTWARE SUPPORT FOR MOTOROLA 68000 CERN M68MIL CROSS MACRO ASSEMBLER INTRODUCTION
1 INTRODUCTION
M68MIL, the Cross Macro Assembler described in this user's guide can be used to translate assembler source programs for the Motorola 68000 microprocessor into CUF0M C4H5], the CERN Universal Format for relocatable Object Modules. A link editor subsequently allows the combination and linking of several such modules into a new CUF0M module. It also permits the construction of CUFOM libraries, which can be placed as input to the link editor to resolve unsatis fied external references once all other input to the link editor has been pro cessed. A pusher finally translates a CUFOM module to the Motorola 'S' format needed for down-line loading from the host computer into the memory of the tai— get machine.
The assembler is upward compatible with the M68000 Cross Macro Assembler [2] provided by Motorola. Additional assembler directives are provided to allow the generation of relocatable object modules. Although this user's guide gives some information about the principles of operation for the M 68000 microprocessor, the user is advised to consult the Motorola publication
to obtain detailed information on the use of the M 68000.
The assembler has been designed as a two pass assembler and is written in PASCAL. Several independent source modules may form the input source stream for the assembler. In pass one the assembler will read a source module, develop the symbol table for this module, expand all macros, perform source code duplication and write the information on a scratch file for processing by pass two. In pass two the assembler reads the scratch file, uses the symbol table to translate the source code into CUFOM based M 68000 code, produces a listing and, if requested, a cross reference table. It will then check if further source modules are con tained in the input source stream and repeat pass one and two until all modules are processed.
The assembler has been installed at CERN on CDC, DEC VAX, IBM, Norsk Data and Siemens computer systems. The source code of the assembler contains additional information to direct a pre-processor to extract the version for a particular computer system. Outside CERN the assembler has been installed on a PRIME compu ter and on a M 68000 operating under the control of a UNIX1 operating system.
This user's guide describes version 3.6 of M68MIL.
UNIX is a Trademark of Bell Laboratories
- 1 - SOFTWARE SUPPORT FOR MOTOROLA 68000 CERN M68MIL CROSS MACRO ASSEMBLER M 68000 PROGRAMMING MODEL
2 M 68000 PROGRAMMING MODEL
For the convenience of the user of this guide the programming model of the M 68000 will be described here before we enter the description of the M68MIL cross assembler. It should however be understood, that the description given by Motorola Inc. in its publication
is the primary source of this information and should always be consulted, when ever doubts about the functioning of the M 68000 or any of its machine instruc- ti ons ari se.
Throughout the description of the M 68000 programming model the following abbreviations will be used:
ea = effective address d8 8 bit displacement An ~ address register dl6 16 bit displacement Dn = data register abs.u absolute short direct address Rn = any An or Dn abs.l = absolute long direct address SR = status register { } = contents of PC = program counter => = replaces SP = stack pointer $nnn = hexadecimal number C, N, V, X and Z: condition codes
2.1 PRIVILEGE STATES
The M 68000 microprocessor allows two modes of operation
• supervisor or system mode
• user or normal mode
In supervisor mode all instructions can be executed, including those changing the mode of operation, while in user mode a few "privileged" instructions such as "RESET", "STOP" and access to the "system" byte of the status register are inhibited. The M 68000 is automatically put into supervisor mode whenever it is started using the external reset line and when an exception (interrupt, error condition) occurs.
- 2 - SOFTWARE SUPPORT FOR MOTOROLA 68000 CERN M68MIL CROSS MACRO ASSEMBLER M 68000 PROGRAMMING MODEL
2.2 MEMORY ADDRESSINGxSCHEME
The smallest directly addressable unit of memory is a byte <8-bits). Since memory addresses are specified using 24-bits, byte addresses are numbered from 000000 to FFFFFF in hexadecimal notation. This allows a directly addressable memory array of up to 16,777»216 bytes.
b_x
byte
7 0
The next larger directly addressable unit of memory is a word (16-bits). A word consists of two consecutive bytes and must be aligned on even byte addressing boundaries.
b 0 b 1
word
15 8 7 0
The largest directly addressable unit of memory is a long word (32-bits). A long word consists of two consecutive words (or four consecutive bytes) and must be aligned on even byte addressing boundaries.
b 0 b 1 b_2 b_3
long word
31 16 15 0
Note:
• The byte with the even address occupies the upper part of the word (bits 15 through 8) while the byte with the odd address occupies the lower part of the word (bits 7 through 0). (i.e. the byte in the upper part is the one with the lower memory address)
• The word with the lower even address occupies the upper part of the long word (bits 31 through 16) while the word with the higher even address occu pies the lower part of the long word (bits 15 through 0).
• The memory unit used by the M 68000 for instruction processing is the word, hence instructions must always start at even addresses.
• If memory is accessed for word or long word operations with an odd address an address error exception (see section on exceptions) will occur.
- 3 - SOFTWARE SUPPORT FOR MOTOROLA 68000 CERN M68MIL CROSS MACRO ASSEMBLER M 68000 PROGRAMMING MODEL
2.3 REGISTER SET
The register set offered by the M 68000 comprises
• eight 32-bit general purpose data registers» which may hold byte (8-bit), word (16-bit) and long word (32-bit) operands. They can be used as accumu lators, index registers and counters. Their names are: DO, Dl, ... , D7.
31 15 7 0
data regi ster
L byte operand I word operand I long word operand
• seven 32-bit general purpose address registers, which are typically used to hold memory addresses allowing various types of memory access (see section on addressing modes). The contents of an address register may be changed using word (16-bit) or long word (32-bit) operations. Changing of the con tents on a byte (8-bit) boundary is not possible. Their names are: AO, Al, ... , A6.
31 16 15 0
address register
word operand long word operand
• two 32-bit stack pointers, one of which (called the system stack pointer: SSP) is active in supervisor mode, the other (called the user stack poin ter: USP) is active in user mode . Since they have the same characteris tics as the other address registers and since only one of them can be active at any given time, they are named A7.
• one 32-bit program counter, named PC.
• a 16-bit status register, named SR. The top byte of the status register is called the system byte, changeable only in supervisor mode, while the lower byte is called the user byte (or the condition code register: CCR).
- 4 - SOFTWARE SUPPORT FOR MOTOROLA 68000 CERN M68MIL CROSS MACRO ASSEMBLER M 68000 PROGRAMMING MODEL
15 8 7
T - S -- i i i --- X N Z V c status register
L carry bit overflow bit zero bit condition codes negative bit extend bit interrupt mask supervisor mode system byte trace mode }
Data registers and address registers may be used as source or destination operands. The following rules apply:
• Uhen a data register is used as a source operand» only the appropriate low order portion is used (byte» word or long word).
• Uhen a data register is used as a destination operand (register direct addressing mode), only the appropriate low order portion of the register is changed (byte» word or long word); the remaining high order portion» if any» remains unchanged. The condition code register is affected and reflects the change in the appropriate portion of the data register.
• Uhen an address register is used as a source operand either the entire long word (32-bits) or the low order word (16-bits) are used» depending on the size of the operation.
• Uhen an address register is used as a destination operand (register direct addressing mode)» then the entire register is affected» i.e. during a word access bit 15 is replicated into bits 16 through 31 (sign extension). The condition code register remains unaffected.
2.4 ADDRESSING MODES
The M 68000 allows up to 14 different addressing modes» which can be divided into the following six groups:
• implied (or inherent) addressing
• register direct addressing
• immediate addressing
• direct (or absolute data) addressing
- 5 - SOFTWARE SUPPORT FOR MOTOROLA 68000 CERN M68MIL CROSS MACRO ASSEMBLER M 68000 PROGRAMMING MODEL
• address register indirect addressing
• program counter relative addressing
Throughout the description of the programming model we will use the term 'effec tive address' to describe the actual physical address to be used by the micro processor in order to fetch or store an operand. This effective address, abbre viated , is always the result of one of the addressing modes mentioned above. Since not all addressing modes are allowed for a given machine instruc tion» we use the term in the description of the machine instruction and add a table depicting those addressing modes allowed as source operand and those as destination operand.
In the subsequent description of the addressing modes we will use the MOVE instruction for illustration since it allows almost all address modes.
The MOVE instruction always has two operands» one operand specifies the address of the data to be moved (also called: source operand)» the other speci fies the address to which to move the data (also called: destination operand). Since the M 68000 allows three different sizes of data to be handled, namely bytes» words and long words» a size option may be added to those machine instructions, that allow different data sizes. This is done by adding the suf fix •B for operations on bytes .W for operations on words •L for operations on long words to the machine instruction. If no size code is added» the assembler assumes operations on words as the default operation size. The general form of the MOVE instruction is therefore:
MOVE.n
Implied addressing, sometimes also called inherent addressing» means the machine instruction itself already implies certain registers of the microproces sor» hence they are not specified as operands in the instruction itself. Typical examples for the M 68000 are the following instructions:
JMP
=> PC
BSR
{PC} => stack» => PC
just to mention a few.
- 6 - SOFTWARE SUPPORT FOR MOTOROLA 68000 CERN M68MIL CROSS MACRO ASSEMBLER M 68000 PROGRAMMING MODEL
Register Direct Addressing
Register direct addressing, if it is used to describe the source operand, implies that the data for the operation is contained either in a data register or in an address register. When used to specify the destination operand, it means that the result of the machine instruction is to be stored into a data or address register. The general form of a HOVE instruction using register direct addressing modes for both operands would be
MOVE Rn,Rn
To illustrate some of the properties let us assume the following register con- tents:
31 15 7 0
FF FF FF FF in register DO
31 15 7 0
12 34 56 78 in register Dl
31 16 15
00 01 EF 02 in register A0
If we now execute the following machine instruction:
MOVE.L D1,D0
Me Mill find
31 15 7 0
12 34 56 78 in register DO.
If we however had executed
MOVE D1,D0 we would find
- 7 - SOFTWARE SUPPORT FOR MOTOROLA 68000 CERN M68MIL CROSS MACRO ASSEMBLER M 68000 PROGRAMMING MODEL
after execution. Note:
• The number of locations allocated after the instruction word to hold the data depends on the size option used with the machine instruction and not on the actual size of the data.
• Since instructions must start on a word boundary immediate operands of size byte are stored in the lower byte of a word, the upper byte of which is zero.
Direct Addressing
In direct addressing the address to be used to access or store data is itself specified as an operand. It is stored as an extension to the instruction word using the direct addressing mode for one or both of its operands. The M 68000 allows two forms of direct addressing modes depending on the size of the address used
• in the long direct addressing mode a long word (32-bits) is used to hold the address, thus data in the entire address range from $000000 to $FFFFFF may be accessed
• in the short direct addressing mode a word (16-bits) is used to hold the address. The same rule as already outlined for the address registers applies also for the short direct addressing mode; the 16-bit address is expanded to a full 32-bit address (of which for the current M 68000 chip only the low order 24-bi ts will be used). This means that with the short direct addressing mods data in the address ranges $000000 to $007FFF and $FF8000 to $FFFFFF may be accessed, or, to put it differently, data in the address range $008000 to $FF7FFF cannot bo accessed using the short direct addressing mode.
The general form of a MOVE instruction using direct addressing modes for both operands would be
MOVE
,
When during instruction assembly M68MIL encounters as operand a label symbol (see chapter: Assembler notations) in direct addressing mode it does not always know the size of the final address to be used. It for instance has to take a decision as to which form to assume whenever it encounters a forward referenced symbol, i.e. a symbol which has not yet been defined, or a relative symbol, i.e. a symbol the value of which may be changed by the link-editor. By default it will use the long direct addressing mode to ensure correct handling of the sym bol. The assembler directives SECTION, FSHORT and FLOHG will allow the program mer to override the assembler defaults (see chapter: Assembler Directives).
- 10 - SOFTWARE SUPPORT FOR MOTOROLA 68000 CERN H68MIL CROSS MACRO ASSEMBLER M 68000 PROGRAMMING MODEL
To show an example, let us suppose that we want to move the data word stored at address $6000 to address $8002. The instruction would be
MOVE.W $6000,$8002
which Mould be assembled to
b_0 b_l
13 F8 instruction word
15 8 7 0
b 0 b_l
60 00 extension holding source address
15 8 7 0
bO bl b 2 b 3
00 00 80 02 extension holding destination address
31 16 15
Notes
• The size of the instruction extension depends only on the size of the address specified and not on the size of the operation to be performed.
Address Register Indirect Addressing
There are actually five different address register indirect addressing modes. All of them use the contents of an address register as the base to calculate the effective address. The effective address is then used by the microprocessor to fetch or store an operand, or, in the case of a jump or jump subroutine instruc tion, as a new address value for the program counter.
Address Register Indirect:
The general form of a MOVE instruction using address register indirect addressing modes for both operands would be
MOVE (An),(An)
This is the simplest form where the address register holds the effective address itself, in other words: the address register "points" to the address in memory that holds the data or the next instruction to be executed.
- 11 - SOFTWARE SUPPORT FOR MOTOROLA 68000 CERN M68MIL CROSS MACRO ASSEMBLER M 68000 PROGRAMMING MODEL
Assume register A4 contains
31 16 15 0
00 D3 OE 02 register A4
and memory at address $00D30E02 contains the word
b_0 b_l
IF 01 data word in memory
15 8 7 0
then the instruction
MOVE.W (A4),DO
would move $1F01 into register DO.
Address Register Indirect with Postincrement:
The general form of a MOVE instruction using address register indirect with postincrement addressing modes for both operands would be
MOVE (An)+,(An)+
In this form the address register again points to the address in memory, but is automatically incremented by one, two or four depending on the size of the data operation (byte, word or long word) after the address contained in the register has been used by the microprocessor.
Assume we want to move a block of three long words beginning at address $1000 to another block beginning at address $2000, then we could write
MOVEA #$1000,A0 start address of source block
M0VEA #$2000,Al start address of destin, block
M0VE.L (A0)+,(A1)+ move and increment addresses
MOVE.L (A0)+,(A1)+
MOVE.L (A0)+,(A1)+
The first two instructions using immediate addressing for the source operand and register direct addressing for the destination operand would load the block addresses into registers A0 (source block) and Al (destination block).
- 12 - SOFTWARE SUPPORT FOR MOTOROLA 68000 CERN M68MIL CROSS MACRO ASSEMBLER M 68000 PROGRAMMING MODEL
The next instruction uses address register indirect with postincrement for source and destination operand. The following operations will occur:
• fetch the long word pointed to by AO from memory.
• add four (we are loading four bytes) to the contents of register A0
• store the long word into memory at the address indicated by register Al
• add four (we are storing four bytes) to the contents of register Al
When we now start the next instruction both registers point to the next oper ands (source and destination respectively).
Address Register Indirect with Predecrement:
The general form of a MOVE instruction using address register indirect with predecrement addressing modes for both operands would be
MOVE -(An),-(An)
This address mode is similar to the one just described, but the M 68000 first subtracts one, two or four (again depending on the size of the opera tion) from the contents of the address register and then uses this contents as an address for data access.
The above coding sequence to copy three long words could well have been written using address register indirect with predecrement as follows:
MOVE #$100C,A0 fourth item in source block
MOVE »$200C,A1 fourth item in destin, block
M0VE.L -(A0),-(A1) decrement addresses and move
M0VE.L -(A0),-(A1)
M0VE.L -(A0),-(A1)
These two addressing modes, the address register indirect with postincrement or predecrement allow easily to maintain stacks with push and pull operations and to manipulate queues. The stack of the M 68000 (system stack or user stack, depending on privilege state) is addressed using address register A7. As a consequence of the M 68000 design it grows from high addresses to low addresses and shrinks from low addresses to high addresses (see in chapter Machine Instructions: JSR and RTS instructions). In other words, to push information on to the stack we use
MOVE.W «S1000,-(A7) pushes value $1000
- 13 - SOFTWARE SUPPORT FOR MOTOROLA 68000 CERN M68MIL CROSS MACRO ASSEMBLER M 68000 PROGRAMMING MODEL
The following operations will occur
• fetch the word containing the value $1000 (immediate addressing mode)
• subtract two from the contents of address régi ster A7 (we want to push a word)
• store the word into memory at the address contained in address register A7
The value $1000 is now stored on the stack and register A7 is pointing to it» that is to say> register A7 always points to last valid entry on the stack which is also called: the top of the stack. If we now want to inspect the word on the top of the stack» we may write
TST (A7) TST sets condition codes
if however we want to pull the word off the stack, we may write
MOVE (A7)+,D0 top of stack => DO
Note: If the information to be pushed on or pulled off the M 68000 stack is a byte» i.e. if we write
MOVE.B D0,-(A7) push bits 0-7 from DO
or
MOVE.B (A7)+,D0 pull byte into bits 0-7 of DO
the M 68000 will behave as follows
push:
• in order to keep the M 68000 stack pointer aligned on word boundai— ies, two rather than one will be subtracted from address register A7 although we just want to push one byte
• the byte contained in bits 0-7 of DO will be stored as upper byte of the memory word register A7 is pointing to» the low order byte of that memory word remains unchanged
pull:
• the byte at the memory location pointed to by the stack pointer A7 will be loaded into bits 0-8 of the data register DO
• the stack pointer A7 will be incremented by two in order to keep it aligned on word boundaries
- 14 - SOFTWARE SUPPORT FOR MOTOROLA 68000 CERN M68MIL CROSS MACRO ASSEMBLER M 68000 PROGRAMMING MODEL
Address Register Indirect with Displacement:
The general form of a MOVE instruction using address register indirect with displacement addressing modes for both operands would be
MOVE dl6(An),dl6(An)
Here the M 68000 uses the contents of the address register as the base address and allows the addition of a signed 16 bit displacement integer to obtain the effective address. Thus we can access an address range of
[ - 32 768 .. + 32 767 ]
where is the contents of the address register.
This addressing mode is particularly useful to handle tables. Assume we have in register A3 the base address of a table containing the addresses of peripheral equipment we have to monitor» each address is supposed to be 32-bits long. If we now want to load the address of the fifth peripheral
equipment contained in that table into register A4t we can write
MOVE.L 4*(5-l)(A3),A4
and could now use address register A4 to read for instance the status regis ter of that equipment.
Note:
• address register A3 not only contains the base address of the table» but it also points to the first element in the table
• each element in the table is four bytes long; in order to access the n-th element in the table we have to calculate 4*(n-l) as the displace ment to be used
• for clarity of documentation we can leave it to the assembler to evalu ate such an expression
Address Register Indirect with Index and Displacement:
The general form of a MOVE instruction using address register indirect with index and displacement addressing modes for both operands would be
MOVE d8CAn,Rn.S),d8(An,Rn.S)
where the optional size designator n.S" for the register Rn could be either ".W" or n.L".
- 15 - SOFTWARE SUPPORT FOR MOTOROLA 68000 CERN M68MIL CROSS MACRO ASSEMBLER M 68000 PROGRAMMING MODEL
The M68MIL assembler will calculate the displacement of "
Program Counter Relative with Index and Displacement:
The general form of a MOVE instruction using program counter relative with index and displacement addressing mode for the source operand would be