Chapter 3 Introduction to the 68000 - PowerPoint PPT Presentation

1 / 42
About This Presentation
Title:

Chapter 3 Introduction to the 68000

Description:

V= an-1 bn-1 sn-1 an-1 bn-1 sn-1. where an-1, bn-1, sn-1 are the MSBs of ... MM 400 -B -DEC MM 2100 -W -DEC. DF: Displays the contents of all registers ... – PowerPoint PPT presentation

Number of Views:46
Avg rating:3.0/5.0
Slides: 43
Provided by: wsu64
Category:

less

Transcript and Presenter's Notes

Title: Chapter 3 Introduction to the 68000


1
Chapter 3Introduction 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

2
Register Set
  • 8 general-purpose data registers. Word operation
    on D00-D15, byte operation on D00-D07
  • PC points at the next instruction to be
    executed. 31
    00

3
Address 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.

Assume D4 2341AC05. After MOVE.B
(A0),D4 D4 2341AC57
M(A0) M(1005) 57
4
Condition Code Register
  • The CCR is updated to reflect the result of the
    operation.
  • Z1 if the result is 0
  • C1 if there is carry-out from MSB
  • V1 if there is overflow
  • N1 if the result is negative

5
Instruction Set
  • The 68000 has a large instruction set.
  • Move data
  • Modify or operate the data
  • Change execution sequence
  • Determine the operation mode of CPU
  • Classification of instruction set architecture
  • CISC (Complex instruction set computer) large
    instruction set, powerful, but difficult to
    optimize code (Motorola 68000, Intel x86, etc.)
  • RISC (Reduced instruction set computer)
    smaller instruction set, easy to optimize code,
    but longer program (e.g., PowerPC, Sun SPARC,
    MIPS, etc.)

6
Instruction Format
  • Motorola 68000 uses Two-Address Instruction
    Format
  • Op-code Src1 Src2 (and Dst)
  • x y x
  • Src1 y, Src2 and Dst x
  • 68000 uses two-address format
  • Example I J K
  • Solution
  • MOVE J,I I ? J
  • ADD K,I I ? K I

Nothing new, think of x y j - k in
Java/C/C
How about ADD K,J MOVE J,I
7
More Examples
  • I J K L
  • I J K L
  • I (J K) L
  • I (J K) L M
  • I J K L M
  • I J K (L M)
  • I (J K) (L M)

8
Data Movement
  • Register-to-register, register-to-memory,
    memory-to-register, memory-to-memory,
    constant-to-memory/register.
  • MOVE src,dest dest ? src
  • MOVE.B, MOVE.W, MOVE.L copy 8-bit, 16-bit,
    32-bit, respectively
  • Legal Assembler Form RTL
  • 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,12 12 ? D3 ???
  • What about MOVE.W X,D1?

9
Data Typing
  • Most high-level language, such as Pascal and 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.
  • Another example A pointer can be manipulated
    arithmetically
  • JAVA?

10
Data Typing (con.)
Memory Map
12
00
A 1000
ORG 1000 A DC.B 12 B DC.W 3456 C DS.B 1 D DS.L
1
34
56
B 1002
C 1004
00
00
00
00
D 1006
00
00
MOVE.B A,D0 ADD.B B,D0 D0 ? 12 34
MOVE.B A,D0 ADD.W B,D0 D0 ? 12 3456
MOVE.W A,D0 ADD.W B,D0 D0 ? 1200 3456
MOVE.L A,D0 ADD.L B,D0 D0 ? ?
11
Arithmetic Operation
  • ADD, SUB, CLR, NEG, ASL, ASR
  • ADD.B 1234,D3 D3 ? M(1234)D3
  • The CCR is updated accordingly.
  • Example V3 V1 V2
  • signed integers unsigned integers

