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

Lecture-3-PIC Assembly

Uploaded by

Sheri Gaming
Copyright
© © All Rights Reserved
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)
9 views

Lecture-3-PIC Assembly

Uploaded by

Sheri Gaming
Copyright
© © All Rights Reserved
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/ 35

The University of Texas at Arlington

Lecture 3
PIC Assembly

CSE 3442/5442
Embedded Systems I
Based heavily on slides by Dr. Gergely Záruba and Dr. Roger Walker
RISC: Reduced Instruction
Set Computer
1. Fixed instruction size (2 and 4 bytes in PIC ;
ADD, GOTO)
2. Many registers (no need for large stack)
3. Small instruction set – longer code
4. Small clock cycle/instruction
5. Usually Harvard architecture
6. No microcoding; instructions are internally
hardwired – can result in 50% reduction in the
number of transistors
7. No cross operations between GFR registers
2
PIC uses Harvard Architecture

3
PIC18F452 Pin Diagram

4
Example - Powering Up
PIC18F458

5
Example - Powering Up
PIC18F458

6
Example - Powering Up
PIC18F458

7
Programs in ROM

• When PIC is powered up (VCC applied to


Reset Pin), the micro-controller begins
executing instruction at location 00000h
(Reset Vector)
• Use ORG statement for this instruction in
your code (if programming in assembly)
– C compiler takes care of creating assembly
code having this

8
Recap

9
Recap

• Register
– A place inside the PIC that can be written to,
read from, or both (8-bit numbers)

10
Dec, Hex, Bin

11
Assembler/Compiler
Data Formats
• Data Byte Representation
– hex, decimal, binary, ASCII

Format .ASM .C

Decimal D’127’ or .127 127

Hex 07F or H’07F’ or 07FH or 0x7F 0x7F

Binary b‘01111111’ 0b01111111

12
Assembler/Compiler
Directives
• Instructions (MOVLW, ADDLW, etc.) tell CPU what to do
• Directives give directions to the Assembler/Compiler
– “pseudo-instructions”

• Assembler directives:
– EQU (defining constants), (SET is similar but can be reset)
– ORG (origin - explicit address offset operand must be hex)
– END (tells assembler that this is end of code)
– LIST (indicates specific controller, e.g., LIST P=18F452)
– #include (to include libraries associated)
– _config directives – tell assembler what the configuration (stored at
300000H) bits of the target PIC should be
– radix (e.g., radix dec will change to decimal notation; default is hex)
13
Configuration Registers

Table 19-1 from Data Sheet


14
Assembly Language
Structure
[label] mnemonic [operand1, operand2] [;comment]

15
Assembly Language
Structure
[label] mnemonic [operand1, operand2] [;comment]

optional
• Label: Can now refer to a line of code by name
• Mnemonic (instruction): ADDLW, BNZ, etc.
• Operand(s): Literal, file register location, variable
that is manipulated, used, or acted upon
• Comment: starts with ; and is ignored by assembler

16
Instruction Format

17
Instruction Format

18
Instruction Set Info.

19
Opcode

20
Status Flags

21
Assembly Programming
Sample
SUM EQU 0F7H

ORG 0H

HERE MOVLW 0
MOVWF SUM
MOVLW 25H ;25H  WREG
ADDLW 0x34 ;+ 34H
ADDLW 11H ;+ 11H
ADDLW 0C1H ;+ C1H
ADDLW 25 ;+25H
ADDLW D'18' ;+ 18 decimal
ADDLW B'00000110‘ ;+6 dec
MOVWF SUM

MOVLW SUM
GOTO HERE

END 22
Assembly Code Assembled an
Linked

23
Program Counter (PC)

ORG 0

MOVLW 5
ADDLW 4

END

24
PIC18 Program Counter

2 MB

21-bit  000000 to 1FFFFF addresses

25
PIC18 On-Chip Program ROM
Address Range

4k

16 k
32 k

(452)

Figure 2-10
26
PIC18 Program
ROM Space

21-bit  000000 to 1FFFFF addresses

27
Assembly Programming
sample
SUM EQU 0F7H

ORG 0H

0x00 HERE MOVLW 0


0x02 MOVWF SUM
0x04 MOVLW 25H ;25H  WREG
0x06 ADDLW 0x34 ;+ 34H
0x08 ADDLW 11H ;+ 11H
0x0A ADDLW 0C1H ;+ C1H
0x0C ADDLW 25 ;+25H
… ADDLW D'18' ;+ 18 decimal
ADDLW B'00000110‘ ;+6 dec
MOVWF SUM

MOVLW SUM
GOTO HERE

END 28
PIC18 Program ROM Width

29
ROM Contents

Opcode
0x00 MOVLW 25H 0x0E

0x02 ADDLW 34H

0x04 ADDLW 11H

0x06

0x08 Opcode
… 0x0F

30
ROM Contents

25H MOVLW
0x00 MOVLW 25H
34H ADDLW
0x02 ADDLW 34H 11H ADDLW

0x04 ADDLW 11H

0x06

0x08

25H 0EH
34H 0FH
11H 0FH
31
ROM Contents

32
GOTO and the PC

• GOTO, 4 byte instruction:


0E 07
0F EF
10 00
11 F0
little endian!

PCU PCH PCL

0 0 0 k19 k15 k14 k7 k6 k0 0

21 bit PC 33
Assembly Programming
sample
SUM EQU 0F7H

0x00 ORG 0H

0x00 HERE MOVLW 0


0x02 MOVWF SUM
0x04 MOVLW 25H ;25H  WREG
0x06 ADDLW 0x34 ;+ 34H
0x08 ADDLW 11H ;+ 11H
0x0A ADDLW 0C1H ;+ C1H
0x0C ADDLW 25 ;+25H
… ADDLW D'18' ;+ 18 decimal
ADDLW B'00000110‘ ;+6 dec
MOVWF SUM

MOVLW SUM
GOTO HERE ;GOTO 0x00

END 34
Note

• Chapter 2 for more details of Assembly


and Architecture
• Start reading Chapter 3
– Branching

35

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy