Sei sulla pagina 1di 28

68000 Assembly Language Programming

Universiti Teknikal Malaysia Melaka


Faculty of Electronics and Computer Engineering
Department of Computer Engineering

BENM 2123 MICROPROCESSOR TECHNOLOGY


Chapter 2:

Humans difficult writing program directly in machine code (binary language understood by microprocessor). Assembly language make it easier for writing that will produce source file (.ASM) contain all instruction mnemonic. The source will be converted to actual language information that machine will understand by a special program called an assembler (ASM68K). The assembler will translate source file into three files;
Object file (.OBJ) contain only machine language List file (.LST) contain all text from source file and additional information. Hex file (.HEX) printable version for object file (object code).

The 68000 Assembly Language Programming


07/08 Masrullizam Mat Ibrahim
UNIVERSITI TEKNIKAL MALAYSIA MELAKA 68000 Assembly Language Programming 1

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

Assembly Language Programming

68000 Assembly Language Programming

68000 Assembly Language Programming

Instruction format

LABEL pointer to the instructions memory operation OPCODE operation code OPERANDS data used in the operation COMMENTS for program documentation

Example:
DATA1 PLACE DATA2 ORG DC.W DS.L EQU $8000 $3F0C $2 $F4 ;set PC for data area ;define constant as $3F0C ;reserve memory locations ;to store two longword ;equate constant

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

Printed with FinePrint trial version - purchase at www.fineprint.com

STNEMMOC
4

SDNAREPO

EDOCPO

LE BAL

68000 Assembly Language Programming

68000 Assembly Language Programming

Opcode
Opcode is an operation code that will be executed by microprocessor. Associates with the size of data to be executed i.e. opcode.<field> that can be:
Byte, <opcode>.B Word, <opcode>.W Longword, <opcode>.L

Label normally used during branch and reference operation. Comment provide readability for future reference.
Explain the operation of each instruction. Semicolon (;) sign start the comment.

Linker
A program that combines all objects files after assembled and tested individually into one large object file. Linker will examine each object file due to:
Its length in bytes Its proper place in the final object file Modification should be made to it

Operand
Operand can be:
Register Constant Memory address

Special collection of object files sometimes available in a library file where may contain often-used program

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

68000 Assembly Language Programming

68000 Assembly Language Programming

Basic addressing mode


Dn :Data register direct An :register indirect #n :immediate N :absolute MOVE.L MOVE.L MOVE.L MOVE.L D0, D1 (A0), D1 #10, D1 $100011 , D1

Loader
A program takes care of loading program into memory. Usually linker and loader are combined into a single program called a link-loader.

Immediate operand can be specified in several format


Hexadecimal ($) Octal (@) Decimal (& or nothing) Binary (%) ASCII (within single quotes abc)

Example files

Label and comments


Label refers to, for example starting points of functions, loop starts and loop ends, and certain data storage locations. Due to difficulty for us to determine the exact memory address of the pointed location
UNIVERSITI TEKNIKAL MALAYSIA MELAKA

.asm
6
UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

07/08 Masrullizam Mat Ibrahim

Printed with FinePrint trial version - purchase at www.fineprint.com

68000 Assembly Language Programming

Addressing Mode

68000 Assembly Language Programming

Microprocessor could not directly manipulate data memory location. The data have to loaded into register, manipulated, and written back into memory. Addressing to unsure the processes could be done effectively. In MC68000 there are 14 different addressing modes. The example presented for addressing modes make use the MOVE instruction.
.lst

Syntax of MOVE instruction:


MOVE.<size> <source> , <destination>

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

11

MC68000 Instruction Group


Data transfer Arithmetic

68000 Assembly Language Programming

68000 Assembly Language Programming

Move operands (data) among memory locations and registers Addition, subtraction, multiply, divide,

Logical
AND, NOT, OR, XOR,

Shift and rotate


Arithmetic shift, logical shift, rotate

