Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 3 Introduction to the 68000 Register Set: data, address, condition code, status. Register Set: data, address, condition code, status. Basic Instruction.

Similar presentations


Presentation on theme: "Chapter 3 Introduction to the 68000 Register Set: data, address, condition code, status. Register Set: data, address, condition code, status. Basic Instruction."— Presentation transcript:

1 Chapter 3 Introduction to the Register Set: data, address, condition code, status. Register Set: data, address, condition code, status. Basic Instruction Set Basic Instruction Set Basic addressing modes: register, absolute, immediate, register indirect, etc. Basic addressing modes: register, absolute, immediate, register indirect, etc. Assembling and debugging a program Assembling and debugging a program

2 Register Set D 31 D 16 D 08 D 00 D0 D7 D6 PC 8 general-purpose data registers. Word operation on D 00 -D 15, byte operation on D 00 -D 07 8 general-purpose data registers. Word operation on D 00 -D 15, byte operation on D 00 -D 07 PC points at the next instruction to be executed PC points at the next instruction to be executed

3 Address Register: A0-A7 Memory A 0E A0 A 31 A 16 A 00 A0 A1 A7 8 address registers of 32 bits. 8 address registers of 32 bits. Information in an address register represents a location in memory. Information in an address register represents a location in memory. Special one: A7 is used as stack pointer. Special one: A7 is used as stack pointer. [M(A0)] = [M(1005)] = 57

4 Condition Code Register The CCR is updated to reflect the result of the operation.The CCR is updated to reflect the result of the operation. Z=1if the result is 0Z=1if the result is 0 C=1if there is carry-out from MSB V=1if there is overflow N=1if the result is negative Carry oVerflow CVZN X 07 Zero Negative eXtend

5 Instruction Set The has a large instruction set.The has a large instruction set. –Move data –Modify or operate the data –Change execution sequence –Determine the operation mode of CPU e.g. MOVE.BD3,1234e.g. MOVE.BD3,1234 MOVE.B#25,D2 Classification of instruction set architectureClassification of instruction set architecture –CISC (Complex instruction set computer): large instruction set, powerful, but difficult to optimize code –RISC (Reduced instruction set computer): smaller instruction set, easy to optimize code, but longer program

6 Data Movement Register-to-register, register-to-memory, memory-to-register, memory-to-memory, constant-to-memory/register.Register-to-register, register-to-memory, memory-to-register, memory-to-memory, constant-to-memory/register. 8-bit, 16-bit, 32-bit correspond to MOVE.B, MOVE.W, MOVE.L8-bit, 16-bit, 32-bit correspond to MOVE.B, MOVE.W, MOVE.L Legal:Assembler FormRTLLegal:Assembler FormRTL MOVE.B D1,D2[D2]  [D1] MOVE.B D3, 1234[M(1234)]  [D3] MOVE.B 1234,2000[M(2000)]  [M(1234)] MOVE.B #12,1234[M(1234)]  12 Illegal:MOVE.B D3,#1212  [D3] ???Illegal:MOVE.B D3,#1212  [D3] ???

7 Unconditional Branch BRA: BranchBRA: Branch BRA address ; GOTO address Example: BRANEXT MOVE.BD1,D2 NEXTMOVE.B#1,D4 Which instruction will be executed after BRA NEXT is executed?

8 Conditional Branch BEQ, BNE, BCC, BCS, BVSBEQ, BNE, BCC, BCS, BVSExample: BCCCheck_5 IF c=0 THEN branch to Check_5 MOVE.BD1,D2 … Check_5MOVE.B#1,D4 BCCCheck_5 C=0C=1 Check_5 MOVE.B #1,D4 MOVE.B D1,D2

9 Conditional Branches (con.) BNEBranch on [CCR(Z)]=0 BEQBranch on [CCR(Z)]=1 BCCBranch on [CCR(C)]=0 BCSBranch on [CCR(C)]=1 BVCBranch on [CCR(V)]=0 BVSBranch on [CCR(V)]=1 The complete set of conditional branch instructions is given in Table 5.2 on page 208. (e.g., BLT, BLE, BGT, BGE, etc.)The complete set of conditional branch instructions is given in Table 5.2 on page 208. (e.g., BLT, BLE, BGT, BGE, etc.)

