Presentation on theme: "Chapter 3 Introduction to the 68000"— Presentation transcript:
1Chapter 3 Introduction to the 68000 Register Set: data, address, condition code, status.Basic Instruction SetBasic addressing modes: register, absolute, immediate, register indirect, etc.Assembling and debugging a program
2Register Set8 general-purpose data registers. Word operation on D00-D15, byte operation on D00-D07D31D16D08D00D0D7D6PC points at the next instruction to be executedPC
3Address Register: A0-A7 8 address registers of 32 bits. Information in an address register represents a location in memory.Special one: A7 is used as stack pointer.Memory10051004100610074A0E0757A0A31A16A00A0A1A7[M(A0)] = [M(1005)] = 57
4Condition Code Register CarryoVerflowCVZNX7ZeroNegativeeXtendThe CCR is updated to reflect the result of the operation.Z=1 if the result is 0C=1 if there is carry-out from MSBV=1 if there is overflowN=1 if the result is negative
5Instruction Set The 68000 has a large instruction set. Move dataModify or operate the dataChange execution sequenceDetermine the operation mode of CPUe.g. MOVE.B D3,1234MOVE.B #25,D2Classification of instruction set architectureCISC (Complex instruction set computer): large instruction set, powerful, but difficult to optimize codeRISC (Reduced instruction set computer): smaller instruction set, easy to optimize code, but longer program
7Unconditional Branch BRA: Branch BRA address ; GOTO address Example: BRA NEXTMOVE.B D1,D2NEXT MOVE.B #1,D4Which instruction will be executed after BRA NEXT is executed?
8Conditional Branch BEQ, BNE, BCC, BCS, BVS Example: BCC Check_5 IF c=0 THEN branch to Check_5MOVE.B D1,D2…Check_5 MOVE.B #1,D4BCC Check_5C=0C=1Check_5 MOVE.B #1,D4MOVE.B D1,D2
9Conditional Branches (con.) BNE Branch on [CCR(Z)]=0BEQ Branch on [CCR(Z)]=1BCC Branch on [CCR(C)]=0BCS Branch on [CCR(C)]=1BVC Branch on [CCR(V)]=0BVS Branch on [CCR(V)]=1The complete set of conditional branch instructions is given in Table 5.2 on page 208. (e.g., BLT, BLE, BGT, BGE, etc.)
10CMP and TST Useful for changing program flow CMP: Compare Syntax: CMP src,DnOperation: [Dn] - [src]Result of - is not savedTST: Test an operandSyntax: TST destCompare [dest] to 0, no result savedTST D1 is the same as CMP __,D1
11Change Program FlowIF1 Set Flag Test Opposite Condition and BR to ENDIF if TRUE THEN1 IF-Part ENDIF1 ...IF X1 = 0 THEN X1 := Y1IF1 MOVE.B X1,D0 (or “TST.B X1”)BNE ENDIF1THEN1 MOVE.B Y2,X1ENDIF1 … other code
18Data TypingMost high-level language, like Pascal, Java, Ada, are said to be strongly typed.Assembly language is not strongly typed.How about C/C++?Example: A character can be multiplied by an integer.JAVA?
22ASL (Arithmetic Shift Left) OperandFormat:ASL #n,destorASL Di,destshifts bits in dest LEFT by n or [Di] places, respectivelyThe bit shifted out is shifted in C-bit of CCR.Example: ASL.B #3,D0[D0] =[C]=[C]=[C]=
23ASL (Arithmetic Shift Left) Why is ASL useful?ASL is the fastest way to perform“multiply by 2’s power”ASL dest = ASL #1,destWhat does ASL #n, dest do?[dest] [dest] x 2nHow to multiply D0 by 2 ?[D0] =After ASL.B #1,D0[D0] =Can ASR cause overflow?
24ASR (Arithmetic Shift Right) OperandCMSBSame as ASL, butbits shifted to RIGHTMSB is duplicated back into MSB (Why?)ASR.B #1,D0 is equivalent to dividing D0 by 2How to divideD1 by 32 ?Example: [D0] = -22 =After “ASR.B #1,D0”[D0] = = -11[CCR(c)] = 0Can ASR cause overflow?
25Effect of Arithmetic Operations on CCR Addition: 1, if carry out from MSBC = 0, otherwise 1, if operands are of same sign andV = their sum is of the opposite sign____ ____ ____V= an-1 bn-1 sn-1 + an-1 bn-1 sn-1where an-1, bn-1, sn-1 are the MSBs ofsource destination and result, respectively
26Effect of Arithmetic Operations on CCR Subtraction: 1, if NO carry out from MSBC = 0, otherwise 1, if operands are of opposite sign andV = the result is of same sign as the source____________V= (an-1 bn-1) (dn-1 an-1)where an-1, bn-1, dn-1 are the MSBs ofsource destination and result, respectively
27Logical Operation AND, OR, EOR, NOT If [D0] = 11110000 AND.B #% ,D0 ;[D0]=OR.B #% ,D0 ;[D0]=EOR.B #% ,D0 ;[D0]=
28Use RegistersAccesses to data registers are faster than accesses to memory.Shorter instruction, 3 bits to indicate either one of 8 general-purpose registers.Use comments to indicate how registers are used in program.* GetChar: Input an ASCII-coded character into D0* Input Parameters: None* Output parameters: ASCII character in D0, Error code in D6* Registers modified: D0, D1, D6GetChar MOVE.B ACIAC,D1BTST.B #RDRF,D1BEQ GetCharMOVE.B ACIAC,D0AND.B #% ,D1MOVE.B D1,D6RTS
29Addressing ModesConcerned with the way in which data is accessed (where operand can be found)Data register direct, absolute, immediate, and address register indirect.Looking for a house in a familiar neighborhood, “The house next to Tim’s” (relative location) is enough.Looking for a house in a new environment, “61 William Street” (actual address) is necessary, even with a city name.
30Absolute AddressingUse the actual or absolute address of the operand, e.g. CLR.B $234MOVE.B D2, $2000The source is data register direct, a type of absolute addressing mode. $2000 is memory location 2000Symbols can also be usedExample:MOVE.B Input,D0SUB.B Time,D0
31Immediate Addressing MOVE.B #25,D2 ; [D2] 25 Immediate addressing is faster than the absolute addressing.Data 25 is part of the instruction stored in IR.Absolute Addressing:Hours DC.B 25ADD.B Hours,D2Immediate Addressing:Hours EQU 25ADD.B #Hours,D2What about “ADD.B #Hours,D2What about “ADD.B Hours,D2
32IF 7<P<25 THEN X := 6 if ((7<P) && (P<25)) X = 6; MOVE.B P,D0CMP.B #7,D0BLE OutOfRangeCMP.B #25,D0BGE OutOfRangeMOVE.B #6,XOutOfRange …IF 7<P<25 THEN X := 6 if ((7<P) && (P<25)) X = 6;CLR.B D1 D1: XMOVE.B#1,D0 D0: INEXT ADD.B D0,D1ADD.B #1,D0CMP.B #10,D0BLE NEXTMOVE.B D1,XX := 0 FOR I := 1 TO X = X + I X = 0; for (I = 1; I <= 10; I++) X = X + I;
33Address Register Indirect The address of an operand is found in an address register, A0 to A7Pointer or referenceMOVEA: copy an address to address regMOVEA.L #$1000,A0CLR.B (A0)same effect asCLR.B $10001000A00FFF10011002100300
34Indirect Addressing Two accesses: 1) to the address register A0 to find the actual address of operand, 1000.2) to the memory location 1000 to get the operand.Why is address register indirect addressing useful?
35Example: Add 100 numbers together, the data starts at memory location 200016 MOVE.B $2000,D0ADD.B $2001,D0ADD.B $2002,D0ADD.B $2003,D0:ADD.B $2063,D0CLR.B D0MOVEA.L #$2000,A0NEXT ADD.B (A0),D0ADDA.L #1,A0CMPA.L #$2064,A0BNE NEXT
36Different Addressing* Program to test the different addressing modes.* [D2] [M(0)] By Mingrui Zhang3ORG $1000A ABSOL: DC.B 26A IMMED: EQU 267ORG $2000C MOVEA.L #$1000,A0MOVE.L $0,D2A D ADD.B (A0),D212C MOVE.L $0,D2D ADD.B ABSOL,D215MOVE.L $0,D2A ADD.B #IMMED,D218C 4E STOP #$2700END $2000
37The Teesside MC68000 Cross-assembler and Simulator TOOLS FILEStext editor Test.X68X68K Test.BIN (and Test.LIS)E68KDesing the programEdit source fileCross-assemble the programRun the program
38Debugging Commands HELP: Provide information about commands MD (.): Displays the contents of memorye.g. MD 400MD 400 -DI ;disassemble the contents ofmemory.MM: Memory modificatione.g. MM 400 -B MM WMM 400 -B -DEC MM W -DECDF: Displays the contents of all registers.PC: set PCe.g. .PC 400GO: Execute program, (ESC to escape)TR: Executes a single instruction at a timeBR 10000: Places a marker at location 10000QU: Quit