Bit manipulation
Bit test, bit set, bit clear,

BCD operation
Add and subtract BCD notation

Program flow
Branch, jump and return

System control
Miscellaneous : trap, reset, SR/CCR manipulation,
UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

10

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

12

Printed with FinePrint trial version - purchase at www.fineprint.com

68000 Assembly Language Programming

68000 Assembly Language Programming

Address register direct

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

13

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

15

68000 Assembly Language Programming

68000 Assembly Language Programming

Data register direct

Address register indirect

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

14

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

16

Printed with FinePrint trial version - purchase at www.fineprint.com

68000 Assembly Language Programming

68000 Assembly Language Programming

Address register indirect with postincrement

Address register indirect with offset

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

17

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

19

68000 Assembly Language Programming

68000 Assembly Language Programming

Address register indirect with predecrement

Address index register indirect with offset

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

18

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

20

Printed with FinePrint trial version - purchase at www.fineprint.com

68000 Assembly Language Programming

68000 Assembly Language Programming

Absolute short address

Program counter with offset

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

21

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

23

68000 Assembly Language Programming

68000 Assembly Language Programming

Absolute long address

Program counter with offset and index

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

22

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

24

Printed with FinePrint trial version - purchase at www.fineprint.com

68000 Assembly Language Programming

Instruction Set Format

68000 Assembly Language Programming

Immediate data

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

25

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

27

68000 Assembly Language Programming

68000 Assembly Language Programming

Quick immediate data

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

26

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

28

Printed with FinePrint trial version - purchase at www.fineprint.com

Machine Code Generation

68000 Assembly Language Programming

Instruction Set (Data Transfer)


EXG Exchange register LEA Load effective address LINK Link and allocate MOVE Move data MOVEA Move address MOVEM Move multiple address MOVEP Move peripheral data MOVEQ Move quick PEA Push Effective data SWAP Swap register halves UNLK - Unlink
* Please refer to instruction set

68000 Assembly Language Programming

10

000

000

111

100

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

29

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

31

68000 Assembly Language Programming

68000 Assembly Language Programming

10

000

000

111

100

Instruction format = 0010 0000 0011 1100 = $203C Machine code = 203C 00000012

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

30

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

32

Printed with FinePrint trial version - purchase at www.fineprint.com

68000 Assembly Language Programming

68000 Assembly Language Programming

Example 1: What is the new value for each register after the following instructions are executed?
Register Name Content 00000000 00000059

Example 2 :
Write MC68000 assembly code to :
Load data byte $A9 and data word $F0E2 into D6 and D2 respectively. Interchange the data without loading a new data into both data registers.

MOVE.B

#$59,D0

Old D0 New D0 Old D2 New D2

Register Name Content 00000000 00000000

MOVE.B #$A9,D6 MOVE.W #$F0E2,D2 MOVE.L D6,D0 MOVE.L D2,D6

MOVE.W

#$1F36,D2

0000FFFF 00001F36

Initial D6 Initial D2

Load D6

000000A9 0000F0E2 000000A9 0000F0E2 000000A9

MOVE.B

#$38,D3

Old D3 New D3

1234ABCD 1234AB38

MOVE.L D0,D2

Load D2 D0 New D6 New D2

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

33

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

35

68000 Assembly Language Programming

68000 Assembly Language Programming

MOVE.W

#$DE38,D2

Old D2 New D2

00001FD2

0000DE38
1234ABCD

MOVE.W

#$DE38,D3

Old D3 New D3

1234DE38
00001FD2

MOVE.L

#$78DE38,D2

Old D2 New D2

0078DE38
1234ABCD

MOVE.L

#$5678DE38,D3

Old D3 New D3

5678DE38

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

34

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

36

Printed with FinePrint trial version - purchase at www.fineprint.com

68000 Assembly Language Programming

68000 Assembly Language Programming

Example 3:
What is the new value of the register after each instruction is executed?

