0% found this document useful (0 votes)
39 views

Language Levels: Compiler

High-level languages allow for easier programming and portability across systems compared to assembly language. Assembly language provides a one-to-one mapping to machine language and is specific to the processor. It can be difficult to write, read and understand. A software toolchain is used to translate programs from high-level to machine language, including editors, assemblers, linkers and compilers. Assembly language uses directives like ORG, EQU, DC and DS to define memory locations and constants. Programs are assembled into object files then linked together and loaded as machine code.

Uploaded by

Hatem Mohamed
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Language Levels: Compiler

High-level languages allow for easier programming and portability across systems compared to assembly language. Assembly language provides a one-to-one mapping to machine language and is specific to the processor. It can be difficult to write, read and understand. A software toolchain is used to translate programs from high-level to machine language, including editors, assemblers, linkers and compilers. Assembly language uses directives like ORG, EQU, DC and DS to define memory locations and constants. Programs are assembled into object files then linked together and loaded as machine code.

Uploaded by

Hatem Mohamed
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Language Levels

func(int *v, int k) { High-Level Language


int temp,j; • one to (possibly) many mapping to assembly
for(j=0; j<k ; j++){ • makes programming easier
temp = v[k]; • allows for portability
v[k] = (v[k+1]*2)/5;
v[k+1]=temp; Assembly Language
} • one-to-one mapping to machine language
} • still hard to get things done
• every processor has different assembly
language (non-portable)

Compiler Machine Language


• Difficult to write, read, and understand

func
link A6,-4 1110101010110001110101
move 4(A6),temp(A6) 1010100010101010100001
lea 4(A6),A0 Assembler 0010001010101010101010
adda #2,A0 1010100010101001010101
...
Characteristics of Assembly Language

Assembly language is made up of two types of statements:

• Executable statements:

One of the processor’s valid instructions which can be translated into machine
code by the assembler

• Assembler Directives:

Assembler directives cannot be translated into machine code; they simply tell the
assembler things it needs to know about the program and its environment.

o Link symbolic names to actual values.


o Set up predefined constants
o Allocate storage for memory
o Control the assembly process
68000 Assembly Language Program Structure

*Our first assembly language program.


*This program displays my name on the screen 10 times.

Labels Mnemonic Operand Comment

CR EQU %00001101 ;ASCII carriage return


LF EQU %00001010 ;ASCII line feed

ORG $8000
MOVE.W #10,D6 ;repeat 10x
LOOP MOVEA.L #MESSAGE,A1 ;A1 points to message
TRAP #2 ;send message
SUBQ.W #1,D6 ;decrement count
BNE LOOP ;if not 0, do it again
TRAP #14 ;if 0, return to MON68K
MESSAGE DC.B 'Gary Grewal'
DC.B CR,LF ;begin a new line
DC.B 0 ;end with null byte
END
Assembler Directives

We are going to use the following directives in this course:

<label> EQU <value> Equate


ORG <value> Origin
<label> DC <value> Define Constant
<label> DS <value> Define Storage
END <value> End of assembly language program
and starting address for execution

• In each case, the term <label> indicates a user defined label (symbolic name) that
must start in column 1, and

• <value> indicates a value that must be supplied by the programmer (this may be a
number, or a symbolic name that has a value).
EQU Directive

The EQU assembler directive simply equates a symbolic name to a numeric value. It
does not reserve space in memory!

Format: <label> EQU <value>

Sunday EQU 1 The assembler substitutes the equated value for the
Monday EQU 2 symbolic name; that is,
.
. ADD #Sunday,D0 ⇔ ADD #1,D0
ADD #Sunday,D0

• You could also write:

Sunday EQU 1 The assembler evaluates Sunday + 1 as 1 + 1


Monday EQU Sunday + 1 and assigns the value 2 to the symbolic name
Monday
ORG Directive
The ORG directive sets the memory address of the instructions or data items that follow.

Format: ORG <address>

CODE EQU $8000 ;program starts at $8000


DATA EQU $9000 ;data starts at $9000

ORG CODE
MOVE #100,D0 008000 30
. Operation word
. 008001 3C
. 008002 00
ORG DATA Extension word
. 008003 64
.
009000

