You are on page 1of 9

28/10/2021

CEN498 Embedded Systems

Assoc. Prof. Dr. Kamil Dimililer

Dr. Kamil Dimililer 2

1
28/10/2021

Memory Organization
3

Dr. Kamil Dimililer 4

2
28/10/2021

Dr. Kamil Dimililer 5

Dr. Kamil Dimililer 6

3
28/10/2021

Directives
• Commands that are recognized and
acted upon by the assembler
– Not part of the instruction set
– Used to inform assembler (declare ).
• Different assemblers have different
directives. For Example,
• KEYDATA EQU 0x21 ; Declares that
KEYDATA is used instead of 0x21

Dr. Kamil7Dimililer

Instructions
• Assembled into machine code by
assembler
• Executed at runtime by the CPU
• Member of the instruction set the
selected processor
• Parts
– Label
– Mnemonic
– Operand
– Comment

Dr. Kamil8Dimililer

4
28/10/2021

Labels
• Act as place markers
– marks the address (offset) of code and data
• Follow identifer rules
• Data label
– must be unique
– example: KEYDATA Address of data memory

• Code label
– target of jump and loop instructions
– example: L1: Address of code memory

Dr. Kamil9Dimililer

Mnemonics and Operands


• Instruction Mnemonics
– "reminder"
– examples: MOVF, ADDWf, BTSSZ etc.
• Operands
– constant (literal value – k in the table above)
– constant expression
– Register (in general- we use only f or w in
mid-range pic model )
– memory (data label)

Dr. Kamil10Dimililer

10

5
28/10/2021

Comments
• Comments are useful
–explain the program's purpose
–when it was written, and by whom
–revision information
–tricky coding techniques
–application-specific explanations
–begin with semicolon (;)

Dr. Kamil11Dimililer

11

A program communicates to:

• Programmer

• Compiler/assembler

• Processor

Dr. Kamil12Dimililer

12

6
28/10/2021

• ; ########## EXP1.ASM ############################

• ; WRITTEN BY
• ; DATE REV 1
• ; FILE SAVED AS EXP1.ASM
• ; FOR PIC 16F877 40 PIN DEVICE
• ; RESONATOR 10MHz
• ; WATCHDOG DISABLED
• ; CODE PROTECTION OFF

• TITLE "Write to port D"


• list p = 16f877
• include <p16f877.inc>

• ORG 0 ;START ADDRESS


• GOTO START ;START OF PROGRAM

Example •


; ********** THE ROUTINES START HERE *********
ORG 20H
START CALL INITP ;INITIALISE PORTS

• REPEAT MOVLW D'55' ;SET OUTPUT TO 55H


• MOVWF PORTD ;WRITE TO PORT C
• GOTO REPEAT ;REPEAT FOREVER

• INITP BSF STATUS,RP0 ;PAGE 1


• MOVLW 0 ;MAKE PORT D OUTPUT
• MOVWF TRISD ;DO IT
• BCF STATUS,RP0
• RETURN ;RETURN

• END
Dr. Kamil Dimililer 13

13

Initialization of the processor


If the conditions are not changed, the processors
operate with their (power on) default values . The
most important default values and the related
registers for mid-range pic models:
• If you do not adjust banks (STATUS register), all
direct adresses are in bank 0.
• If you do not change ADCON1 register, All ports
are analog inputs
• When you adjust ports/pins to be digital, If you
do not adjust related TRIS register that ports/pins
are digital inputs
Dr. Kamil Dimililer 14

14

7
28/10/2021

Status Register

Dr. Kamil Dimililer 15

15

Status Register

Dr. Kamil Dimililer 16

16

8
28/10/2021

ADCON1 Register

Dr. Kamil Dimililer 17

17

Digital Port: Input or Output?

Dr. Kamil Dimililer 18

18

You might also like