Solution
Solution 1: Solution 2: ORG $0 MOVEA.L #$3000,A0 MOVE.B (A0)+,D0 MOVE.B (A0)+,D1 MOVE.B (A0)+,D2 MOVE.B (A0)+,D3 MOVEA.L MOVE.B MOVE.B MOVE.B MOVE.B MOVE.B MOVE.B MOVE.B MOVE.B END #$3004,A1 (A1)+,(A0)+ (A1)+,(A0)+ (A1)+,(A0)+ (A1)+,(A0)+ D0,(A1)+ D1,(A1)+ D2,(A1)+ D3,(A1)+

Register Name MOVEA.L #$12549F00,A2 Old A2 New A2 Content 11111111 12549F00

ORG $0 MOVEA.L #$3000,A0 MOVE.L (A0),D0

MOVEA.W #$9F00,A5

Old A5 New A5

4444FFFF FFFF9F00

MOVEA.L #$3004,A1 MOVE.L (A1),(A0) MOVEA.L #$3004,A1 MOVE.L D0,(A1) END

MOVEA.B #$3C7E,A0

Old A0 New A0

22DD33CC ?

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

37

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

39

68000 Assembly Language Programming

68000 Assembly Language Programming

Exercise 1:
Two longword data are stored inside external memory starting at address $3000. The data are $12345678 and $ABCDEF00. Exchange the data so that the first longword will reside at the location where second longword is initially stored and vice-versa Suggestion:
1. Transfer 1st longword into data registers 2. Transfer 2nd longword into memory starting at $3000 3. Transfer 1st longword (stored in registers) into memory starting at $3004

Before 3000 3002 3004 3006 12 56 AB EF


After 3000 3002 3004 3006 ? ? ? ? ? ? ? ? 3001 3003 3005 3007

Exercise 2:
34 78 CD 00 3001 3003 3005 3007

Write an MC68000 assembly language program to run a DC motor in the sequence of FORWARD, STOP, REVERSE, STOP. The motor is interfaced to the microprocessor-based system at address $003004. Bit 4 and 3 are used t control the DC motor, as indicate. The program should starts at address $00000A. Comment your program for readability purpose. Ignore the delay program part.

D15-D0

Operation STOP FORWARD REVERSE

Bit 4 1 1 0

Bit3 1 0 1 68000 SYSTEM


A23-A0

MOTOR DRIVER

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

38

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

40

Printed with FinePrint trial version - purchase at www.fineprint.com

68000 Assembly Language Programming

68000 Assembly Language Programming

Solution
ORG $A MOVEA.L MOVE.B MOVE.B MOVE.B MOVE.B END #$003004, A5 #$10, $003004 #$18, $003004 #$8, $003004 #$18, $003004 ;program starts at this location ;set the interfacing address ;motor forward ;motor stop ;motor reverse ;motor stop ;end of program

Example 4: Assume that D0 through D3 are loaded with 55556666, 77778888, 9999AAAA, BBBBCCCC. A0 points memory location at address 0030B8. What data is written to memory?
Memory Address 0030B8 0030BA 0030BC 0030BE Reg D0 MOVEM.L D0-D3,(A0) D1 D2 D3 55 77 99 BB 55 77 99 BB Content 66 88 AA CC 66 88 AA CC Content 66 88 AA CC 66 88 AA CC

ORG

$A MOVEA.L MOVE.B MOVE.B MOVE.B MOVE.B END #$003004,A5 #$10,(A5) #$18,(A5) #$8,(A5) #$18,(A5)

;program starts at this location ;set the interfacing address ;motor forward ;motor stop ;motor reverse ;motor stop ;end of program

MOVEM.W D0-D3,(A0)

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

41

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

43

68000 Assembly Language Programming

68000 Assembly Language Programming

