Lecture 3: MC68000 instruction set

g Assembler directives (the most important ones)
n ORG, EQU, END, DC, DS, EXTERN/PUBLIC

g Instructions (the most important ones)
n n n n n n n n

Data movement Integer arithmetic Boolean Shift and rotate Bit manipulation Binary Coded Decimal Program flow System control

Microprocessor-based System Design Ricardo Gutierrez-Osuna Wright State University

1

including n defining symbols and assigning them values n controlling the flow of execution of the assembler n setting format and content of the object and listing files Microprocessor-based System Design Ricardo Gutierrez-Osuna Wright State University 2 .Assembler directives g Assembler directives n are instructions to the assembler program g and they appear in the mnemonic (opcode) field of the source code n are not instructions to the microprocessor g and they have no direct effect on the contents of memory (except DC) g They cover a number of functions.

Assembler directives (the most important ones) DIRECTIVE ORG EQU END DC DS RSEG EXTERN PUBLIC OPERATION set program origin equate value to symbol end of source program define data constant define RAM storage begin relocatable segment define external symbol define public symbol symbol [label] [label] SYNTAX ORG value EQU value END label DC number[.symbol][…] Microprocessor-based System Design Ricardo Gutierrez-Osuna Wright State University 3 .symbol][…] PUBLIC symbol[.number][…] DS count RSEG name EXTERN symbol[.

d0 g NOTES n Hex address $1000 is set as the starting address for the following instruction n The opcode for MOVE.L goes in address $1002 … and so on Microprocessor-based System Design Ricardo Gutierrez-Osuna Wright State University 4 .The ORG directive g FUNCTION (ORIGIN) n Sets the starting address in memory for the instructions or data constants that follow g EXAMPLE 00001000 00001000 203C 00000012 1 2 ORG MOVE.L $1000 #$12.L goes in address $1000 g The second word for MOVE.

d0 $2000 n Assigns a value to a symbol.L 6 END $1000 $100 $2000 #count. The symbol is used later in the program in place of the value 203C 00000100 g NOTES n The value of $100 replaces the symbol in the binary code n The use of EQU directives is encouraged because g makes program more readable g makes programs easier to maintain Microprocessor-based System Design Ricardo Gutierrez-Osuna Wright State University 5 .The EQU directive g FUNCTION (EQUATE) g EXAMPLE 00001000 00000100 00002000 00002000 00002006 1 ORG 2 count EQU 3 4 ORG 5 MOVE.

d0 $1000 g NOTES n The label of the END directive (optional) represents the entry point for the program n The address of the entry point is used by debuggers. to identify the starting address of the program Microprocessor-based System Design Ricardo Gutierrez-Osuna Wright State University 6 .The END directive g FUNCTION n Used at the end of the source program n Statements following the END directive are not processed by the assembler g EXAMPLE 00001000 00001000 00001006 203C 00000012 1 2 3 ORG MOVE.L END $1000 #$12. and so on. loaders. conversion utilities.

B DC.B DC.0 $1000 0005FFFF 05FF 777269676874 0D00 g NOTES n For words and longwords.The DC directive g FUNCTION (DEFINE CONSTANT) n Places data constants WITHIN A PROGRAM g EXAMPLE 0000000D 00001000 00001000 00001004 00001006 0000100C 0000100E 1 2 3 4 5 6 7 cr num more name var EQU ORG DC DC.-1 5.B END $0D $1000 5. the assembler adjusts the address of the constant to ensure proper alignment.-1 ’wright’ cr. n ASCII characters defined as words are left-justified within the word Microprocessor-based System Design Ricardo Gutierrez-Osuna Wright State University 7 .

they will contain garbage data Microprocessor-based System Design Ricardo Gutierrez-Osuna Wright State University 8 . g EXAMPLE 00000004 00001000 00001000 00001004 00001005 1 length 2 3 buffer 4 temp 5 EQU ORG DS.The DS directive g FUNCTION (DEFINE STORAGE) n Reserves RAM storage for use during execution of the program.B END 4 $1000 length $FF FF g NOTES n The memory locations reserved for buffer are not initialized.B DC.

RTS g NOTES n MAIN. which will typically be shared among several main programs...subroutine is . whereas SUBS.W BSR … … … SQRT #100.ASM PUBLIC SQRT SQRT .defined here … … .The EXTERN/PUBLIC directives g FUNCTION n Used when a program is split over multiple files (modules) g EXAMPLE MAIN. Microprocessor-based System Design Ricardo Gutierrez-Osuna Wright State University 9 .ASM contains the subroutines.D7 SQRT SUBS.ASM EXTERN MOVE.ASM contains the code of a main program.

bit set. .. g Shift and rotate n Arithmetic-shift. g Binary Coded Decimal n Add. Microprocessor-based System Design Ricardo Gutierrez-Osuna Wright State University 10 . . NOT.. jump and return g System control n Miscellaneous: trap. logical-shift. bit clear.. . subtraction.Instruction categories g Data movement n Move operands (data) among memory locations or registers g Integer arithmetic n Addition.. g Boolean n AND. reset.. SR/CCR manipulation. multiply. subtract and negate in BCD notation g Program flow n Branch... . OR. divide. rotate g Bit manipulation n Bit test. XOR..

W #$8C.-(A7) .copies all working .or 32-bit value from one memory location or register to another memory location or register Copies a source operand to an address register.D0 [D0]←$FFFFFFFD [D0]←$00000004 MOVEM MOVEM.A0 MOVEA. MOVEA.D0 MOVE.registers to stack Microprocessor-based System Design Ricardo Gutierrez-Osuna Wright State University 11 .D0 MOVE. MOVE. MOVEA operates only on words or longwords.Data movement INSTR. The data to be moved is sign-extended before it is copied to its destination Transfers the contents of a group of registers specified by a list.D0 EXAMPLE [D0]←$XXXXXX8C [D0]←$XXXX008C [D0]←$0000008C MOVEA MOVEA.W #$8C00. 16. MOVE DESCRIPTION Copies an 8-. Copies a 8-bit signed value in the range –128 to +127 to one of the eight data registers.B #$8C.AO [A0]←$FFFF8C00 [A0]←$00008C00 MOVEQ MOVEQ #-3.L #$8C00. MOVEM operates only on words or longwords.L A0-A3/D0-D7.D0 MOVEQ #4. The list of registers is defined as Ai-Aj/Dp-Dq.W sign-extends the 16-bit operand to 32 bits.L #$8C.

EXAMPLE ADD. Assume [D0]=$1234B021. Assume [D0]=$1234B021.B D0 CLR.L D0 NEG.8] . MULS is similar but treats data as signed. EXT. DIVS is similar but treats data as signed. CRL (clear) writes zeros into the destination operand. ADD× SUB× MULU MULS DIVU DIVS CLR NEG EXT DESCRIPTION ADD×/SUB× add/subtract the contents of a source to/from the contents of a destination and deposits the result in the destination location. The 16-bit result is stored in the low word of the destination. DIVU (divide unsigned) works with a 32-bit dividend and a 16bit divisor.W converts an 8-bit into a 16-bit.[D0]←$00400000 DIVS #-3. Direct memory-to-memory operations are not permitted.L D0 . Sign-extend increases the bit-size of a signed integer.[D0]←$00007EDD MULU #$0800.[D0]←$00000000 .[D0]←$1234B000 .[D1]←$22228123 .L converts a 16-bit into a 32-bit.[D0]←$12340021 .[D0]←$FFFFB021 Microprocessor-based System Design Ricardo Gutierrez-Osuna Wright State University 12 .W ADD. Assume [D0]=$0000000E.D1 D0.D1 #N.L D0. NEG (negate) performs a 2s complement operation on the destination data--subtracts it from zero. MULU (multiply unsigned) forms the product of two 16-bit integers. 1410.D1 D1. and the 16bit remainder in the high word. and EXT.D0 .D0 .L ADDQ SUB. The dividend must be a data register.[D1]←$11118123 .D0 .W D0 EXT. Assume [D0]=$ABCD8000.N∈[1. Assume [D0]=$11118000 and [D1]=$11110123.[D0]←$12344FDF .[D0]←$0002FFFC CLR. The 32-bit destination must be a data register.Integer arithmetic INSTR.W D0 EXT.