10 CMP and TST Useful for changing program flowUseful for changing program flow CMP: CompareCMP: Compare –Syntax: CMP src,Dn –Operation: [Dn] - [src] –Result of - is not saved TST: Test an operandTST: Test an operand –Syntax: TST dest –Compare [dest] to 0, no result saved TST D1 is the same as CMP __,D1TST D1 is the same as CMP __,D1

11 IFX1 = 0THEN X1 := Y1 IF1MOVE.B X1,D0(or “TST.B X1”) BNE ENDIF1 THEN1MOVE.B Y2,X1 ENDIF1…other code Change Program Flow IF1 Set Flag Test Opposite Condition and BR to ENDIF if TRUE THEN1 IF-Part ENDIF1...

12 IFX1 = 0THENX1 := Y1 ELSEX1 := Y2 Wrong IF1 MOVE.B X1,D0 BEQ THEN1 BEQ THEN1 ELSE1 MOVE.B Y2,X1 THEN1 MOVE.B Y1,X1 ENDIF1 … Right IF1 MOVE.B X1,D0 BEQ THEN1 BEQ THEN1 ELSE1 MOVE.B Y2,X1 BRA ENDIF1 BRA ENDIF1 THEN1 MOVE.B Y1,X1 ENDIF1... Change Program Flow (con.)

13 IFX1 = 0THENX1 := Y1 ELSEX1 := Y2 IF1 MOVE.B X1,D0 BNE ELSE1 BNE ELSE1 THEN1 MOVE.B Y1,X1 BRA ENDIF1 must have this branch BRA ENDIF1 must have this branch ELSE1 MOVE.B Y2,X1 ENDIF1... Change Program Flow (con.)

14 WHILE (K > 0) DO S WHILETST.B K BLE ENDWH test opposite condition S loop body BRA WHILE ENDWH... Change Program Flow (con.)

15 FOR I = N1 TO N2 DO S MOVE.B N1,D0 D0: loop counter MOVE.B N1,D0 D0: loop counter NEXTCMP.B N2,D0 BGT ENDFOR S loop body ADD.B #1,D0 BRA NEXT ENDFOR... Change Program Flow (con.)

16 1 assembly language instruction = 1 machine language instruction 1 assembly language instruction = 1 machine language instruction 1 high-level language instruction  1 machine language instructions 1 high-level language instruction  1 machine language instructions

17 Subroutine … BSR ADD12 BSR ADD12 … … ADD12 ADD.B D1,D2 SUB.B #12,D2 SUB.B #12,D2 RTS RTS

18 Data Typing Most high-level language, like Pascal, Java, Ada, are said to be strongly typed.Most high-level language, like Pascal, Java, Ada, are said to be strongly typed. Assembly language is not strongly typed.Assembly language is not strongly typed. How about C/C++?How about C/C++? –Example: A character can be multiplied by an integer. JAVA?JAVA?

19 Data Typing (con.) ORG$1000 ADC.B$12 BDC.W$3456 CDS.B1 DDS.L1 MOVE.BA,D0 ADD.BB,D0[D0]  $12 + $34 MOVE.BA,D0 ADD.WB,D0[D0]  $12 + $3456 MOVE.LA,D0 ADD.LB,D0[D0]  ? A 1000 B 1002 C MOVE.WA,D0 ADD.WB,D0[D0]  $ $3456 Memory Map D 1006

20 Arithmetic Operation ADD, SUB, CLR, NEG, ASL, ASRADD, SUB, CLR, NEG, ASL, ASR ADD.B 1234,D3; [D3]  [M(1234)]+[D3]ADD.B 1234,D3; [D3]  [M(1234)]+[D3] The CCR is updated accordingly.The CCR is updated accordingly. Example: V3 = V1 + V2Example: V3 = V1 + V2 signed integers unsigned integers ORG$400 V1DC.B12 V2DC.B14 V3DS.B1 ORG$600 MOVE.BV1,D0 ADD.B V2,D0 MOVE.B D0,V3 BVS Error1... ORG$400 V1DC.B12 V2DC.B14 V3DS.B1 ORG$600 MOVE.BV1,D0 ADD.B V2,D0 MOVE.B D0,V3 BCS Error1... Are the codes correct? Data Program Where is the right place for BVS/BCS?

