Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
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).
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
STNEMMOC
4
SDNAREPO
EDOCPO
LE BAL
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
Loader
A program takes care of loading program into memory. Usually linker and loader are combined into a single program called a link-loader.
Example files
.asm
6
UNIVERSITI TEKNIKAL MALAYSIA MELAKA
Addressing Mode
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
11
Move operands (data) among memory locations and registers Addition, subtraction, multiply, divide,
Logical
AND, NOT, OR, XOR,
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
10
12
13
15
14
16
17
19
18
20
21
23
22
24
Immediate data
25
27
26
28
10
000
000
111
100
29
31
10
000
000
111
100
Instruction format = 0010 0000 0011 1100 = $203C Machine code = 203C 00000012
30
32
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
MOVE.W
#$1F36,D2
0000FFFF 00001F36
Initial D6 Initial D2
Load D6
MOVE.B
#$38,D3
Old D3 New D3
1234ABCD 1234AB38
MOVE.L D0,D2
33
35
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
34
36
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)+
MOVEA.W #$9F00,A5
Old A5 New A5
4444FFFF FFFF9F00
MOVEA.B #$3C7E,A0
Old A0 New A0
22DD33CC ?
37
39
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
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
Bit 4 1 1 0
MOTOR DRIVER
38
40
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)
41
43
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
42
44
45
47
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
MOVEQ #$7B,D6
46
48
Pseudo-Opcode
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
49
51
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
50
52
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
53
55
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
54
56
Example
[D2] = 12345678, [D3] = 5F02C332. What is the result of ADD.B D2,D3?
57
59
[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
New D2
58
60
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
MULU.W D4,D5 Name Old D4 Old D5 Content 0000000A 00000064
[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
MULU.W D4,D5
Content 03059A02
New D2
61
63
62
64
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
65
67
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
66
68
69
71
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
70
72
73
75
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
000000C0
74
76
Example:
What is the result of OR.L D3,D4 ?
[D3] = FFFFFC18, [D4] = 000186A0.
FFFFFC18 FFFFFEB8
22445591
77
79
78
80
81
83
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
A2B457C1
82
84
85
87
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
1 1 0 0 1 1 1 1
86
88
89
91
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
Content
1 1 0 0 1 1 1 1
90
UNIVERSITI TEKNIKAL MALAYSIA MELAKA
1 0 1 1
92
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
93
BHI, BLS, BCC, BCS, BNE, BEQ, BVC, BVS, BPL, BMI, BGE, BLT, BGT & BLE.
BRA Branch always BSR Branch to subroutine JMP Jump JSR Jump to subroutine RTR Return and store RTS Return from subroutine
94
96
Example (BCC/BCS):
What is the value in D0 in the following program?
1.
2. Loop1 3. 4. 5. Loop2 6. 7. 8. Loop3
Register Name Old D0 New D0 (line 2) New D0 (line 5) New D0 Content $000000F4
$0000003D $000000E8
97
99
Example (BEQ):
What is the value in D0 in the following program?
1.
2. Delay 3. 4. 5. Finish
Register Name Old D0 New D0 (line 2) New D0 (last looping) New D0 Content $000000FF
$000000FE $00000000
98
100
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
$00000004 $00000005
101
103
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.
2. Positive 3. 4. Negative 5. 6.
Register Content
$00000004 $00000003
$0000002B $11223304
BIGGER
102
104
Example (BSR/BTS):
Determine the value in D0 and D1 in the following program?
Register Content
ADDOP
$00000009 $00000005
105
107
Example (JSR):
Determine the value in D0 and D1 in the following program?
Register Content
ADDOP
106
108
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
DELAY DEL1
;delay subroutine
VAR
#$FF #$00
109
111
110