Example 5:
Memory location start at address $004100 store $1111222288889999. Determine the data in D0 and D1 after execution.
Memory 004100 004101 004102 004103 004104 004105 004106 00417 11 11 22 22 88 88 99 99 MOVEA.L #$004100,A0 MOVEM.W (A0)+,D0/D1 Old D0 New D0 Old D1 New D1 New A0 1234DEFC 12341111 B5D2C7F1 B5D22222 00001034 MOVEA.L #$004100,A0 MOVEM.L (A0),D0/D1 Name Old D0 New D0 Old D1 New D1 New A0 Register Content 1234DEFC 11112222 B5D2C7F1 88889999 00001030

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

42

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

44

Printed with FinePrint trial version - purchase at www.fineprint.com

68000 Assembly Language Programming

68000 Assembly Language Programming

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

45

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

47

68000 Assembly Language Programming

68000 Assembly Language Programming

Example 6: What is the new value of the register after each instruction is executed?

Example 7: What is the new value of the register after each instruction is executed?
Register

Register Name MOVEQ #$B7,D4 Old D4 New D4 Old D6 New D6 Content 1234DEFC 000000B7 B5D2C7F1 0000007B EXG D3,D5

Name Old D3 New D3 Old D5 New D5

Content 1234DEFC B5D2C7F1 B5D2C7F1 1234DEFC

MOVEQ #$7B,D6

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

46

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

48

Printed with FinePrint trial version - purchase at www.fineprint.com

68000 Assembly Language Programming

Pseudo-Opcode

68000 Assembly Language Programming

Mnemonics that understand by the assembler but not the microprocessor There are five pseudo-opcode normally used in MC68000:
ORG
Origin Point the first memory address to store the instructions (source file) of a program

END
End of source file Telling assembler to determine the length of instructions and to generate machine language

DC
Define variable or constant Define value that will be place in object file

DS
Define storage Reserve section of memory

EQU
Equate Define constant value that does not change during exucation
UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

49

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

51

68000 Assembly Language Programming

68000 Assembly Language Programming

Example 8: What is the new value of the register after each instruction is executed?
Register Name SWAP D5 Old D5 New D5 Content 1234DEFC DEFC1234

Example
DATA1 PLACE DATA2 ORG DC.W DS.L EQU ORG MOVE.L MOVE.W MOVE.B MOVEA.L MOVE.L END $8000 $3F0C $2 $F4 ;set PC for data area ;define constant as $3F0C ;reserve memory locations ;to store two longword ;equate constant

START

$8100 ;set PC for instructions area #$12345678,D0 ;load D0 DATA1,D0 ;move word constant to D0 #DATA2,D0 ;move byte constant to D0 #PLACE,A1 ;move memory location where ;place is defined to A1 D0,(A1) ;move data to memory reserved ;by PLACE START ;end of program

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

50

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

52

Printed with FinePrint trial version - purchase at www.fineprint.com

Instruction set (Arithmetic)

68000 Assembly Language Programming

68000 Assembly Language Programming

ADD Add binary ADDA Add address ADDI Add immediate ADDQ Add quick CLR Clear operand CMP Compare CMPA Compare address CMPI Compare immediate CMPM Compare memory DIVS Divide signed numbers DIVU Divide unsigned numbers EXT Extend sign MULS Multiply signed numbers MULU Multiply unsigned numbers
UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

53

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

55

68000 Assembly Language Programming

68000 Assembly Language Programming

NEG Negate NEGX Negate with extend SUB Subtract binary SUBA Subtract address SUBI Subtract immediate SUBQ Subtract quick SUBX Subtract with extend TAS Test and set TST - Test

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

54

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

56

Printed with FinePrint trial version - purchase at www.fineprint.com

68000 Assembly Language Programming

68000 Assembly Language Programming

Example
[D2] = 12345678, [D3] = 5F02C332. What is the result of ADD.B D2,D3?

Register ADD.B D2,D3 Name Old D2 Old D3 Content 12345678 5F02C332

Register Name New D2 New D3 Content 12345678 5F02C3AA