Assume [D0]=$1234F0F0.XOR of the lowest byte of D0 .D0 NOT.Boolean INSTR.W D0 TST D0 Microprocessor-based System Design Ricardo Gutierrez-Osuna Wright State University 13 .B #%10101010.significant bit of D0 . Similar to CMP #0. Bit-wise NOT operation. Normally used to clear. operand EXAMPLE ANDI.C ORI. AND ANDI OR ORI EOR EORI NOT TST DESCRIPTION Bit-wise logical AND operation.set even bits of D0 . certain bits in a destination operand.[D0]←$12340F0F .B #%0111111.Z and clear V. Bit-wise logical OR operation. Bit-wise logical XOR operation.D0 EOR.D0 .lowest byte .B #%11111111.update N. Normally used to set certain bits in a destination operand.clear the 8th least . or mask.

Shift and rotate INSTR. ASL OPERATION Arithmetic shift left Arithmetic shift right Logic shift left Logic shift right C X 0 Operand C X C X Operand C X Operand 0 BIT MOVEMENT Operand 0 ASR LSL LSR ROL Rotate left C Operand ROR Rotate right Swap words of a longword Operand C SWAP 16 bits 16 bits Microprocessor-based System Design Ricardo Gutierrez-Osuna Wright State University 14 .

Bit manipulation INSTR.[D0]←$00000008 and [Z]←0 BCHG #4. D0 .[D0]←$0000000D and [Z]←1 BCLR #0. D0 .[Z]←1 Microprocessor-based System Design Ricardo Gutierrez-Osuna Wright State University 15 . BSET BCLR BCHG BTST DESCRIPTION Bit test and set Causes the Z-bit to be set if the specified bit is zero and then forces the specified bit of the operand to be set to one Bit test and clear works like BSET except that the specified bit is cleared (forced to zero) after it has been tested Bit test and change causes the value of the specified bit to be reflected in the Z-bit and then toggles (inverts) the state of the specified bit Bit test reflects the value of the specified bit in the Z-bit EXAMPLE (Assume [D0]=$00000009) BSET #2. D0 . D0 .[D0]←$00000019 and [Z]←1 BTST #2.

