device options: select micro- controller core (here...

14
- Compiler, assembler, linker - The build process in detail - Compiler options - Linker options - Warnings and error messages - Example: Keil C166 projects - Source level debugging using a micro- controller simulator - Download into target RAM - Source level debugging using a target Monitor Compilation process – fundamentals 3 topics lecture week Compilation Process – Fundamentals MP3-1 Compilation process example: flashing LED Compilation Process – Fundamentals MP3-2 Compilation process example: flashing LED Source files: - flash.c … the program - traps.c … interrupts (unused) - start167.a66 μC initializations Build process: - compiling flash.c - assembling Start167.a66 - linking both objects to ‘flash’ and producing EEPROM ‘hex’ file Compilation Process – Fundamentals MP3-3 Device options: Select micro- controller core (here: C167CR- LM) for this project Compilation process example: flashing LED Compilation Process – Fundamentals MP3-4

Upload: hathien

Post on 18-Jul-2018

256 views

Category:

Documents


0 download

TRANSCRIPT

-C

om

pil

er, as

sem

ble

r, lin

ker

-T

he

build p

roce

ss in d

etai

l

-C

om

pil

er o

ptions

-L

inker

options

-W

arnin

gs

and e

rror

mes

sages

-E

xam

ple

: K

eilC

166 p

roje

cts

-Sourc

e le

vel

deb

uggin

g u

sing a

mic

ro-

contr

oller

sim

ula

tor

-D

ow

nlo

ad into

tar

get

RA

M

-Sourc

e le

vel

deb

uggin

g u

sing a

tar

get

Monit

or

Com

pilat

ion

pro

cess

fundam

enta

ls

3

topics

lecture

week

Compilation Process –Fundamentals

MP

3-1

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

Compilation Process –Fundamentals

MP

3-2

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

Sourc

e fi

les:

-fl

ash.c

… the

pro

gra

m

-tr

aps.

c…

inte

rrupts

(unuse

d)

-st

art1

67.a

66

… µ

C init

iali

zations

Buil

d p

roce

ss:

-co

mpil

ing f

lash

.c

-as

sem

bli

ng S

tart

167.a

66

-li

nkin

g b

oth

obje

cts

to ‘

flas

h’

and

pro

duci

ng E

EP

RO

M ‘

hex

’ fi

le

Compilation Process –Fundamentals

MP

3-3

Dev

ice

options:

Sel

ect

mic

ro-

contr

oll

er

core

(her

e:

C167C

R-

LM

) fo

r

this

pro

ject

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

Compilation Process –Fundamentals

MP

3-4

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

Tar

get

options:

CP

U,

exte

rnal

mem

ory

(CO

DE

at

0x4000,

DA

TA

at

0x8000),

etc.

Compilation Process –Fundamentals

MP

3-5

Outp

ut

options:

Confi

gure

exec

uta

ble

outp

ut fi

le

(flash

) an

d

the

dow

n-

load

able

‘hex

’ fi

le

(flash.h86)

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

Compilation Process –Fundamentals

MP

3-6

Lis

ting

options:

Spec

ify

det

ail of

info

rmat

ion

wit

hin

the

list

ing f

iles

of

com

pil

er,

asse

mble

r,

linker

, …

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

Compilation Process –Fundamentals

MP

3-7

Com

pil

er

options:

Def

ine

mac

ros

(e.g

.

MO

NIT

OR

),

level

of

feed

bac

k

(war

nin

gs,

deb

ug info

),

etc.

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

Compilation Process –Fundamentals

MP

3-8

Ass

emble

r

options:

Mem

ory

model

(her

e:

SM

AL

L –

nea

r co

de,

nea

r dat

a),

CP

U d

etai

ls

(MO

D167),

etc.

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

Compilation Process –Fundamentals

MP

3-9

Lin

ker

and

Loca

tor

options:

Spec

ify

mem

ory

map

of

the

exec

uta

ble

(RA

M,

RO

M, et

c.)

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

Compilation Process –Fundamentals

MP

3-1

0

Deb

uggin

g:

Simulator

(PC

bas

ed)

or Monitor

(dow

nlo

ad

to tar

get

boar

d,

deb

uggin

g

via

ser

ial

inte

rfac

e

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

Compilation Process –Fundamentals

MP

3-1

1

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

#include <reg167.h>

void wait (void) { } /* wait function (empty) */

void main (void) {

unsigned int

i; /* delay variable */

DP2 = 0x00FF; /* bits 0 –

7 : outputs */

ODP2 = 0x0000; /* output driver : push/pull */

while (1) { /* loop forever */

P2 |= 0x0001; /* switch on LED (P2.0

= 1) */

for (i = 0; i < 10000; i++) wait(); /* delay for 10000 counts */

P2 &= ~0x0001; /* switch off LED (P2.0 = 0) */

for (i = 0; i < 10000; i++) wait(); /* delay for 10000 counts */

} /* while(1) */

} /* main */

Compilation Process –Fundamentals

MP

3-1

2

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

#include <reg167.h>

void wait (void) { } /* wait function (empty) */

void main (void) {

unsigned int

i; /* delay variable */

DP2

= 0x00FF; /* bits 0 –

7 : outputs */

ODP2

= 0x0000; /* output driver : push/pull

*/

(…)

}

Mac

ro d

efin

itio

ns

of special function registers

(SF

R)

such

as

DP

2 (

dat

a dir

ection, port

2)

or

OD

P2

(outp

ut dri

ver

, port

2)

Compilation Process –Fundamentals

MP

3-1

3

#include <reg167.h>

void wait (void) { } /* wait function (empty) */

void main (void) {

unsigned int

i; /* delay variable */

DP2

= 0x00FF; /* bits 0 –

7 : outputs */

ODP2

= 0x0000; /* output driver : push/pull

*/

(…)

}

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

Em

pty

funct

ion ‘

wai

t’; ca

llin

g u

pon w

ait does

n’t

do a

nyth

ing b

ut w

aste

a lit

tle

bit o

f C

PU

tim

e. T

his

is a

n e

asy w

ay o

f sl

ow

ing d

ow

n the

pro

cess

or

Compilation Process –Fundamentals

MP

3-1

4

#include <reg167.h>

void wait (void) { } /* wait function (empty) */

voidmain (void)

{

unsigned int

i; /* delay variable */

DP2

= 0x00FF; /* bits 0 –

7 : outputs */

ODP2

= 0x0000; /* output driver : push/pull

*/

(…)

}

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

Mai

n p

rogra

m w

ith n

o c

all-

up p

aram

eter

s [ (void)

… o

n the

right-

han

d s

ide

of main ]

and n

o r

eturn

val

ues

[ void

… o

n the

left

-han

d s

ide

of main ].

Compilation Process –Fundamentals

MP

3-1

5

#include <reg167.h>

void wait (void) { } /* wait function (empty) */

void main (void) {

unsigned int

i; /* delay variable */

DP2

= 0x00FF; /* bits 0 –

7 : outputs */

ODP2

= 0x0000; /* output driver : push/pull

*/

(…)

}

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

Var

iable

, lo

cal to

main

. T

his

is

a 16-b

it u

nsi

gned

inte

ger

var

iable

whic

h c

an s

tore

dat

a val

ues

rangin

g f

rom

0 to 2

16-1

= 6

5535 =

0xF

FF

F (

hex

)

Compilation Process –Fundamentals

MP

3-1

6

#include <reg167.h>

void wait (void) { } /* wait function (empty) */

void main (void) {

unsigned int

i; /* delay variable */

DP2

= 0x00FF; /* bits 0 –

7 : outputs */

ODP2

= 0x0000; /* output driver : push/pull

*/

(…)

}

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

Ass

ignm

ent of

val

ues

0x00F

F (

= b

inar

y p

atte

rn

0000.0

000.1

111.1

111)

and 0

x0000 (

= 0

) to

spec

ial

funct

ion r

egis

ters

DP

2an

d O

DP

2, re

spec

tivel

y

Compilation Process –Fundamentals

MP

3-1

7

#include <reg167.h>

void wait (void) { } /* wait function (empty) */

void main (void) {

unsigned int

i; /* delay variable */

DP2

= 0x00FF; /* bits 0 –

7 : outputs */

ODP2

= 0x0000; /* output driver : push/pull

*/

(…)

}

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

This

pro

gra

ms

bit

s 0 –

7 o

f port

2 a

s outp

uts

(D

P2

= 0

000.0

000.1

111.1

111)

and s

elec

ts the

push

/pull

outp

ut dri

ver

of

port

2 (

OD

P2 =

0x0000)

Compilation Process –Fundamentals

MP

3-1

8

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

-E

ach d

igital

outp

ut ca

n b

e co

nfi

gure

d to b

e dri

ven

by a

push

/pull a

mpli

fier

or

an o

pen

-dra

in tra

nsi

stor

-P

ush

/pull a

mpli

fier

s ca

n d

rive

the

outp

ut to

logic

al

hig

h o

r lo

gic

al low

; open

-dra

in o

utp

uts

can

only

pull the

outp

ut to

gro

und (

GN

D)

or

leav

e it

in a

floating

stat

e (h

igh im

ped

ance

, Hi-Z

)

Compilation Process –Fundamentals

MP

3-1

9

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

-Im

ple

men

ted u

sing b

ipola

r tr

ansi

stors

, push

/pull

tech

nolo

gy is

also

ref

erre

d to a

s Transistor-

Transistor Logic (TTL);

the

equiv

alen

t fi

eld e

ffec

t

tran

sist

or

(FE

T)

circ

uit

ry is

called

Complementary

Metal-Oxide-Silicon logic (CMOS)

-O

pen

-dra

in (

open

-coll

ecto

r) tec

hnolo

gy r

equir

es a

n

exte

rnal

pull-up resistor

to a

llow

the

outp

ut to

attai

n

a lo

gic

al h

igh lev

el; open

-dra

in c

ircu

its

are

use

ful

when

mult

iple

outp

uts

are

to b

e ti

ed toget

her

in

par

alle

l to

im

ple

men

t a

wir

ed-A

ND

funct

ion

Compilation Process –Fundamentals

MP

3-2

0

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

(…)

while (1) { /* loop forever */

P2 |= 0x0001; /* switch on LED (P2.0

= 1) */

for (i = 0; i < 10000; i++) wait(); /* delay for 10000 counts */

P2 &= ~0x0001; /* switch off LED (P2.0 = 0) */

for (i = 0; i < 10000; i++) wait(); /* delay for 10000 counts */

} /* while(1) */

} /* main */

Em

bed

ded

pro

gra

ms

nev

er e

nd; th

is is

usu

ally

achie

ved

wit

h a

n e

ndle

ss loop, e.

g. while(1){…}

or

for(;;){ …

}–

both

const

ruct

s ar

e unconditional

Compilation Process –Fundamentals

MP

3-2

1

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

(…)

while (1) { /* loop forever */

P2 |= 0x0001; /* switch on LED (P2.0

= 1) */

for (i = 0; i < 10000; i++) wait(); /* delay for 10000 counts */

P2 &= ~0x0001; /* switch off LED (P2.0 = 0) */

for (i = 0; i < 10000; i++) wait(); /* delay for 10000 counts */

} /* while(1) */

} /* main */