[A0] = CE001A2B, [A3] = 00140300. What is the result of ADDA.W A0,A3?


Register ADDA.W A0,A3 Name Old A0 Old A3 Content CE001A2B 00140300 Register Name New A0 New A3 Content CE001A2B 00141D2B

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

57

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

59

68000 Assembly Language Programming

68000 Assembly Language Programming

[D2] = 250C30F7. What is the different between ADDI.B #$10,D2 and ADDI.W #$10,D2?
Register ADDI.B #$10,D2 Name Old D2 Content 250C30F7 Name New D2 Register Content 250C3007

Register ADDI.W #$10,D2 Name Old D2 Content 250C30F7 Name

Register Content 250C3107

New D2

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

58

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

60

Printed with FinePrint trial version - purchase at www.fineprint.com

68000 Assembly Language Programming

68000 Assembly Language Programming

Example
[D0] = 0000E384, [D1] = CC3EF385. What is the result of SUB.W D0,D1?

Example:
[D4] = 0000000A, [D5] = 00000064. What is the result of MULU.W D4,D5?
Register Register Name New D4 New D5 Content 0000000A 000003E8

Register SUB.W D0,D1 Name Old D0 Old D1 Content 0000E384 CC3EF385

Register
MULU.W D4,D5 Name Old D4 Old D5 Content 0000000A 00000064

Name New D0 New D1

Content 0000E384 CC3E1001

[D4] = 0000FFF0, [D5] = 0000FFF6. What is the result of MULU.W D4,D5? [D2] = 03059A2E. What is the result of SUBI.W #$2C,D2?
Register Register Name New D4 New D5 Content 0000FFF0 FFE600A0

Register SUBI.W #$2C,D2 Name Old D2 Content 03059A2E Name

Register
MULU.W D4,D5

Name Old D3 Old D5

Content 0000FFF0 0000FFF6

Content 03059A02

New D2

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

61

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

63

68000 Assembly Language Programming

68000 Assembly Language Programming

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

62

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

64

Printed with FinePrint trial version - purchase at www.fineprint.com

68000 Assembly Language Programming

68000 Assembly Language Programming

Example:
[D4] = 0000019A, [D5] = 0007A120. What is the result of DIVU D4,D5?
Register DIVU D4,D5 Name Old D4 Old D5 Content 0000019A 0007A120 Register Name New D4 New D5 Content 0000019A 00D204C3

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

65

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

67

68000 Assembly Language Programming

68000 Assembly Language Programming

Example:
[D6] = 485C29AF. What is the result of CMP.W #$29AF,D6?
Register CMP.W #$29AF,D6 Name Old D6 Content 485C29AF Name New D6 Z flag Register Content 485C29AF 1

[A3] = 015030. What is the result of CMPI.W #$5,(A3)?


Memory CMPI.W #$5,(A3) Name Old 015030 Old 015031 Content 05 16 Name New 015030 New 015030 Memory Content 05 16

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

66

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

68

Printed with FinePrint trial version - purchase at www.fineprint.com

68000 Assembly Language Programming

68000 Assembly Language Programming

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

69

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

71

68000 Assembly Language Programming

68000 Assembly Language Programming

Example:
[D0] = ABCDEF1, [D6] = FDAC2345 and [ARRAY] = 0030B8. What is the result of CLR.B D0, CLR.W D6 and CLR.L ARRAY?
Register Name CLR.B D0 Old D0 CLR.W D6 Old D6 ABCDEF1 FDAC2345 New D0 New D6 ABCDE00 FDAC0000 Content Name Register Content

Example:
[D2] = 025055C6. What is the result of NEG.B D2?
Register NEG.B D2 Name Old D2 NEG.W D2 NEG.L D2 Memory Register Name New 0030B8 New 0030BA Content 0000 0000 Address Old 0030B8 Old 0030BA Content 44F0 ACED Old D2 Old D2 Content 025055C6 025055C6 025055C6 Register Name New D2 New D2 New D2 Content 0250553A 0250AA3A FADFAA3A