21 Arithmetic Operation (con.) Subtraction: SUB src, dest; [dest]  [dest] - [src] SUB.BD2,D0 ; [D0(0:7)]  [D0(0:7)] - [D2(0:7)]SUB.BD2,D0 ; [D0(0:7)]  [D0(0:7)] - [D2(0:7)] SUB.WD2,D0 ; [D0(0:15)]  [D0(0:15)] - [D2(0:15)] SUB.WD2,D0 ; [D0(0:15)]  [D0(0:15)] - [D2(0:15)] SUB.LD2,D0 ; [D0]  [D0] - [D2] SUB.LD2,D0 ; [D0]  [D0] - [D2]Clear CLR.BD0 ; [D0(0:7)]  0CLR.BD0 ; [D0(0:7)]  0 Negation: negative value, i.e,, 2’s complement NEG.BD4 ; 2’s complement of D4NEG.BD4 ; 2’s complement of D4 If [D4] = , after [D4] =

22 ASL (Arithmetic Shift Left) Format:Format: –ASL #n,dest or ASL D i,dest shifts bits in dest LEFT by n or [D i ] places, respectively shifts bits in dest LEFT by n or [D i ] places, respectively The bit shifted out is shifted in C-bit of CCR.The bit shifted out is shifted in C-bit of CCR. Example: ASL.B #3,D0 Example: ASL.B #3,D0 [D0] = [C]= [C]= [C]= Operand C 0

23 ASL (Arithmetic Shift Left) Why is ASL useful?Why is ASL useful? ASL is the fastest way to perform “multiply by 2’s power” ASL dest = ASL #1,destASL dest = ASL #1,dest What does ASL #n, dest do?What does ASL #n, dest do? [dest]  [dest] x 2 n How to multiply D0 by 2 ? [D0] = After ASL.B #1,D0 [D0] = Can ASR cause overflow?

24 ASR (Arithmetic Shift Right) Example: [D0] = -22 = After “ASR.B #1,D0” [D0] = = -11 [CCR(c)] = 0 Operand C MSB Same as ASL, butSame as ASL, but –bits shifted to RIGHT –MSB is duplicated back into MSB (Why?) ASR.B #1,D0 is equivalent to dividing D0 by 2ASR.B #1,D0 is equivalent to dividing D0 by 2 How to divide D1 by 32 ? Can ASR cause overflow?

25 Effect of Arithmetic Operations on CCR Addition: Addition:  1, if carry out from MSB  1, if carry out from MSB C =   0, otherwise  0, otherwise  1, if operands are of same sign and  1, if operands are of same sign and V =  their sum is of the opposite sign  0, otherwise  0, otherwise ____ ____ ____ V= a n-1  b n-1  s n-1 + a n-1  b n-1  s n-1 where a n-1, b n-1, s n-1 are the MSBs of source destination and result, respectively

26 Effect of Arithmetic Operations on CCR Subtraction: Subtraction:  1, if NO carry out from MSB  1, if NO carry out from MSB C =   0, otherwise  0, otherwise  1, if operands are of opposite sign and  1, if operands are of opposite sign and V =  the result is of same sign as the source  0, otherwise  0, otherwise ____________ V= (a n-1  b n-1 )  (d n-1  a n-1 ) where a n-1, b n-1, d n-1 are the MSBs of source destination and result, respectively

27 Logical Operation AND, OR, EOR, NOTAND, OR, EOR, NOT If [D0] = If [D0] = AND.B #% ,D0 ;[D0]= OR.B #% ,D0 ;[D0]= EOR.B #% ,D0 ;[D0]=

28 Use Registers Accesses to data registers are faster than accesses to memory.Accesses to data registers are faster than accesses to memory. Shorter instruction, 3 bits to indicate either one of 8 general-purpose registers.Shorter instruction, 3 bits to indicate either one of 8 general-purpose registers. Use comments to indicate how registers are used in program.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, D6 GetCharMOVE.BACIAC,D1 BTST.B#RDRF,D1 BEQGetChar MOVE.BACIAC,D0 AND.B#% ,D1 MOVE.BD1,D6 RTS

29 Addressing Modes Concerned with the way in which data is accessed (where operand can be found)Concerned with the way in which data is accessed (where operand can be found) Data register direct, absolute, immediate, and address register indirect.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 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.Looking for a house in a new environment, “61 William Street” (actual address) is necessary, even with a city name.