P2 |= 0x0001

is e

quiv

alen

t to

P2 = P2| 0x0001.

This

com

bin

es the

conte

nts

of

port

2 w

ith the

mas

k

0x0001 (

logic

al O

R);

eff

ecti

vel

y this

lig

hts

the

LE

D c

onnec

ted to b

it 0

of

port

2 (

P2.0

= 1

)

Compilation Process –Fundamentals

MP

3-2

2

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

(…)

while (1) { /* loop forever */

P2 |= 0x0001; /* switch on LED (P2.0

= 1) */

for (i = 0; i < 10000; i++) wait(); /* delay for 10000 counts */

P2 &= ~0x0001; /* switch off LED (P2.0 = 0) */

for (i = 0; i < 10000; i++) wait(); /* delay for 10000 counts */

} /* while(1) */

} /* main */

Dum

my f

unct

ion c

all to

em

pty

funct

ion wait

. T

his

was

tes

som

e C

PU

tim

e. D

oin

g this

insi

de

a lo

op is

a si

mple

way

of

pro

duci

ng a

short

tim

e del

ay

Compilation Process –Fundamentals

MP

3-2

3

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

(…)

while (1) { /* loop forever */

P2 |= 0x0001; /* switch on LED (P2.0

= 1) */

for (i = 0; i < 10000; i++) wait(); /* delay for 10000 counts */

P2 &= ~0x0001; /* switch off LED (P2.0 = 0) */

for (i = 0; i < 10000; i++) wait(); /* delay for 10000 counts */

} /* while(1) */

} /* main */