CLR.L ARRAY

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

70

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

72

Printed with FinePrint trial version - purchase at www.fineprint.com

Instruction Set (logical)


AND logical AND ANDI AND immediate OR logical OR ORI OR immediate EOR Exclusive OR EORI Exclusive OR immediate NOT logical complement

68000 Assembly Language Programming

68000 Assembly Language Programming

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

73

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

75

68000 Assembly Language Programming

68000 Assembly Language Programming

Example:
What is the result of AND.W D0,D1 ?
[D0] = 3795AC5F, [D1] = B6D34B9D.
Register AND.W D0,D1 Name Old D0 Old D1 Content 3795AC5F B6D34B9D Name New D0 New D1 Register Content 3795AC5F

B6D3081D

What is the result of ANDI.L #$F0,D7?


[D7] = 1234ADCB.
Register ANDI.L #$F0,D7 Name Old D7 Content 1234ADCB Register Name New D7 Content

000000C0

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

74

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

76

Printed with FinePrint trial version - purchase at www.fineprint.com

68000 Assembly Language Programming

68000 Assembly Language Programming

Example:
What is the result of OR.L D3,D4 ?
[D3] = FFFFFC18, [D4] = 000186A0.

Register OR.L D3,D4 Name Old D3 Old D4 Content FFFFFC18 000186A0

Register Name New D3 New D4 Content

FFFFFC18 FFFFFEB8

What is the result of ORI.B #$80,D2 ?


[D2] = 22445511.
Register ORI.B #$80,D2 Name Old D2 Content 22445511 Register Name New D2 Content

22445591

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

77

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

79

68000 Assembly Language Programming

68000 Assembly Language Programming

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

78

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

80

Printed with FinePrint trial version - purchase at www.fineprint.com

68000 Assembly Language Programming

68000 Assembly Language Programming

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

81

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

83

68000 Assembly Language Programming

68000 Assembly Language Programming

Example:
What is the result of EOR.W D2,D3 ?
[D2] = 02040608, [D3] = 10121416.
Register EOR.W D2,D3 Name Old D2 Old D3 Content 02040608 10121416 Register Name New D2 New D3 Content

Example:
What is the result of NOT.B D1 ?
[D1] = 000000FF
Register NOT.B D1 Name Old D1 Content 000000FF Name New D1 Register Content

02040608 1012121E

00000000

What is the result of EORI.W #$9119,D4 ?


[D4] = A2B4C6D8
Register EORI.W #$9119,D4 Name Old D4 Content A2B4C6D8 Name New D4 Register Content

A2B457C1

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

82

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

84

Printed with FinePrint trial version - purchase at www.fineprint.com

Instruction Set (shift & rotate)


ASL arithmetic shift left ASR arithmetic shift right LSL logical shift left LSR logical shift right ROL rotate left ROR rotate right ROXL rotate left with extend ROXR rotate right with extend

68000 Assembly Language Programming

68000 Assembly Language Programming

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

85

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

87

68000 Assembly Language Programming

68000 Assembly Language Programming

Example:
What is the result of I. II. ASL.B ASL.W D1,D0 #3,D0 D1,D0 #4,D0
Register Name New D0 New D0 New D0 New D0 Content x c

[D0] = F123123F [D1] = 00000005

III. ASR.W IV. ASR.L

F12312E0 F12391F8 F1230091 FF123123

1 1 0 0 1 1 1 1

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

86

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

88

Printed with FinePrint trial version - purchase at www.fineprint.com

68000 Assembly Language Programming

68000 Assembly Language Programming

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

89

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

91

68000 Assembly Language Programming

68000 Assembly Language Programming

Example:
What is the result of I. II. LSL.B D1,D0 LSL.W #3,D0 [D0] = F123123F. [D1] = 00000005