• The 68000 reserves the first 1024 bytes of memory for exception vectors.
• The starting address of program memory for the 68KMB is 800016. Therefore, you should
begin your programs with ORG $008000
DC Directive
The DC directive allows you to put a data value in memory at the time that the program
is first loaded. The DC directive takes the suffix .B, .W, and .L, depending on the size
of the value.

Format: <label> DC <value>


009000 01 Val1 = $009000
009001

DATA EQU $9000 009002 00


. 009003 02
. Val2 = $009002
009004 00
ORG DATA
Val1 DC.B 1 009005 03
Val2 DC.W 2,3 009006 47
Me DC.B ‘Gary’ 009007 61
Me = $009006
009008 72
009009 79

Memory Map
DS Directive
The DS directive is used to reserve one or more memory locations. The DS directive
takes a suffix .B, .W, and .L and an operand specifying the number of such quantities to
reserve.

Format: <label> DS <value>


009000
009001
Result = $009000
009002
009003
DATA EQU $9000 009004
.
009005
.
ORG DATA 009006 Table = $009004
Result DS.L 1
Table DS.B 9 00900C
Point DS.W 1
00900D
00900E
Point = $00900E
00900F
END Directive

The END directive indicates that the end of the code has been reached.

• Optionally specifies the place at which to start execution.

Format: END <start address>

EQU $8000
Start MOVE #1,D2
.
.
.
.
.
.
END Start
The Software Used When Creating Assembly Programs

Listing File
(program1.lst)
EDITOR ASSEMBLER

Binary File LINKER


(program1.obj)

program1.src

S-Record
(final.hex)

download to 68KMB
and execute
Example of a Simple Assembly Language
Program

The following program adds together two 8-bit numbers stored in the memory
locations called VALUE1 and VALUE2, and stores the sum in the memory
location called RESULT.

The source program is called ADD.SRC (The file extension .SRC is required by
the 68000 assemble.)

ORG $8000 ;start of program area


MYPROG MOVE.B VALUE1,D0
MOVE.B VALUE2,D1
ADD.B D0,D1
MOVE.B D1,RESULT
TRAP #14 ;stop execution

ORG $9000 ;start of data area


VALUE1 DC.B 12 ;store 12 in memory
VALUE2 DC.B 24 ;store 24 in memory
RESULT DS.B 1 ;reserve byte for result

END MYPROG ;end of program and


;entry point

To assemble ADD.SRC:

C:\68KMB\A68K ADD.SRC ADD.LST ADD.OBJ


ADD.SRC ⇒ ADD.LIS

Assembling ADD.SRC produces a text file, called ADD.LIS, that contains the original assembly-language
program after assembly, plus any error messages. The contents of ADD.LIS are shown below:

1 00008000 ORG $8000 ;start of program area


2 00008000 103900009000 MYPROG MOVE.B VALUE1,D0
3 00008006 123900009001 MOVE.B VALUE2,D1
4 0000800C D200 ADD.B D0,D1
5 0000800E 13C100009002 MOVE.B D1,RESULT
6 00008014 4E4E TRAP #14 ;stop execution
7
8 00009000 ORG $9000
9 00009000 0C VALUE1 DC.B 12 ;store 12 in memory
10 00009001 18 VALUE2 DC.B 24 ;store 24 in memory
11 00009002 00000001 RESULT DS.B 1 ;reserve byte for result
12
13 00008000 END MYPROG

Lines: 13, Errors: 0, Warnings: 0.


ADD.SRC ⇒ ADD.OBJ ⇒ ADD.HEX

Assembling ADD.SRC also produces a binary machine-code file, called


ADD.OBJ, that can be executed on the 68KMB.

• This file, however, must be converted to Motorola-S records as shown


below:

C:\68KMB\XLINK 68K ADD.OBJ \O=ADD.HEX

• The contents of ADD.HEX are:

S0060000616464D0
S1138000103900009000123900009001D20013C111
S1098010000090024E4E38
S10590000C1846
S90380007C

S1 05 9000 0C18 46

B9

Data Bytes ⊕ 46
Checksum FF
LoadAddress
Byte Count Checksum
Record Type Calculation

Field Format
Program Execution
The following dump of a session was produced using a 68000 assembler.
The output of the simulator consists largely of the contents of the 68000’s
registers after each instruction is executed.

>md $8000