P2 &= ~0x0001

is s

hort

for P2 = P2&0xFFFE

.

The

mas

k ~0x0001(NOT0000.0000.0000.0001)

expan

ds

to 1111.1111.1111.1110 = 0xFFFE

. T

he

AND

oper

atio

n thus

clea

rs b

it 0

of

port

2 (

LE

D o

ff)

Compilation Process –Fundamentals

MP

3-2

4

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

(…)

while (1) { /* loop forever */

P2 |= 0x0001; /* switch on LED (P2.0

= 1) */

for (i = 0; i < 10000; i++) wait(); /* delay for 10000 counts */

P2 &= ~0x0001; /* switch off LED (P2.0 = 0) */

for (i = 0; i < 10000; i++) wait(); /* delay for 10000 counts */

} /* while(1) */

} /* main */

More

tim

e w

asti

ng to m

ake

the off-phase o

f th

e

LE

D a

s lo

ng a

s th

e on-phase

. A

ltoget

her

, th

e

pro

gra

m p

roduce

s a

slow

ly f

lash

ing L

ED

Compilation Process –Fundamentals

MP

3-2

5

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

-C

om

pil

atio

n o

f th

is p

rogra

m u

sing the

KE

IL tool

chai

n (µ

Vis

ion)

pro

duce

s th

e fo

llow

ing f

iles

:

-fl

ash.lst

asse

mble

r li

stin

g o

f flash.c

-fl

ash.o

bj

obje

ct f

ile

(mac

hin

e co

de)

-S

tart

167.lst

asse

mble

r li

stin

g o

f Start167.a66

-S

tart

167.o

bj

obje

ct f

ile

(mac

hin

e co

de)

-fl

ash.lnp

linker

com

man

d f

ile

-fl

ash.m

66

det

aile

d m

emory

map

-fl

ash

linked

exec

uta

ble

module

-fl

ash.h

86

EE

PR

OM

ver

sion o

f flash

Compilation Process –Fundamentals

MP

3-2

6

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

-O

ther

com

pil

ers