Example:
What is the result of I. II. ROL.B D1,D0 ROL.W #3,D0 [D0] = F123123F. [D1] = 00000005

III. LSR.W D1,D0 IV. LSR.L #4,D0

III. ROR.W D1,D0 IV. ROR.L #4,D0


Register Register Content
X C

Name New D0 New D0 New D0 New D0

Name New D0 New D0 New D0 New D0

Content

F12312E0 F12391F8 F1230091 0F891891

1 1 0 0 1 1 1 1
90
UNIVERSITI TEKNIKAL MALAYSIA MELAKA

F12312E7 F12391F8 F123F891 FF123123

1 0 1 1
92

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

07/08 Masrullizam Mat Ibrahim

Printed with FinePrint trial version - purchase at www.fineprint.com

68000 Assembly Language Programming

68000 Assembly Language Programming

Instruction Set (Bit Manipulation & BCD Operations)


Bit manipulation
BCHG Bit change BCLR Bit clear BSET Bit set BTST Bit test Example:
D5 = 2C459A7. What is the state of Z flags and contents of D5 after BCHG #6,D5 executed?
Register Name BCHG #6,D5 Old D5 2C459A7 New D1 Content Register Name Content

2C459E7

New Z = 1

BCD operations
ABCD Add BCD NBCD Negate BCD SBCD Subtract BCD
D3 = 0000000C, D4 = 75793290. What is the result of BCLR D3,D4?
Register BCLR D3,D4 Name Old D3 Old D4 Content 0000000C 75793290 Register Name New D3 New D4 Content

0000000C 75792290
95

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

93

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

68000 Assembly Language Programming

Instruction Set (Program Control)


Bcc Conditional branch

68000 Assembly Language Programming

BHI, BLS, BCC, BCS, BNE, BEQ, BVC, BVS, BPL, BMI, BGE, BLT, BGT & BLE.

DBcc Decrement and branch


DBT, DBF, DBHI, DBLS, DBCC, DBCS, DBNE, DBEQ, DBVC, DBVS, DBPL, DBMI, DBGE, DBLT, DBGT & DBLE.

BRA Branch always BSR Branch to subroutine JMP Jump JSR Jump to subroutine RTR Return and store RTS Return from subroutine

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

94

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

96

Printed with FinePrint trial version - purchase at www.fineprint.com

68000 Assembly Language Programming

68000 Assembly Language Programming

Example (BCC/BCS):
What is the value in D0 in the following program?

1.
2. Loop1 3. 4. 5. Loop2 6. 7. 8. Loop3

MOVE.B LSR.B BCC BRA LSL.B BCS BRA END

#$F4,D0 #$2,D0 Loop2 Loop1 #$3,D0 Loop3 Loop2

Register Name Old D0 New D0 (line 2) New D0 (line 5) New D0 Content $000000F4

$0000003D $000000E8

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

97

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

99

68000 Assembly Language Programming

68000 Assembly Language Programming

Example (BEQ):
What is the value in D0 in the following program?

1.
2. Delay 3. 4. 5. Finish

MOVE.B SUBI.B BEQ BRA END

#$FF,D0 #1,D0 Finish Delay

Register Name Old D0 New D0 (line 2) New D0 (last looping) New D0 Content $000000FF

$000000FE $00000000

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

98

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

100

Printed with FinePrint trial version - purchase at www.fineprint.com

68000 Assembly Language Programming

68000 Assembly Language Programming

Example (BNE):
Determine the value in D0 and D1 in the following program?

Example (BHI/BLS):
Determine the value in D0 and D1 in the following program?

1.

MOVE.B

#$00,D0 #$01,D0 #$3F,D0 Again D0,D1


Name Old D0 Old D1 New D0 (Line 2) New D1 (Line 5)

Register Content $00000000 $FFFFFFFFF

MOVE.B SMALLER MOVE.B ADDI.B CMP.B BHI BRA END