008000 10 39 00 00 90 00 12 39 00 00 90 01 D2 00 13 C1
008010 00 00 90 02 4E 4E 30 3C 00 64 00 00 00 00 00 00
008020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

>md $9000

009000 0C 18 00 00 00 00 00 00 00 00 00 00 00 00 00 00
009010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

>md $8000 –di (called DI $8000 on 68KMB)

008000: MOVE.B $00009000,D0


008006: MOVE.B $00009001,D1
00800C: ADD.B D0,D1
00800E: MOVE.B D1,$00009002
008014: TRAP #14
008016: ORI.B #0,D0
00801A: ORI.B #0,D0
00801E: ORI.B #0,D0
008022: ORI.B #0,D0
008026: ORI.B #0,D0
00802A: ORI.B #0,D0
00802E: ORI.B #0,D0
008032: ORI.B #0,D0
008036: ORI.B #0,D0
00803A: ORI.B #0,D0
00803E: ORI.B #0,D0
>df (called RD on 68KMB)
PC=008000 SR=2000 SS=00A00000 US=00000000 X=0
A0=00000000 A1=00000000 A2=00000000 A3=00000000 N=0
A4=00000000 A5=00000000 A6=00000000 A7=00A00000 Z=0
D0=00000000 D1=00000000 D2=00000000 D3=00000000 V=0
D4=00000000 D5=00000000 D6=00000000 D7=00000000 C=0
---------->MOVE.B $00009000,D0

>tr
PC=008006 SR=2000 SS=00A00000 US=00000000 X=0
A0=00000000 A1=00000000 A2=00000000 A3=00000000 N=0
A4=00000000 A5=00000000 A6=00000000 A7=00A00000 Z=0
D0=0000000C D1=00000000 D2=00000000 D3=00000000 V=0
D4=00000000 D5=00000000 D6=00000000 D7=00000000 C=0
---------->MOVE.B $00009001,D1

Trace>
PC=00800C SR=2000 SS=009FFFFA US=00000000 X=0
A0=00000000 A1=00000000 A2=00000000 A3=00000000 N=0
A4=00000000 A5=00000000 A6=00000000 A7=009FFFFA Z=0
D0=0000000C D1=00000018 D2=00000000 D3=00000000 V=0
D4=00000000 D5=00000000 D6=00000000 D7=00000000 C=0
---------->ADD.B D0,D1

Trace>
PC=00800E SR=2000 SS=009FFFFA US=00000000 X=0
A0=00000000 A1=00000000 A2=00000000 A3=00000000 N=0
A4=00000000 A5=00000000 A6=00000000 A7=009FFFFA Z=0
D0=0000000C D1=00000024 D2=00000000 D3=00000000 V=0
D4=00000000 D5=00000000 D6=00000000 D7=00000000 C=0
---------->MOVE.B D1,$00009002

>md 9000

009000 0C 18 24 00 00 00 00 00 00 00 00 00 00 00 00 00

TRACE>
PC=008014 SR=2000 SS=009FFFFA US=00000000 X=0
A0=00000000 A1=00000000 A2=00000000 A3=00000000 N=0
A4=00000000 A5=00000000 A6=00000000 A7=009FFFFA Z=0
D0=0000000C D1=00000024 D2=00000000 D3=00000000 V=0
D4=00000000 D5=00000000 D6=00000000 D7=00000000 C=0
---------->TRAP #14
WARNING!

The previous program (to add together two 8-bit numbers stored in the memory
locations called VALUE1 and VALUE2, and store the sum in the memory
location called RESULT) will not assemble using A68K.

This assembler requires you to place greater-than signs (>) in front of the labels
VALUE1, VALUE2, and RESULT as shown below:

ORG $8000 ;start of program area


MYPROG MOVE.B >VALUE1,D0
MOVE.B >VALUE2,D1
ADD.B D0,D1
MOVE.B D1,>RESULT
TRAP #14 ;stop execution

ORG $9000 ;start of data area


VALUE1 DC.B 12 ;store 12 in memory
VALUE2 DC.B 24 ;store 24 in memory
RESULT DS.B 1 ;reserve byte for result

END MYPROG ;end of program and


;entry point

As this requirement it is not generally true of other assemblers, I will not be


using the > sign in most of the code that I show you in class.

You might also like