You are on page 1of 22

Embedded System

Chapter 3
Embedded Programs

1
Introduction
 Instruction Set
Group of instruction computer can recognize
and execute
are represented in binary (machine code)
 A program
is a sequence of instructions drawn from the
instruction set and combined to perform specific
operation

2
Introduction cont…
How to program
Machine code
Uses the binary equivalent of the instructions
Slow, tedious, and error‐prone
Example
00 0111 0001 0101

3
Introduction cont…
How to program
Assembly language
Each instruction is given a mnemonic
A program called Assembler converts to
machine code
slow and inefficient for large and complex
programs
Examples
ADDFW NUM, w

4
Introduction cont…
How to program
High‐level language
Use English‐like commands to program
Compiler converts to machine code
Easy !!
The program could be inefficient !
Example
for (i=0; i<10; i++) sum += a[i];

5
PIC18F4520 Instruction Set
Standard instruction set => 75
Extended instructions => 8
for optimization
Standard Instruction set
Use single program memory word => 16
bits
the16-bit word is divided into
an opcode, which specifies the instruction type
one or more operands, which further specify
6 the operation of the instruction.
PIC18F4520 Instruction Set cont…
Grouped as
1. Byte-oriented operations
2. Bit-oriented operations
3. Literal operations
4. Control operation

7
PIC18F4520 Instruction Set cont…
1. Byte oriented instructions
 have three operands
1. The file register (specified by ‘f’)
 specifies which file register is to be used by the instruction.
2. The destination of the result (specified by ‘d’)
 specifies where the result of the operation is to be placed
 If ‘d’ is zero, result on the WREG register.
 If ‘d’ is one, result in the file register
3. The accessed memory (specified by ‘a’)
 RAM access bit
 a = 0: Access RAM (BSR register is ignored)
 a = 1: BSR register

8
PIC18F4520 Instruction Set cont…
Example
ADDWF f, d, a

9
PIC18F4520 Instruction Set cont…

10
PIC18F4520 Instruction Set cont…
2. bit-oriented instructions
have three operands:
1. The file register (specified by ‘f’)
2. The bit in the file register (specified by
‘b’)
 selects the number of the bit affected by the
operation
3. The accessed memory (specified by ‘a’)

11
PIC18F4520 Instruction Set cont…
Example
BSF f, bit, a

12
PIC18F4520 Instruction Set cont…

13
PIC18F4520 Instruction Set cont…
3. The literal instructions
Operands can be
 A literal value to be loaded into a file register
 specified by ‘k’
 desired FSR register to load the literal value
 specified by ‘f’
 No operand required
 specified by ‘—’)
Example MOVLW 7Fh

14
PIC18F4520 Instruction Set cont…

15
PIC18F4520 Instruction Set cont…
4.The control instructions
Operands can be:
 A program memory address
 specified by ‘n
 mode of the CALL or RETURN instructions
 specified by ‘s’
mode of the table read and table write instructions
 specified by ‘m’
No operand required
 specified by ‘—’

16
PIC18F4520 Instruction Set cont…

17
PIC18F4520 Instruction Set cont…

18
19
PORTB initialization
More on Datasheet for PIC18F4520, Page 108 - 110

20
Write an assembly code which will add two constants ,
let say 0xAA and 0x07 and send output through
PORTA. Assume you are going to program it on
PIC18F4520. Use datasheet for PORTA
Configurations.

21
22

You might also like