#$02,D1 #$04,D0 #1,D1 D1,D0 BIGGER SMALLER


Register Name New D0 New D1 Content

2. Again ADDQ 3. CMP.B 4. BNE 5. MOVE.B

$00000004 $00000005

BIGGER $00000001 $FFFFF3F

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

101

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

103

68000 Assembly Language Programming

68000 Assembly Language Programming

Example (BPL/BMI):
Determine the value in D0 and D1 in the following program?

Example (BGT):
Determine the value in D0 and D1 in the following program?

1.

MOVE.B SUBI BPL ADDI BMI MOVE.B

#$50,D0 #$25,D0 Positive #$5,D0 Negative D0,D1


Name Old D0 Old D1 New D0 (line 2) New D1 (line 6)

Register Content $00000050 $11223344

MOVE.B SMALLER MOVE.B SUBI.B CMP.B BGT BRA END

#$05,D1 #$04,D0 #1,D1 D1,D0 BIGGER SMALLER


Name New D0 New D1

2. Positive 3. 4. Negative 5. 6.

Register Content

$00000004 $00000003

$0000002B $11223304

BIGGER

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

102

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

104

Printed with FinePrint trial version - purchase at www.fineprint.com

68000 Assembly Language Programming

68000 Assembly Language Programming

Example (BSR/BTS):
Determine the value in D0 and D1 in the following program?

MOVE.B #$05,D1 MOVE.B #$04,D0 BSR ADDOP : : ADD.B D1,D0 RTS


Name New D0 New D1

Register Content

ADDOP

$00000009 $00000005

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

105

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

107

68000 Assembly Language Programming

68000 Assembly Language Programming

Example (JSR):
Determine the value in D0 and D1 in the following program?

MOVE.B #$05,D1 MOVE.B #$04,D0 JSR ADDOP : : ADD.B D1,D0 RTR


Name New D0 New D1

Register Content

ADDOP

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

106

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

108

Printed with FinePrint trial version - purchase at www.fineprint.com

Instruction Set (System Control)


ANDI SR AND immediate to SR EORI SR EOR immediate to SR MOVE SR MOVE to/from SR MOVE USP MOVE to/from USP ORI SR OR immediate to SR RESET Reset processor RTE Return from exception STOP Stop processor CHK Check register ILLEGAL Illegal instruction TRAP Trap call TRAPV Trap on overflow ANDI CCR AND immediate to CCR ORI CCR OR immediate to CCR EORI CCR EOR immediate to CCR MOVE CCR MOVE to/from CCR NOP No operation
UNIVERSITI TEKNIKAL MALAYSIA MELAKA

68000 Assembly Language Programming

68000 Assembly Language Programming

Example:
* Experiment 2a : Data transfer * Objective : Lights on LEDs * Switch/ADC-Switch; others off ORG MOVEA.L MOVE.B MOVE.B MOVE.B $400400 #$A00001,A0 #$0,+$E(A0) #$FF,+$6(A0) #$0,+$12(A0) ;memory address for RAM ;base address for PI/T ;set Port B as unidirectional 8-bit ;set all bit Port B as output ;reset all output bit

START

MOVEA.L MOVE.B BSR MOVE.B BSR BRA

VAR,A1 (A1)+,+$12(A0) DELAY (A1)+,+$12(A0) DELAY START

;light on all LEDs ;delay ;light off all LEDs

DELAY DEL1

MOVE.L SUBQ.L BNE RTS DC.B DC.B END

#$5FFFF,D6 #$1,D6 DEL1

;delay subroutine

VAR

#$FF #$00

07/08 Masrullizam Mat Ibrahim

109

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

111

68000 Assembly Language Programming

UNIVERSITI TEKNIKAL MALAYSIA MELAKA

07/08 Masrullizam Mat Ibrahim

110

Printed with FinePrint trial version - purchase at www.fineprint.com

Potrebbero piacerti anche