(e.g

. G

NU

gcc

) m

ight pro

duce

a

slig

htly d

iffe

rent se

t of

outp

ut fi

les

-U

nder

stan

din

g the

purp

ose

and c

onte

nts

of

thes

e

file

s is

im

per

ativ

e to

the

succ

essf

ul dev

elopm

ent of

embed

ded

mic

roco

ntr

oll

er p

rogra

ms

-T

he

tools

use

d to p

roduce

thes

e fi

les

can b

e ca

lled

upon f

rom

wit

hin

the

KE

IL inte

gra

ted d

evel

opm

ent

envir

onm

ent (I

DE

) or

from

a s

hel

l (e

.g. M

SD

OS

com

man

d lin

e pro

mpt, M

AT

LA

B c

om

man

d lin

e

pro

mpt, U

NIX

/Lin

ux ter

min

al, et

c.)

Compilation Process –Fundamentals

MP

3-2

7

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

-O

n P

Cs

the

KE

IL tool ch

ain incl

udes

:

-C

166.e

xe

AN

SI-

C c

ross

-com

piler

(C

166)

-E

C166.e

xe

embed

ded

C+

+ c

ross

-com

pil

er

-L

IB166.e

xe

libra

ry m

anag

er u

tili

ty

-O

H166.e

xe

obje

ct to h

ex-f

ile

conver

ter

-L

166.e

xe

linker

and loca

tor

-A

166.e

xe

mac

ro a

ssem

ble

r (C

166)

-N

ot al

l of

thes

e pro

gra

ms

are

use

d e

ver

y tim

e a

pro

gra

m is

com

pil

ed (

built)

Compilation Process –Fundamentals

MP

3-2

8

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

-T

he

flas

hin

g L

ED

exam

ple

mak

es u

se o

f…

-C

166

… to c

om

pil

e th

e C

-sourc

e co

de

into

asse

mble

r co

de

for

the

C167 µ

C

-A

166

… to turn

the

asse

mble

r co

de

into

relo

cata

ble

mac

hin

e co

de

(obje

ct f

ile)

-L

166

… to lin

k a

ll o

bje

ct f

iles

(fl

ash.o

bj,

Sta

rt167.o

bj)

to a

n a

bso

lute

exec

uta

ble

-O

H166

… to p

roduce

an I

NT

EL

hex

-86 f

ile

whic

h c

an b

e w

ritt

en to a

n E

EP

RO

M

usi

ng a

FL

AS

H/E

EP

RO

M b

urn

er

Compilation Process –Fundamentals

MP

3-2

9

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

C166 COMPILER V5.03, FLASH

10/16/2004 17:52:41 PAGE 1

C166 COMPILER V5.03, COMPILATION OF MODULE FLASH

OBJECT MODULE PLACED IN flash.OBJ

COMPILER INVOKED BY: F:\Keil\C166\BIN\C166.EXE flash.c

MOD167 DEFINE(MONITOR) DEBUG CODE

SYMBOLS PAGELENGTH(18)

stmt lvl

source

1 #include <reg167.h>

2

3 void wait (void) { } /* wait function (empty) */

4