30 Absolute Addressing Use the actual or absolute address of the operand, e.g. CLR.B $234Use the actual or absolute address of the operand, e.g. CLR.B $234 MOVE.B D2, $2000MOVE.B D2, $2000 The source is data register direct, a type of absolute addressing mode. $2000 is memory location 2000 Symbols can also be usedSymbols can also be usedExample: MOVE.BInput,D0 SUB.BTime,D0

31 Immediate Addressing MOVE.B #25,D2; [D2]  25MOVE.B #25,D2; [D2]  25 Immediate addressing is faster than the absolute addressing.Immediate addressing is faster than the absolute addressing. Data 25 is part of the instruction  stored in IR.Data 25 is part of the instruction  stored in IR. Absolute Addressing: HoursDC.B 25 ADD.B Hours,D2 Immediate Addressing: HoursEQU 25 ADD.B #Hours,D2 What about “ADD.B #Hours,D2What about “ADD.B Hours,D2

32 MOVE.B P,D0 CMP.B #7,D0 BLE OutOfRange CMP.B #25,D0 BGE OutOfRange MOVE.B #6,X OutOfRange… IF 7 { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://slideplayer.com/3269709/11/images/slide_31.jpg", "name": "MOVE.B P,D0 CMP.B #7,D0 BLE OutOfRange CMP.B #25,D0 BGE OutOfRange MOVE.B #6,X OutOfRange… IF 7

33 Address Register Indirect The address of an operand is found in an address register, A0 to A7The address of an operand is found in an address register, A0 to A7 Pointer or referencePointer or reference MOVEA: copy an address to address regMOVEA: copy an address to address reg MOVEA.L #$1000,A0 MOVEA.L #$1000,A0 CLR.B (A0) CLR.B (A0) same effect as same effect as CLR.B $ A FFF

34 Indirect Addressing Two accesses:Two accesses: 1) to the address register A0 to find the actual address of operand, ) to the memory location 1000 to get the operand. Why is address register indirect addressing useful?Why is address register indirect addressing useful?

35 Example: Add 100 numbers together, the data starts at memory location MOVE.B $2000,D0 ADD.B $2001,D0 ADD.B $2002,D0 ADD.B $2003,D0 : ADD.B $2063,D0 CLR.B D0 MOVEA.L #$2000,A0 NEXTADD.B (A0),D0 ADDA.L #1,A0 CMPA.L #$2064,A0 BNE NEXT

36 Different Addressing 1 * Program to test the different addressing modes. 1 * Program to test the different addressing modes. 2 * [D2]  [M(0)] + 26.By Mingrui Zhang 2 * [D2]  [M(0)] + 26.By Mingrui Zhang ORG$ ORG$ A ABSOL: DC.B A ABSOL: DC.B A IMMED: EQU A IMMED: EQU ORG $ ORG $ C MOVEA.L #$1000,A C MOVEA.L #$1000,A MOVE.L $0,D MOVE.L $0,D A D410 ADD.B (A0),D A D410 ADD.B (A0),D C MOVE.L $0,D C MOVE.L $0,D D ADD.B ABSOL,D D ADD.B ABSOL,D MOVE.L $0,D MOVE.L $0,D A ADD.B #IMMED,D A ADD.B #IMMED,D C 4E STOP #$ C 4E STOP #$ END $ END $2000

37 The Teesside MC68000 Cross- assembler and Simulator Desing the program Edit source file Cross-assemble the program Run the program TOOLS FILES text editor Test.X68 X68K Test.BIN (and Test.LIS) E68K

38 Debugging Commands HELP: Provide information about commandsHELP: Provide information about commands MD (.): Displays the contents of memoryMD (.): Displays the contents of memory e.g. MD 400 MD 400 -DI ;disassemble the contents of memory. memory. MM: Memory modificationMM: Memory modification e.g. MM 400 -BMM W MM 400 -B -DECMM W -DEC DF: Displays the contents of all registersDF: Displays the contents of all registers.PC: set PC.PC: set PC e.g..PC 400 GO: Execute program, (ESC to escape)GO: Execute program, (ESC to escape) TR: Executes a single instruction at a timeTR: Executes a single instruction at a time BR 10000: Places a marker at location 10000BR 10000: Places a marker at location QU: QuitQU: Quit


Download ppt "Chapter 3 Introduction to the 68000 Register Set: data, address, condition code, status. Register Set: data, address, condition code, status. Basic Instruction."

Similar presentations


Ads by Google