NBCD D1 . [C]←1 Microprocessor-based System Design Ricardo Gutierrez-Osuna Wright State University 16 . This is SBCD D1. [D1]=21) DESCRIPTION Adds the source operand and the X-bit to the destination operand using BCD arithmetic.[D0]←00000027 a BYTE operation only.[D1]←00000069 a BYTE operation only. [D0]=48. [V]←1.D1 .[D1]←00000052 Subtract the destination operand and the X-bit from zero.D0 . This is ABCD D0. ABCD SBCD NBCD EXAMPLE (Assume [X]=0. so the X-bit is used to provide a mechanism for multi-byte BCD operations. Subtract the source operand and the X-bit from the destination operand using BCD arithmetic. the X-bit is used to provide a mechanism for multi-byte BCD operations.Binary Coded Decimal INSTR. .[X]←1.

If the destination is outside of a 16-bit signed integer. Bcc cannot be used. Bcc (branch conditional) is used whenever program execution must follow one of two paths depending on a condition. BRA Bcc BSR RTS JMP DESCRIPTION BRA (branch always) implements an unconditional branch.or 16-bit signed integer. BSR branches to a subroutine.or 16-bit signed integer. The PC is saved on the stack before loading the PC with the new value. relative to the PC. The offset is expressed as an 8. including absolute address (see reference manual). The condition is specified by the mnemonic cc. RTS is use to return from the subroutine by restoring the PC from the stack. cc CC CS NE EQ PL MI HI LS GT LT GE LE VC VS T F CONDITION Carry clear Carry set Not equal Equal Plus Minus Higher than Lower than or same as Greater than Less than Greater than or equal to Less than or equal to Overflow clear Overflow set Always true Always false BRANCH TAKEN IF C=0 C=1 Z=0 Z=1 N=0 N=1 CZ = 1 C+Z=1 NVZ + N V Z = 1 NV + N V = 1 NV + N V = 0 Z + (NV + N V) = 1 V=0 V=1 Always Never Microprocessor-based System Design Ricardo Gutierrez-Osuna Wright State University 17 . If the destination is outside of a 16-bit signed integer.Program flow (details in Lecture 5) INSTR. JMP (jump) is similar to BRA. The offset is expressed as an 8. whereas JMP has more addressing modes. BRA cannot be used. The only difference is that BRA uses only relative addressing.

(2) sets the execution mode to supervisor and (3) loads the PC with a new value read from a vector table STOP loads the SR with an immediate operand and stops the CPU. AND.System control INSTR. RESET asserts the CPU’s RESET line for 124 cycles. OR and EOR that allow altering the bits in the status and condition code registers. MOVE ANDI ORI EORI TRAP DESCRIPTION Unique variations of MOVE. If STOP or RESET are executed in user mode. a privilege violation occurs. TRAP performs three operations: (1) pushes the PC and SR to the stack. STOP RESET Microprocessor-based System Design Ricardo Gutierrez-Osuna Wright State University 18 .

Sign up to vote on this title
UsefulNot useful