Data
Are the codes correct?
Program
Where is the right place for BVS/BCS?
12
Arithmetic Operation (con.)
  • Subtraction SUB src, dest dest ? dest -
    src
  • SUB.B D2,D0 D0(07) ? D0(07) - D2(07)
  • SUB.W D2,D0 D0(015) ? D0(015) -
    D2(015)
  • SUB.L D2,D0 D0 ? D0 - D2
  • At least one of the two operands of ADD/SUB must
    be a data register.
  • Clear
  • CLR.B D0 D0(07) ? 0
  • Negation negative value, i.e,, 2s complement
  • NEG.B D4 2s complement of D4
  • If D4 01101100, after D4 10010100

13
Two-Address Format Revisit
  • Example I J K
  • Solution
  • MOVE J,I I ? J
  • ADD K,I I ? K I
  • If I, J, and K are memory locations, then
  • Solution
  • MOVE J,D0 D0 ? J
  • ADD K,D0 D0 ? K D0
  • MOVE D0,I I ? D0

OR MOVE J,D0 MOVE K,D1 ADD D1,D0 MOVE
D0,I
14
More Examples
  • I J K L
  • I J K L
  • I (J K) L
  • I (J K) L M
  • I J K L M
  • I J K (L M)
  • I (J K) (L M)

15
ASL (Arithmetic Shift Left)
C
0
Operand
  • Format
  • ASL n,dest
  • or
  • ASL Di,dest Di is a data register
  • 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,D0
  • D0 0 1 0 1 1 1 0 0
  • C0 1 0 1 1 1 0 0 0
  • C1 0 1 1 1 0 0 0 0
  • C0 1 1 1 0 0 0 0 0

16
ASL (Arithmetic Shift Left)
  • Why is ASL useful?
  • ASL is the fastest way to perform
  • multiply by 2s power
  • What does ASL n, dest do?
  • dest ? dest x 2n

Can ASL cause overflow?
17
ASR (Arithmetic Shift Right)
  • Same as ASL, but
  • bits shifted to RIGHT
  • MSB is duplicated back into MSB (Why?)
  • ASR.B 1,D0 is equivalent to dividing D0 by 2

How to divide D1 by 32 ?
  • Example D0 -22 11101010
  • After ASR.B 1,D0
  • D0 11110101 -11
  • CCR(c) 0

Can ASR cause overflow?
18
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

19
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

20
Logical Operation
  • AND, OR, EOR, NOT
  • If D0 11110000
  • AND.B 10100110,D0 D010100000
  • OR.B 10100110,D0 D011110110
  • EOR.B 10100110,D0 D001010110
  • NOT.B D0 D000001111

21
Unconditional Branch
  • BRA Branch
  • BRA address GOTO address
  • Example
  • BRA NEXT
  • MOVE.B D1,D2
  • NEXT MOVE.B 1,D4
  • Which instruction will be executed after BRA NEXT
    is executed?

22
Conditional Branch
  • BEQ, BNE, BCC, BCS, BVS, etc.
  • Example
  • BCC Check_5 IF c0 THEN branch to Check_5
  • MOVE.B D1,D2
  • Check_5 MOVE.B 1,D4

23
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.)

24
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 D1 is the same as CMP __,D1

25
IF X1 0 THEN X1 Y1
Change Program Flow IF-THEN
IF1 Set Flag Test Opposite Condition
and BR to ENDIF if
TRUETHEN1 IF-PartENDIF1 ...
  • IF1 MOVE.B X1,D0 (or TST.B X1)
  • BNE ENDIF1
  • THEN1 MOVE.B Y1,X1
  • ENDIF1 other code

26
IF X1 0 THEN X1 Y1 ELSE X1 Y2
Change Program Flow IF-THEN-ELSE
  • Wrong
  • IF1 TST.B X1
  • BEQ THEN1
  • ELSE1 MOVE.B Y2,X1
  • THEN1 MOVE.B Y1,X1
  • ENDIF1