5 void main (void) {

6 1

7 1 unsigned int

i; /* delay variable */

(…)

-L

isti

ng f

ile flash.lst

:

Nam

e of

the

outp

ut fi

le (

flas

h.o

bj)

Compilation Process –Fundamentals

MP

3-3

0

C166 COMPILER V5.03, FLASH

10/16/2004 17:52:41 PAGE 1

C166 COMPILER V5.03, COMPILATION OF MODULE FLASH

OBJECT MODULE PLACED IN flash.OBJ

COMPILER INVOKED BY: F:\Keil\C166\BIN\C166.EXE flash.c

MOD167 DEFINE(MONITOR) DEBUG CODE

SYMBOLS PAGELENGTH(18)

stmt lvl

source

1 #include <reg167.h>

2

3 void wait (void) { } /* wait function (empty) */

4

5 void main (void) {

6 1

7 1 unsigned int

i; /* delay variable */

(…)

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

-L

isti

ng f

ile flash.lst

:

Com

pil

er invoca

tion c

om

man

d lin

e

Compilation Process –Fundamentals

MP

3-3

1

C166 COMPILER V5.03, FLASH

10/16/2004 17:52:41 PAGE 1

C166 COMPILER V5.03, COMPILATION OF MODULE FLASH

OBJECT MODULE PLACED IN flash.OBJ

COMPILER INVOKED BY: F:\Keil\C166\BIN\C166.EXE flash.c

MOD167 DEFINE(MONITOR) DEBUG CODE

SYMBOLS PAGELENGTH(18)

stmt lvl

source

1 #include <reg167.h>

2

3 void wait (void) { } /* wait function (empty) */

4

5 void main (void) {

6 1

7 1 unsigned int

i; /* delay variable */

(…)

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

-L

isti

ng f

ile flash.lst

:

Sourc

e co

de

list

ing lin

e num

ber

s an

d s

ourc

e co

de

Compilation Process –Fundamentals

MP

3-3

2

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

C166 COMPILER V5.03, FLASH

10/16/2004 17:52:41 PAGE 3

ASSEMBLY LISTING OF GENERATED OBJECT CODE

; FUNCTION wait

(BEGIN RMASK = @0x8000)

; SOURCE LINE # 3

0000 CB00

RET

; FUNCTION wait

(END RMASK = @0x8000)

; FUNCTION main (BEGIN RMASK = @0x4020)

; SOURCE LINE # 5

; SOURCE LINE # 10

0002 E6E1FF00 MOV DP2,#0FFH

; SOURCE LINE # 11

0006 D180 EXTR #01H

0008 E6E10000 MOV ODP2,#00H

; SOURCE LINE # 13

Em

pty

funct

ion wait

is im

ple

men

ted a

s a

sim

ple

retu

rn inst

ruct

ion (RET

, m

achin

e co

de:

0xCB).

A

zero-byte

has

bee

n inse

rted

for word alignment

Compilation Process –Fundamentals

MP

3-3

3

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

C166 COMPILER V5.03, FLASH

10/16/2004 17:52:41 PAGE 3

ASSEMBLY LISTING OF GENERATED OBJECT CODE

; FUNCTION wait (BEGIN RMASK = @0x8000)

; SOURCE LINE # 3

0000 CB00

RET

; FUNCTION wait (END RMASK = @0x8000)

; FUNCTION main

(BEGIN RMASK = @0x4020)

; SOURCE LINE # 5

; SOURCE LINE # 10

0002

E6E1FF00 MOV DP2,#0FFH

; SOURCE LINE # 11

0006 D180 EXTR #01H

0008 E6E10000 MOV ODP2,#00H

; SOURCE LINE # 13

Funct

ion main

beg

ins

at

relo

cata

ble

addre

ss 0

002

(foll

ow

ing f

unct

ion wait

).

Fir

st inst

ruct

ion:

‘port

2 is

outp

ut’

(DP2 = 0xFF)

Compilation Process –Fundamentals

MP

3-3

4

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

000C

?C0003:

; SOURCE LINE # 15

000C 76E00100 OR P2,#01H

; SOURCE LINE # 16

0010 E005 MOV R5,#00H

;----

Variable 'i' assigned to Register 'R5' ----

0012 ?C0008:

0012 BBF6 CALLR wait

0014 86F50F27 CMPI1 R5,#0270FH

0018 8DFC JMPR cc_ULT,?C0008

001A ?C0006:

; SOURCE LINE # 18

001A 66E0FEFF AND P2,#0FFFEH

; SOURCE LINE # 19

001E E005 MOV R5,#00H

0020 ?C0013:

SC166 COMPILER V5.03, FLASH

10/16/2004 17:52:41 PAGE 5

0020 BBEF CALLR wait

0022 86F50F27 CMPI1 R5,#0270FH

0026 8DFC JMPR cc_ULT,?C0013

0028 ?C0011:

; SOURCE LINE # 21

0028 0DF1

JMPR cc_UC,?C0003

; FUNCTION main (END RMASK = @0x4020)

while(1) { … }

loop, U

nC

onditio

nal

jum

p to ?C0003

Loca

l var

iable

,

kep

t in

R5 f

or

fast

acc

ess

Sw

itch

LE

D o

n

and o

ff (set/

clear bit P2.0)

Compilation Process –Fundamentals

MP

3-3

5

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

A166 MACRO ASSEMBLER START167

10/16/2004 17:52:42 PAGE 38

618

619

620 ?C_RESET PROC TASK C_STARTUP INTNO RESET = 0

621 ?C_STARTUP: LABEL NEAR

622

623

624 $IF (WATCHDOG = 0)

00000000 A55AA5A5 625 DISWDT

; Disable watchdog

; timer

626 $ENDIF

627

635 $ENDIF

636

0010 637 BCON0L SET (_MTTC0 << 5) OR (_RWDC0 << 4)

001E 638 BCON0L SET BCON0L

OR ((NOT _MCTC0) AND 0FH)

001E 639 BCON0L SET BCON0L

AND (NOT (_RDYEN0 << 3))

001E 640 BCON0L SET BCON0L

OR (_RDY_AS0 << 3)

Sta

rtup

file

Start167.a66

initia

lize

s th

e pri

nci

pal

syst

em c

onfi

gura

tion r

egis

ters

and d

efin

es the

stac

k;

this

code

is c

alle

d u

pon R

ES

ET

and b

efore

main

.

Compilation Process –Fundamentals

MP

3-3

6

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

(…)

861 ;--------------------------------------------------------

862 ;

863 ; The following code is necessary to set RAM variables to

864 ; 0 at start-up (RESET) of the C application program.

865 ;

(…)

975 ;--------------------------------------------------------

976 ;

977 ; The following code is necessary, if the application

978 ; program contains initialized

variables at file level.

979 ;

(…)

0000012A FA??????

E 1104 JMP FAR main

Start167 c

lear

s un-i

nit

iali

zed v

aria

ble

s (B

SS

) an

d

moves

initia

lise

d v

aria

ble

s fr

om

EE

PR

OM

to R

AM

;

then

main

is c

alle

d (

abso

lute

addre

ssst

ill unknow

n)

Compilation Process –Fundamentals

MP

3-3

7

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

"flash.obj",

"Start167.obj"

TO "flash"

RESERVE (8H-0BH, 0ACH-0AFH)

CLASSES

(ICODE (0x4000-0x7FFF), NCODE (0x4000-0x7FFF),

FCONST

(0x4000-0x7FFF), HCONST (0x4000-0x7FFF),

XCONST (0x4000-0x7FFF), NCONST

(0x4000-0x7FFF),

NDATA

(0x8000-0xBFFF), NDATA0

(0x8000-0xBFFF),

SDATA (0xE000-0xE7FF, 0xF600-0xFDFF), SDATA0 (0xE000-0xE7FF, 0xF600-0xFDFF),

IDATA (0xF600-0xFDFF), IDATA0 (0xF600-0xFDFF),

FDATA (0x8000-0xBFFF), FDATA0 (0x8000-0xBFFF),

HDATA (0x8000-0xBFFF), HDATA0 (0x8000-0xBFFF),

XDATA (0x8000-0xBFFF), XDATA0 (0x8000-0xBFFF))

CINITTAB (0x4000-0x7FFF)

Lin

ker

scr

ipt flash.lnp

def

ines

the

linker

options;

obje

cts flash.objan

d Start167.objar

e co

mbin

ed

(lin

ked

) to

outp

ut fi

le flash

. A

ll a

bso

lute

sym

bols

are

reso

lved

and m

apped

to the

spec

ifie

d a

ddre

sses

ranges

(C

ON

ST

= c

ode,

DA

TA

= v

aria

ble

s)

Compilation Process –Fundamentals

MP

3-3

8

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

L166 LINKER/LOCATER V5.05

10/16/2004 17:52:42 PAGE 1

L166 LINKER/LOCATER V4.25, INVOKED BY:

C:\PROGRAM FILES\KEIL\R423\C166\BIN\L166.EXE flash.obj, Start167.obj

TO flash

RESERVE (8H-0BH,

0ACH-0AFH) CLASSES (ICODE (0X4000-0X7FFF), NCODE (0X4000-0X7FFF), FCONST (0X4000-0X7FFF),

HCONST (0X4000-0X7FFF), XCONST (0X4000-0X7FFF), NCONST (0X4000-0X7FFF), NDATA (0X8000-0XBFFF),

NDATA0 (0X8000-0XBFFF), SDATA (0XE000-0XE7FF, 0XF600-0XFDFF), SDATA0 (0XE000-0XE7FF, 0XF600-

0XFDFF), IDATA (0XF600-0XFDFF), IDATA0 (0XF600-0XFDFF), FDATA (0X8000-0XBFFF), FDATA0 (0X8000-

0XBFFF), HDATA (0X8000-0XBFFF), HDATA0 (0X8000-0XBFFF), XDATA (0X8000-0XBFFF), XDATA0 (0X8000-

0XBFFF)) CINITTAB (0X4000-0X7FFF)

CPU TYPE: C167 or derivative

CPU MODE: SEGMENTED

MEMORY MODEL: SMALL

Lin

ker

outp

ut fi

le flash.m66

pro

vid

es a

sum

mar

y o

f th

e li

nk p

roce

ss (

com

man

d lin

e

wit

h a

ll o

pti

ons,

mem

ory

model

, sy

mbols

,

mem

ory

map

, et

c.);

ver

y u

sefu

l fo

r deb

uggin

g!

Compilation Process –Fundamentals

MP

3-3

9

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

INTERRUPT PROCEDURES OF MODULE: flash (FLASH)

INTERRUPT PROCEDURE INT INTERRUPT NAME

=====================================================

?C_RESET 0 RESET

MEMORY MAP OF MODULE: flash (FLASH)

START STOP LENGTH TYPE RTYP ALIGN TGR GRP COMB

CLASS SECTION NAME

=====================================================================================

000000H 000003H 000004H ---

---

---

---

---

---

* INTVECTOR TABLE *

000008H 00000BH 000004H ---

---

---

---

---

---

* RESERVED MEMORY *

0000ACH 0000AFH 000004H ---

---

---

---

---

---

* RESERVED MEMORY *

004000H 004001H 000002H XDATA REL WORD ---

---

GLOB ---

?C_INITSEC

004002H

00412FH 00012EH CODE

REL WORD ---

---

PRIV

ICODE ?C_STARTUP_CODE

004130H 004159H 00002AH CODE REL WORD ---

1 PUBL NCODE ?PR?FLASH

008000H

008FFFH 001000H DATA

REL WORD ---

2 PUBL

NDATA ?C_USERSTACK

00FA00H 00FBFFH 000200H ---

---

---

---

---

---

* SYSTEM STACK *

00FC00H 00FC1FH 000020H DATA ---

BYTE ---

---

---

*REG* ?C_MAINREGISTERS

flas

h.m

66 incl

udes

info

rmat

ion a

bout th

e

inte

rrupt vec

tors

and the

mem

ory

map

Compilation Process –Fundamentals

MP

3-4

0

SYMBOL TABLE OF MODULE: flash (FLASH)

VALUE TYPE REP LENGTH TGR SYMBOL NAME

=========================================================

004132H

GLOBAL LABEL ---

---

main

004130H PUBLIC LABEL ---

---

wait

004130H BLOCK LVL=0 0002H ---

wait

---

BLOCKEND LVL=0 ---

---

004132H BLOCK LVL=0

0028H ---

main

004132H BLOCK LVL=1 0028H ---

000005H SYMBOL REG ---

---

i

---

BLOCKEND LVL=1 ---

---

---

BLOCKEND LVL=0

---

---

004002H

PUBLIC LABEL ---

---

?C_STARTUP

008000H PUBLIC VAR ---

---

?C_USRSTKBOT

00FA00H PUBLIC CONST ---

---

?C_SYSSTKBOT

000000H GLOBAL INTNO ---

---

RESET

000000H SYMBOL RBANK ---

---

?C_MAINREGISTERS

009000H SYMBOL VAR ---

---

?C_USERSTKTOP

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

flas

h.m

66 incl

udes

a tab

le o

f al

l sy

mbols

and

thei

r val

ues

, w

het

her

def

ined

expli

citly b

y the

pro

gra

mm

er o

r im

plici

tly b

y the

com

pil

er

For

ever

y p

air

of

curl

y

bra

cket

s (

{ }

)

the

com

pil

er

intr

oduce

s an

inte

rnal

lab

el

Compilation Process –Fundamentals

MP

3-4

1

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

:020000020000FC

:10000000FA000240000000000000000000000000B4

:1000100000000000000000000000000000000000E0

:1000200000000000000000000000000000000000D0

(…)

:103FE00000000000000000000000000000000000D1

:103FF00000000000000000000000000000000000C1

:104000000000A55AA5A50A863F1E1A8600D21A8965

:1040100000FF0A896F04E60C0800E68AAE04E60D8C

:104020000810E68BAE04E60A0CFAE6000000E60192

:104030000100E6020200E60800FCB54AB5B5E6F06C

(…)

:104110005C1376F300FDE014F1A54C458AF20370C0

:104120009140684B0D01784BB8430DBFFA00324106

:10413000CB00E6E1FF00D180E6E1000076E001007F

:10414000E005BBF686F50F278DFC66E0FEFFE00577

:10415000BBEF86F50F278DFC0DF10000000000007D

:1001D000684B0D01784BB8430DBFFA000E000000CC

:00000001FF

Fil

e flash.h86

is the

linked

exec

uta

ble

in a

n

EE

PR

OM

burn

er c

om

pat

ible

form

at

Rec

ord

len

gth

fie

ld (

hex

)

Chec

k s

um

byte

Addre

ss f

ield

(16-b

it)

Rec

ord

type

fiel

d (

00:

dat

a re

cord

, 01: en

d-o

f-

file

rec

ord

, 02: 8086

segm

ent ad

dre

ss r

ecord

Dat

a fi

eld

Compilation Process –Fundamentals

MP

3-4

2

:020000020000FC

:10000000FA000240000000000000000000000000B4

:1000100000000000000000000000000000000000E0

:1000200000000000000000000000000000000000D0

(…)

:103FE00000000000000000000000000000000000D1

:103FF00000000000000000000000000000000000C1

:104000000000A55AA5A50A863F1E1A8600D21A8965

:1040100000FF0A896F04E60C0800E68AAE04E60D8C

:104020000810E68BAE04E60A0CFAE6000000E60192

:104030000100E6020200E60800FCB54AB5B5E6F06C

(…)

:104110005C1376F300FDE014F1A54C458AF20370C0

:104120009140684B0D01784BB8430DBFFA00324106

:10413000CB00E6E1FF00D180E6E1000076E001007F

:10414000E005BBF686F50F278DFC66E0FEFFE00577

:10415000BBEF86F50F2A78DFC0DF10000000000007D

:1001D000684B0D01784BB8430DBFFA000E000000CC

:00000001FF

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

segm

ent ad

dre

ss 0

x0000

upon RESET

the

CP

U

div

erts

exec

uti

on to

addre

ss 0

x0000

(RE

SE

T

vec

tor)

; her

e, this

addre

ss

conta

ins

JM

PS

0x4002

(jum

p ‘

short

’ to

the

startupcode

found

at

abso

lute

addre

ss 0

x4002,

note

: little

endia

nfo

rmat

)

inst

ruct

ions

of

the

startupcode

(cf.

sli

des

MP

2-2

8 a

nd M

P2-2

9)

addre

ss

0x4002

Compilation Process –Fundamentals

MP

3-4

3

:020000020000FC

:10000000FA000240000000000000000000000000B4

:1000100000000000000000000000000000000000E0

:1000200000000000000000000000000000000000D0

(…)

:103FE00000000000000000000000000000000000D1

:103FF00000000000000000000000000000000000C1

:104000000000A55AA5A50A863F1E1A8600D21A8965

:1040100000FF0A896F04E60C0800E68AAE04E60D8C

:104020000810E68BAE04E60A0CFAE6000000E60192

:104030000100E6020200E60800FCB54AB5B5E6F06C

(…)

:104110005C1376F300FDE014F1A54C458AF20370C0

:104120009140684B0D01784BB8430DBFFA00324106

:10413000CB00E6E1FF00D180E6E1000076E001007F

:10414000E005BBF686F50F278DFC66E0FEFFE00577

:10415000BBEF86F50F2A78DFC0DF10000000000007D

:1001D000684B0D01784BB8430DBFFA000E000000CC

:00000001FF

Com

pil

atio

n p

roce

ss e

xam

ple

: fl

ashin

g L

ED

subro

utine wait

has

bee

n p

lace

d d

irec

tly

bef

ore

main

(addre

ss:

0x4130);

byte

CB

corr

esponds

to the

RE

T

inst

ruct

ion, th

e ze

ro

byte

has

bee

n

intr

oduce

d to e

nsu

re

that

main

beg

ins

on a

n

even

addre

ss (

word

alig

nm

ent)

abso

lute

jum

p to 0

x4132

(main

, cf

. sl

ide

MP

2-2

9)

addre

ss

0x4132

addre

ss

0x4130

Compilation Process –Fundamentals

MP

3-4

4

Deb

uggin

g the

LE

D p

rogra

m in Simulation m

ode

RE

SE

T:

Fet

ch f

irst

inst

ruct

ion

from

addre

ss

0x0000

Compilation Process –Fundamentals

MP

3-4

5

Sin

gle

step

pin

g

thro

ugh

code…

Sta

rt-u

p

code

(initia

lize

syst

em

regis

ters

)

Deb

uggin

g the

LE

D p

rogra

m in Simulation m

ode

Compilation Process –Fundamentals

MP

3-4

6

Sta

rt-u

p

code

concl

udes

wit

h a

(fa

r)

jum

p to

main

Deb

uggin

g the

LE

D p

rogra

m in Simulation m

ode

Compilation Process –Fundamentals

MP

3-4

7

main:

Init

iali

ze

gen

eral

purp

ose

I/O

port

P2

(both

, dat

a

dir

ection

and logic

level

)

Deb

uggin

g the

LE

D p

rogra

m in Simulation m

ode

Compilation Process –Fundamentals

MP

3-4

8

Sim

ula

tor

dis

pla

ys

gen

eral

purp

ose

I/O

port

s;

val

ues

can

be

modif

ied

man

ual

ly

Deb

uggin

g the

LE

D p

rogra

m in Simulation m

ode

Compilation Process –Fundamentals

MP

3-4

9

Alt

ernat

ivel

y:

Monitor

mode

(dow

nlo

ad to

targ

et R

AM

to a

llow

settin

g o

f

bre

akpoin

ts,

com

munic

a-

tions

via

ser

ial

inte

rfac

e)

Deb

uggin

g the

LE

D p

rogra

m in Monitor

mode

Compilation Process –Fundamentals

MP

3-5

0

Monitor

sett

ings:

Phyte

cboar

d

‘phyC

ore

-167’,

com

munic

atio

ns

thro

ugh C

OM

1,

57600 b

ps,

etc

.

Deb

uggin

g the

LE

D p

rogra

m in Monitor

mode

Monitor

resi

des

in

the

addre

ss s

pac

e

from

0xE

A00 to

0xF

FF

F

Compilation Process –Fundamentals

MP

3-5

1

Per

ipher

al

units

(e.g

.

gen

eral

purp

ose

I/O

port

s,

etc.

) now

repre

sent

the

true

stat

e of

the

asso

ciat

ed

har

dw

are

Deb

uggin

g the

LE

D p

rogra

m in Simulation m

ode

Compilation Process –Fundamentals

MP

3-5

2

Sum

mar

y –

Buil

d p

roce

ss

Sourc

e co

de

(fla

sh.c

, et

c.)

Ass

emble

r co

de

(fla

sh.a

sm,

star

tup.a

sm, et

c.)

Obje

ct f

iles

(fl

ash.o

bj, s

tart

up.o

bj, e

tc.)

Lib

rary

obje

cts

(C-f

unct

ions,

e.g. pri

ntf

, get

char

, fa

bs,

etc

.)

Exec

uta

ble

outp

ut fi

le (

flas

h,

e.g. in

EL

F/D

WA

RF

form

at)

‘Hex

’ fi

le f

lash

.h86 (

e.g. in

INT

EL

HE

X-8

6 f

orm

at

Compiler

Assem

bler

Linker / Locator Hex-file utility

Compilation Process –Fundamentals

MP

3-5

3