19419cfd929f4cbbfac238c38f74a148.ppt
- Количество слайдов: 38
Chapter 3 Introduction to the 68000 • Register Set: data, address, condition code, status. • Basic Instruction Set • Basic addressing modes: register, absolute, immediate, register indirect, etc. • Assembling and debugging a program
Register Set • 8 general-purpose data registers. Word operation on D -D , byte operation on D -D 00 D 31 15 00 D 16 D 08 07 D 00 D 6 D 7 • PC points at the next instruction to be executed. 31 00 PC
Address Register: A 0 -A 7 • 8 address registers of 32 bits. • Information in an address register represents a location in memory. • Special one: A 7 is used as stack pointer. A 31 A 16 Memory A 00 A 1 A 7 1004 1005 1006 1007 4 A 57 0 E 07 A 0 1005 [M(A 0)] = [M(1005)] = 57
Condition Code Register 7 N Z V e. Xtend Negative Zero o. Verflow Carry X 0 C • The CCR is updated to reflect the result of the operation. • Z=1 if the result is 0 C=1 if there is carry-out from MSB V=1 if there is overflow N=1 if the result is negative
Instruction Set • The 68000 has a large instruction set. – – • e. g. Move data Modify or operate the data Change execution sequence Determine the operation mode of CPU MOVE. B D 3, 1234 MOVE. B #25, D 2 • Classification 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
Data Movement • 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. L • Legal: RTL MOVE. B D 1, D 2 [D 2] [D 1] MOVE. B • Illegal: Assembler Form [M(1234)] [D 3] [M(2000)] [M(1234)] 12 D 3, 1234, 2000 #12, 1234 MOVE. B D 3, #12 12 [D 3] ? ? ?
Unconditional Branch • BRA: Branch BRA address ; GOTO address Example: BRA MOVE. B NEXT D 1, D 2 MOVE. B #1, D 4 Which instruction will be executed after BRA NEXT is executed?
Conditional Branch • BEQ, BNE, BCC, BCS, BVS Example: BCC Check_5 MOVE. B D 1, D 2 IF c=0 THEN branch to Check_5 … Check_5 MOVE. B #1, D 4 BCC C=0 Check_5 MOVE. B #1, D 4 Check_5 C=1 MOVE. B D 1, D 2
Conditional Branches (con. ) BNE Branch on [CCR(Z)]=0 BEQ Branch on [CCR(Z)]=1 BCC Branch on [CCR(C)]=0 BCS Branch on [CCR(C)]=1 BVC Branch on [CCR(V)]=0 BVS Branch on [CCR(V)]=1 • The complete set of 68000 conditional branch instructions is given in Table 5. 2 on page 208. (e. g. , BLT, BLE, BGT, BGE, etc. )
CMP and TST • Useful for changing program flow • CMP: Compare – Syntax: CMP src, Dn – Operation: [Dn] - [src] – Result of - is not saved • TST: Test an operand – Syntax: TST dest – Compare [dest] to 0, no result saved • TST D 1 is the same as CMP __, D 1
Change Program Flow IF 1 Set Flag Test Opposite Condition and BR to ENDIF if TRUE THEN 1 IF-Part ENDIF 1. . . IF X 1 = 0 X 1 : = Y 1 IF 1 THEN 1 ENDIF 1 THEN MOVE. B X 1, D 0 (or “TST. B X 1”) BNE ENDIF 1 MOVE. B Y 2, X 1 … other code
Change Program Flow (con. ) IF X 1 = 0 Wrong IF 1 MOVE. B X 1, D 0 BEQ THEN 1 ELSE 1 MOVE. B Y 2, X 1 THEN 1 MOVE. B Y 1, X 1 ENDIF 1 … THEN ELSE Right IF 1 X 1 : = Y 2 MOVE. B X 1, D 0 BEQ THEN 1 ELSE 1 MOVE. B Y 2, X 1 BRA ENDIF 1 THEN 1 MOVE. B Y 1, X 1 ENDIF 1. . .
Change Program Flow (con. ) IF X 1 = 0 THEN ELSE MOVE. B X 1, D 0 BNE ELSE 1 THEN 1 MOVE. B Y 1, X 1 BRA ENDIF 1 ELSE 1 MOVE. B Y 2, X 1 ENDIF 1. . . X 1 : = Y 1 X 1 : = Y 2 IF 1 must have this branch
Change Program Flow (con. ) WHILE (K > 0) DO S WHILE ENDWH TST. B K BLE ENDWH S BRA WHILE. . . test opposite condition loop body
Change Program Flow (con. ) FOR I = N 1 TO N 2 DO S NEXT ENDFOR. . . MOVE. B CMP. B BGT S ADD. B BRA N 1, D 0: loop counter N 2, D 0 ENDFOR loop body #1, D 0 NEXT
• 1 assembly language instruction = 1 machine language instruction • 1 high-level language instruction 1 machine language instructions
Subroutine … BSR ADD 12 … … ADD 12 ADD. B D 1, D 2 SUB. B #12, D 2 RTS
Data Typing • Most 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?
Data Typing (con. ) A B C D ORG DC. B DC. W DS. B DS. L $1000 $12 $3456 1 1 A B C D 1000 1002 1004 1006 MOVE. B ADD. B A, D 0 B, D 0 [D 0] $12 + $34 MOVE. B ADD. W A, D 0 B, D 0 [D 0] $12 + $3456 MOVE. W ADD. W A, D 0 B, D 0 [D 0] $1200 + $3456 MOVE. L ADD. L A, D 0 B, D 0 [D 0] ? Memory Map 12 00 34 56 00 00 00
Arithmetic Operation • • Data Program ADD, SUB, CLR, NEG, ASL, ASR ADD. B 1234, D 3 ; [D 3] [M(1234)]+[D 3] The CCR is updated accordingly. Example: V 3 = V 1 + V 2 signed integers unsigned integers V 1 V 2 V 3 ORG DC. B DS. B ORG MOVE. B ADD. B MOVE. B BVS. . . $400 12 14 1 $600 V 1, D 0 V 2, D 0, V 3 Error 1 V 2 V 3 ORG DC. B DS. B ORG MOVE. B ADD. B MOVE. B BCS. . . $400 12 14 1 $600 V 1, D 0 V 2, D 0, V 3 Error 1 Are the codes correct? Where is the right place for BVS/BCS?
Arithmetic Operation (con. ) Subtraction: SUB src, dest ; [dest] - [src] • SUB. B D 2, D 0 ; [D 0(0: 7)] - [D 2(0: 7)] SUB. W D 2, D 0 ; [D 0(0: 15)] - [D 2(0: 15)] SUB. L D 2, D 0 ; [D 0] - [D 2] Clear • CLR. B D 0 ; [D 0(0: 7)] 0 Negation: negative value, i. e, , 2’s complement • NEG. B D 4 ; 2’s complement of D 4 If [D 4] = 01101100, after [D 4] = 10010100
ASL (Arithmetic Shift Left) C Operand 0 • Format: – ASL #n, dest or ASL Di, dest shifts bits in dest LEFT by n or [Di] places, respectively • The bit shifted out is shifted in C-bit of CCR. • Example: ASL. B #3, D 0 [D 0] = 0 1 1 1 0 0 [C]=0 10111000 [C]=1 01110000 [C]=0 11100000
ASL (Arithmetic Shift Left) • Why is ASL useful? ASL is the fastest way to perform “multiply by 2’s power” • ASL dest = ASL #1, dest • What does ASL #n, dest do? [dest] x 2 n How to multiply D 0 by 2 ? [D 0] = 00000110 610 After ASL. B #1, D 0 Can ASR cause overflow? [D 0] = 00001100 1210
ASR (Arithmetic Shift Right) MSB Operand C • Same as ASL, but – bits shifted to RIGHT – MSB is duplicated back into MSB (Why? ) • ASR. B #1, D 0 is equivalent to dividing D 0 by 2 Example: [D 0] = -22 = 11101010 After “ASR. B #1, D 0” [D 0] = 11110101 = -11 [CCR(c)] = 0 How to divide D 1 by 32 ? Can ASR cause overflow?
Effect of Arithmetic Operations on CCR • Addition: 1, if carry out from MSB C= 0, otherwise 1, if operands are of same sign and V= their sum is of the opposite sign 0, otherwise ____ V= an-1 bn-1 sn-1 + an-1 bn-1 sn-1 where an-1, bn-1, sn-1 are the MSBs of source destination and result, respectively
Effect of Arithmetic Operations on CCR • Subtraction: 1, if NO carry out from MSB C= 0, otherwise 1, if operands are of opposite sign and V = the result is of same sign as the source 0, otherwise ______ V= (an-1 bn-1) (dn-1 an-1) where an-1, bn-1, dn-1 are the MSBs of source destination and result, respectively
Logical Operation • AND, OR, EOR, NOT • If [D 0] = 11110000 AND. B #%10100110, D 0 OR. B #%10100110, D 0 EOR. B #%10100110, D 0 ; [D 0]=10100000 ; [D 0]=11110110 ; [D 0]=01010110
Use Registers • Accesses 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. * Get. Char: Input an ASCII-coded character into D 0 * Input Parameters: None * Output parameters: ASCII character in D 0, Error code in D 6 * Registers modified: D 0, D 1, D 6 Get. Char MOVE. B ACIAC, D 1 BTST. B #RDRF, D 1 BEQ Get. Char MOVE. B ACIAC, D 0 AND. B #%01111100, D 1 MOVE. B D 1, D 6 RTS
Addressing Modes • Concerned 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.
Absolute Addressing • Use the actual or absolute address of the operand, e. g. CLR. B $234 • MOVE. B D 2, $2000 The source is data register direct, a type of absolute addressing mode. $2000 is memory location 2000 • Symbols can also be used Example: MOVE. B Input, D 0 SUB. B Time, D 0
Immediate Addressing • MOVE. B #25, D 2 ; [D 2] 25 • Immediate addressing is faster than the absolute addressing. • Data 25 is part of the instruction stored in IR. Absolute Addressing: Immediate Addressing: Hours DC. B 25 ADD. B Hours, D 2 Hours EQU 25 ADD. B #Hours, D 2 What about “ADD. B Hours, D 2
MOVE. B P, D 0 IF 7
Address Register Indirect • The address of an operand is found in an address register, A 0 to A 7 • Pointer or reference • MOVEA: copy an address to address reg • MOVEA. L #$1000, A 0 CLR. B (A 0) same effect as CLR. B $1000 0 FFF 1000 1001 1002 1003 00 1000 A 0
Indirect Addressing • Two accesses: 1) to the address register A 0 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?
Example: Add 100 numbers together, the data starts at memory location 200016 MOVE. B ADD. B : ADD. B $2000, D 0 $2001, D 0 $2002, D 0 $2003, D 0 $2063, D 0 CLR. B MOVEA. L NEXT ADD. B ADDA. L CMPA. L BNE D 0 #$2000, A 0 (A 0), D 0 #1, A 0 #$2064, A 0 NEXT
Different Addressing 1 * Program to test the different addressing modes. 2 * [D 2] [M(0)] + 26. By Mingrui Zhang 3 4 00001000 ORG $1000 5 00001000 1 A ABSOL: DC. B 26 6 0000001 A IMMED: EQU 26 7 8 00002000 ORG $2000 9 00002000 207 C 00001000 MOVEA. L #$1000, A 0 10 00002006 24380000 MOVE. L $0, D 2 11 0000200 A D 410 ADD. B (A 0), D 2 12 13 0000200 C 24380000 MOVE. L $0, D 2 14 00002010 D 4381000 ADD. B ABSOL, D 2 15 16 00002014 24380000 MOVE. L $0, D 2 17 00002018 0602001 A ADD. B #IMMED, D 2 18 19 0000201 C 4 E 722700 STOP #$2700 20 00002000 END $2000
The Teesside MC 68000 Crossassembler and Simulator TOOLS FILES Desing the program Edit source file Cross-assemble the program Run the program text editor Test. X 68 K E 68 K Test. BIN (and Test. LIS)
Debugging Commands • HELP: Provide information about commands • MD (. ): Displays the contents of memory e. g. MD 400 -DI ; disassemble the contents of memory. • MM: Memory modification e. g. MM 400 -B MM 2100 -W MM 400 -B -DEC MM 2100 -W -DEC • DF: Displays the contents of all registers • . PC: set PC e. g. . PC 400 • GO: Execute program, (ESC to escape) • TR: Executes a single instruction at a time • BR 10000: Places a marker at location 10000 • QU: Quit