Title: Computer Systems Introduction to Computer Architecture and Assembly Language Part II
1Computer Systems Introduction to Computer
Architecture and Assembly LanguagePart II
2Assembly Language
- A form of the native language of a computer in
which - - machine code instructions are represented by
mnemonics - e.g., MOVE, ADD, SUB
- - addresses and constants are usually written
in symbolic form - e.g., NEXT, BACK_SP
3MC68000 Assembler
- Valid symbolic name contains up to 8 letters or
numbers. - Name starts with letter.
- TempVa123, TempVa127 are recognized as TempVa12
by assembler
4Files Created by Assembler
Listing File
Source File
Assembler
Editor
Binary File
- Binary file or object file is recognized by
machine. - Listing file contains the information of program
assembling. - If a program written in more than one files,
LINKER is needed to link the object files
together before execution.
5Assembly Language Program
- Two types of statements
- 1. Executable instructions
- 2. Assembler directives
- Executable instruction
- - translated into machine code by assembler
- - tells the machine what to do at execution
6Assembly Language Program
- Assembler directives
- - tell assembler what to do when program
assembled - - are not translated into machine code, they
are non-executable - E.g., EQU, ORG, DC, DS, END
7Assembly Language Program
- Program written in 4 columns
- label instruction operand comment
- - Label begins in column 1
- programmer-defined
- reference to a line
- 50 is 5016, 10 is 00000010, 50 is 5010.
- Longword 32-bit, Word 16-bit, Byte 8-bit.
- A line begins with an in its first column is
a comment ? ignored by the assembler
8SampleProgram
- BACK_SP EQU 08 ASCII code for backspace
- DELETE EQU 01 ASCII code for delete
- CAR_RET EQU 0D ASCII code for carriage
return - ORG 00400 Data origin
- LINE DS.B 64 Reserve 64 bytes for line
buffer - Input a character and store it in a buffer
- ORG 001000 Program origin
- LEA LINE,A2
- NEXT BSR GET_DATA
- CMP.B BACK_SP,D1
- BEQ MOVE_LEFT
- CMP.B DELETE,D1
- BEQ CANCELL
- CMP.B CAR_RET,D1
- BEQ EXIT
- MOVE.B D1,(A2)
- BRA NEXT
- MOVE_LEFT LEA -1(A2),A2
- BRA NEXT
9How Assembler Works
- Two-pass assembler
- Source program scanned twice before producing
the object code - LC Assemblers simulation of PC
- When an assembly program is assembled, LC is
used to keep track of the memory location at
which an instruction would be should that
instruction be executed. - So that machine code can be generated correctly
from assembly code.
10How Assembler Works
- Pass I
- Search source program for symbol definitions and
enter these into symbol table - Pass II
- Use symbol table constructed in Pass I and
op-code table to generate machine code equivalent
to source
11Pass I (Simplified)
START
LC ? 0
Fetch Next Instruction
Y
END?
PASS II
N
Y
Label?
Add Label to Symbol Table w/ LC as its value
Increment LC Accordingly
N
There are exceptions, of course, e.g., EQU.
12Pass II (Simplified)
START
LC ? 0
Fetch Next Instruction
Y
END?
STOP
N
Increment LC Accordingly
Generate Machine Code
Symbol Table Lookup
13 Example
Machine Code
Assembly Code
LC
1 OPT
CRE 2 00000019 A EQU
25 3 00001000 ORG
1000 4 00001000 00000004 M
DS.W 2 5 00001004 00001008 N
DC.L EXIT 6 00001008 2411
EXIT MOVE.L (A1),D2 7 0000100A
139A2000 MOVE.B (A2),(A1,D2)
8 0000100E 06450019 ADDI.W
A,D5 9 00001012 67000008 BEQ
DONE 10 00001016 90B81004
SUB.L N,D0 11 0000101A 60EC
BRA EXIT 12 0000101C 4E722700
DONE STOP 2700 13
00001000 END 1000 Lines
13, Errors 0, Warnings 0. SYMBOL TABLE
INFORMATION Symbol-name Type Value
Decl Cross reference line numbers A
EQU 00000019 2 8. DONE
LABEL 0000101C 12 9. EXIT
LABEL 00001008 6 5, 11. M
LABEL 00001000 4 NOT USED N
LABEL 00001004 5 10.
What we care in the symbol table
14EQU (EQUate) Link a name to a value
Symbol Table
Length EQU 30 Width EQU 25 Area EQU LengthWidth
- The code doesnt need modified, even if the
length and the width changed, - It tells reader how the Area is computed.
- The value in EQU is NOT stored in the data area
of memory ? it replaces the symbol in the code
15ORG (ORiGin)
- Sets up value of location counter (LC)
- LC Assemblers simulation of PC
16DC (Define a Constant) Actually Define
and initialize a variable Qualified by .B, .W,
or .L (byte, word, or longword)
Memory Map
0A
42
001001
001000
00
0A
001003
001002
12
34
001004
001005
41
70
001006
72
69
66
20
38
20
ORG 00001000 FIRST DC.B 10,66 DC.L
0A1234 Date DC.B April 8 1985
DC.L 1,2
31
39
38
35
00
00
001012
00
01
00
00
001016
00
02
- Loads constant into the memory (usually
represented in hexadecimal) - A 16-bit word should not be stored across the
even boundary, e.g. at 1001
Symbol Table
17My perspective on the symbol and its value
Think of a symbol as a bookmark inserted in a
book the value of the bookmark is the page
number its inserted to, NOT the content of the
page.
18Demonstration
Symbol Table
md 1000 001000 0A 42 14 00 00 00 AB CD 4E 72 27
00 00 00 00 00.
The command md in our simulator can be used to
view the memory map
skipped
Machine code of STOP 2700
19DS (Define Storage) Reserves (allocates)
storage location in memory Similar to DC, but
no values stored DC set up values in memory
locations DS reserve memory space for variables
20Example on p68
Memory Map
01000
01004
128 bytes
ORG 1000 FIRST DS.B 4 TABLE DS.B 80 12810
ADRS DS.L 1 VOLTS DS.W 1 LIST DS.W 256 512
bytes 20016 bytes -------------------- Think
of it as bytes4 FIRST bytes128 TABLE int
ADRS short VOLTS short256 LIST
01084
01088
0108A
512 bytes
0128A
Symbol Table
In Java, short is 16 bits and int is 32 bits.
21Example
ORG 001000 TABLE DS.W 256 POINTER_1
DS.L 1 VECTOR_1 DS.L 1 INIT DC.W
0,FFFF ORG 018000 ENTRY LEA ACIAC,A0
MOVE.B SETUP1,(A0)
Memory Map
01000
TABLE
011FF
01200
POINTER_1
01201
01202
01203
01204
VECTOR_1
01205
01206
01207
Symbol Table
01208
INIT
00
01209
00
0120A
FF
0120B
FF
0120C
18000
ENTRY
41
F9
18001
22END End of program