Beruflich Dokumente
Kultur Dokumente
Processor Architecture
•
• CISC
Large amount of instructions each carrying out a different permutation
of the same operation
Functionality of the instructions is more dependent upon the
processor’s designer
• RISC
Fundamental set of instructions
More control for users to design their own operations
• Harvard Architecture
Separate memory space program and data
Instructions are executed in one cycle
Easier timing of loops and delays
•
•
•
•
•
• Von Neumann Architecture example
Mov acc, reg
Cycle 1 Read instruction
Cycle 2 Read data out of Ram and
put into
Acc
Instruction pipeline
000-1FF
Instruction Register
File Address
Program address
Working (W)
Register File Select
Literal Register
Arithmetic & Logic
Unit
Status bits
Status (Flag)
Op- Register Data Bus
code (8 bits)
EEPROM
Instruction MCU 256 bytes
Decode & control
CPU control lines
Ports, Timers
ADC, Serial I/O
Timing control
Clock Reset
Port A B C D E
Features –PIC16F877
• Instruction Pipeline:
• The instruction pipeline is a two-stage pipeline which overlaps the fetch and
execution of instructions.
• The fetch of the instruction takes one TCY, while the execution takes
another TCY.
• Due to the
overlap of the fetch of current instruction and execution of previous
instruction, an instruction is fetched and another instruction is executed every
single TCY.
Single Cycle Instructions
• With the Program Memory bus being 14-bits wide, the entire instruction is
fetched in a single machine cycle (TCY).
• The instruction contains all the information required and is executed in a
single cycle.
• There may be a one cycle delay in execution if the result of the instruction
modified the contents of the Program Counter.
• This requires the pipeline to be flushed and a new instruction to be fetched.
Reduced Instruction Set
• When an instruction set is well designed and highly orthogonal (symmetric),
fewer instructions are required to perform all needed tasks.
•
• With fewer instructions, the whole set can be more rapidly learned.
Reduced Instruction Set
• When an instruction set is well designed and highly orthogonal (symmetric),
fewer instructions are required to perform all needed tasks.
• With fewer instructions, the whole set can be more rapidly learned.
Register File Architecture
• The register files/data memory can be directly or indirectly addressed.
• All special function registers, including the program counter, are mapped in
the data memory.
MEMORY
• Program Memory
• Register File Memory (Data RAM)
Program Memory
• Used for storing compiled code
• Each location is 14 bits long
• Every instruction is coded as a 14 bit word
• PC can address up to 8K addresses because PC for PIC16F877 is 13bit.
Program Memory Organization
• Mid-Range MCU devices have a 13-bit program counter capable of addressing
an 8K x 14 program memory space.
• The width of the program memory bus (instruction word) is 14-bits.
• Since all instructions are a single word, a device with an 8K x 14 program
memory has space for 8K of instructions.
• This makes it much easier to determine if a device has sufficient program
memory for a desired application.
USE OF PCLATCH
• To jump between the program memory pages, the high bits of the Program
Counter (PC) must be modified.
• This is done by writing the desired value into a SFR called PCLATH
(Program Counter Latch High).
• If sequential instructions are executed, the program counter will cross the page
boundaries without any user intervention.
• For devices that have less than 8K words, accessing a location above the
physically implemented address will cause a wraparound.
• That is, in a 4K-word device accessing 17FFh actually addresses 7FFh. 2K-
word devices (or less) do not require paging.
DATA Memory
• Consist of 2 Components
General Purpose Register (GPR) Files (RAM)
Special Purpose Register (SPR) files OR SFR
Banking In SFR
• The data memory is partitioned into four banks. Each bank contains General
Purpose Registers and Special Function Registers.
• Switching between these banks requires the RP0 and RP1 bits in the STATUS
register to be configured for the desired bank when using direct addressing.
• The IRP bit in the STATUS register is used for indirect addressing.
Direct and Indirect Addressing of Banks
• Each Bank extends up to 7Fh (128 bytes).
• The lower locations of each bank are reserved for the
Special Function Registers.
• Above the Special Function Registers are General Purpose Registers.
• All data memory is implemented as static RAM.
• All Banks may contain special function registers.
• Some “high use” special function registers from Bank0 are mirrored in the
other banks for code reduction and quicker access.
Direct Addressing
SFRs IN PIC
• Dedicated to Special Function Like,
– ALU Status
– Timers
– I/O Ports
– ADC
– Etc.
The function of each SFR is fixed because its used to control peripherals.
PIC SFRs are 8 bit registers.
Varies according to series.
GPR(RAM
– It’s a group of RAM locations in file register.
– It is used for data storage and scratch PAD.
– Each location is 8 bit wide.
– Capacity can vary from chip to chip.
WREG
• The 8-bit WREG register is the most widely used register in the PIC
microcontroller.
• WREG stands for working register, as there is only one.
•The WREG register is the same as the accumulator in other
microprocessors.
• The WREG register is used for all arithmetic and logic instructions.
MOVLW instruction
• The MOVLW instruction moves 8-bit data into the WREG register.
• Format:
• MOVLW K ;move literal value K into WREG
• K is an 8-bit value that can range from 0-255 in decimal, or 00-FF in hex.
• The L stands for literal, which means, literally, a number must be used.
• MOVLW 25H ;move value 25H into WREG (WREG = 25H)
ADDLW instruction
• The ADDLW instruction has the following format:
• ADDLW K ;ADD literal value K to WREG
• The ADD instruction tells the CPU to add the literal value K to register
WREG and put the result back in the WREG register.
• Notice that in ADDLW, first comes the letter L (literal) and then the letter W
(WREG), which means "add a literal value to WREG," the destination.
• To add two numbers such as 25H and 34H, one can do the following:
• MOVLW 25H ;load 25H into WREG
• ADDLW 34H ;add value 34 to W(W = W + 34H)
• Executing the above lines results in WREG = 59H (25H + 34H = 59H)
• PORTB, PORTC, and PORTD are part of the special function registers in the
file register
CPU Registers
• STATUS
• PC
• W
• PCL
• PCLATH
STATUS REGISTER
• The STATUS register, shown below, contains the arithmetic status of the
ALU, the RESET status and the bank select bits for data memory.
• Since the selection of the Data Memory banks is controlled by this register, it
is required to be present in every bank.
• This register is also called as Flag Register.
ADDLW 0x11
ADDLW 12H
ADDLW
H’2A’
MOVLW
0E5H – Take care
MOVLW .12
4) ASCII Characters
e.g.
MOVLW A’2’ ;WREG= 00110010 or 32H Hex no. for ASCII ‘2’;
ASSEMBLER DIRECTIVES
• Directives give directions to the assembler.
• E.G. EQU,ORG,LIST and END.
• EQU- Equate –Defines a constant value or fixed address.
• E.g. COUNT EQU 0x25
• MOVLW COUNT ;WREG=25H
ORG(origin)
• Used to indicate beginning of the address.
• Can be used for both code and data memory.
• The number after org must be in HEX.
END Directive
• Indicates to the assembler end of the source file.
• Anything after END will be ignored by the assembler.
LIST Directive
• Its unique for PIC assembler informs to the assembler about specific PIC chip
for which the program should be assembled.
– E.g. LIST P = 16F877
#include directive
• Tells assembler to use libraries associated with the specific device.
• Compiler will compile accordingly.
_config directive
• Gives information to assembler about configuration bits for the targeted chip.
• These bits are read during power up.
radix directive
• Used to indicate the numbering system is decimal or hex.
• Default is HEX if we don’t use radix.
• If you want to use ,use “radix dec”.
Assembler
• The assembler converts source code to object code, and then list file.
• Linker converts –OTH file.
• Both are integrated in MPLAB sodtware.
• MPLAB IDE has =>
Editor
,assembler,linker,simulator and all development environment required.
Immediate Addressing
• Uses 7 bits of 14 bit instruction to identify a register file address
• 8th and 9th bit comes from RP0 and RP1 bits of STATUS register.
• We can use EQU directive to access immediate data.
• Exp: COUNT EQU 0x20
…….
…….
MOVLW COUNT
• The entire data RAM can be accessed using direct addressing mode.
• In direct addressing mode the operand DATA is in RAM memory location
whose address is known.
• This address is part of the instruction.
• E.g. MOVLW 0x56 ;(IMMEDIATE ADDRESSING MODE)
MOVWF
0X40 ;COPY WREG INTO 40H RAM LOCATION
MOVFF
0X40,0X50 ;COPY THE DATA FROM 40H TO 50H
LOOK UP TABLE
• DB:Define byte directive is widely used to allocate ROM program.
• The data can be hex,decimal,binary or ASCII.
• E.g.
ORG
500H
DATA1 DBD’28’
DATA2 DB
B’10101010’
DATA3 DB0x38
DATA4 DB
‘Y’,’1’,’2’,’3’
Indirect Addressing