Right IF1 TST.B X1 BEQ
THEN1 ELSE1 MOVE.B Y2,X1 BRA
ENDIF1 THEN1 MOVE.B Y1,X1 ENDIF1 ...
27
IF X1 0 THEN X1 Y1 ELSE X1 Y2
Change Program Flow IF-THEN-ELSE
Another solution IF1 TST.B X1
BNE ELSE1 THEN1 MOVE.B Y1,X1 BRA
ENDIF1 must have this branch ELSE1
MOVE.B Y2,X1 ENDIF1 ...
28
WHILE (K gt 0) DO S
Change Program Flow WHILE LOOP
While (k gt 0) S
WHILE TST.B K BLE ENDWH test
opposite condition S loop body BRA
WHILE ENDWH ...
29
FOR I N1 TO N2 DO Si.e.,for (I N1 I lt N2
I) S
Change Program Flow FOR LOOP
MOVE.B N1,D0 D0 loop counter
I NEXT CMP.B N2,D0 BGT
ENDFOR S loop body ADD.B
1,D0 BRA NEXT ENDFOR ...
30
1 assembly language instruction 1 machine
language instruction
Note that
  • 1 high-level language instruction ? 1 machine
    language instructions

31
Subroutine
  • BSR ADD12
  • BSR ADD12
  • ADD12 ADD.B D1,D2
  • SUB.B 12,D2
  • RTS

main
subroutine
32
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 Tims (relative location) is
    enough.
  • Looking for a house in a new environment, 61
    William Street (actual address) is necessary,
    even with a city name.

33
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.

34
Absolute Addressing
  • Use the actual or absolute address of the
    operand, e.g. CLR.B 234
  • MOVE.B D2,2000
  • MOVE.B D2,2000
  • MOVE.B D2,2000
  • The source is data register direct, a type of
    absolute addressing mode. 2000 is memory
    location 200016
  • Symbols can also be used
  • Example

35
Immediate 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.

Immediate Addressing Hours EQU 25 ADD.B
Hours,D2
What about ADD.B Hours,D2
What about ADD.B Hours,D2
36
IF 7ltPlt25 THEN X 6if ((7ltP) (Plt25))
X 6
  • MOVE.B P,D0
  • CMP.B 7,D0
  • BLE OutOfRange
  • CMP.B 25,D0
  • BGE OutOfRange
  • MOVE.B 6,X
  • OutOfRange

CLR.B D1 D1 X MOVE.B 1,D0 D0
I NEXT ADD.B D0,D1 ADD.B 1,D0 CMP.B
10,D0 BLE NEXT MOVE.B D1,X
X 0FOR I 1 TO 10 X X IX
0for (I 1 I lt 10 I) X X I
37
Address Register Indirect
  • The address of an operand is found in an address
    register, A0 to A7
  • Pointer or reference
  • MOVEA copy an address to address reg
  • MOVEA.L 1000,A0
  • CLR.B (A0)
  • same effect as
  • CLR.B 1000

38
Indirect 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?

39
Example Add 100 numbers together, the data
starts at memory location 200016
  • 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 NEXT ADD.B
(A0),D0 ADDA.L 1,A0 CMPA.L
2064,A0 BNE NEXT
40
Different Addressing
1 Program to
test the different addressing modes. 2
D2 ? M(0) 26. By
Mingrui Zhang 3 4
00001000
ORG 1000 5 00001000 1A ABSOL
DC.B 26 6 0000001A IMMED
EQU 26 7 8
00002000 ORG
2000 9 00002000 207C00001000 MOVEA.L
1000,A0 or MOVEA.L ABSOL,A0 10
00002006 24380000 MOVE.L 0,D2
11 0000200A D410 ADD.B
(A0),D2 12 13
0000200C 24380000 MOVE.L 0,D2
14 00002010 D4381000 ADD.B
ABSOL,D2 15 16
00002014 24380000 MOVE.L 0,D2
17 00002018 0602001A ADD.B
IMMED,D2 18 19
0000201C 4E722700 STOP
2700 20 00002000
END 2000
41
The Teesside MC68000 Cross-assembler and Simulator
TOOLS FILES text editor Test.X68 X68K
Test.BIN (and Test.LIS) E68K
42
Debugging Commands
  • HELP Provide information about commands
  • MD (.) Displays the contents of memory
  • e.g. MD 400
  • 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
Write a Comment
User Comments (0)
About PowerShow.com