Instruction formats for the PIC series. ROM encoding Instructions are encoded in binary in ROM. The instructions are fixed format, each occupying 14 bits.

Slides:



Advertisements
Similar presentations
Control structures Hot to translate high level control structures to assembler.
Advertisements

A Simple ALU Binary Logic.
SE 292 (3:0) High Performance Computing L2: Basic Computer Organization R. Govindarajan
CH10 Instruction Sets: Characteristics and Functions
Chapter 4 The Von Neumann Model
Instruction execution and sequencing
CPSC 330 Fall 1999 HW #1 Assigned September 1, 1999 Due September 8, 1999 Submit in class Use a word processor (although you may hand-draw answers to Problems.
Goal: Write Programs in Assembly
Microprocessor and Microcontroller Based Systems Instructor: Eng.Moayed N. EL Mobaied The Islamic University of Gaza Faculty of Engineering Electrical.
Prof. Jorge A. Ramón Introducción a Microcontroladores.
Instruction Set Architecture & Design
TK 2633 Microprocessor & Interfacing
Room: E-3-31 Phone: Dr Masri Ayob TK 2633 Microprocessor & Interfacing Lecture 1: Introduction to 8085 Assembly Language.
What is an instruction set?
8051 ASSEMBLY LANGUAGE PROGRAMMING
9/20/6Lecture 21 -PIC Architecture1 PIC Architecture Instruction Set.
Lecture 18 Last Lecture Today’s Topic Instruction formats
Building Assembler Programs Chapter Five Dr. Gheith Abandah1.
Machine Instruction Characteristics
Dr Mohamed Menacer College of Computer Science and Engineering Taibah University CS-334: Computer.
Microprocessor and Interfacing PIC Code Execution
PIC18F Programming Model and Instruction Set
Lecture – 4 PIC18 Family Instruction Set 1. Outline Literal instructions. Bit-oriented instructions. Byte-oriented instructions. Program control instructions.
PIC – ch. 2b. Move to GPR Move [copy] contents of WREG  GPR/RAM MOVLW99H;WREG=99H MOVWF0H ;move [copy] WREG contents to location 0h … -Cant move literal.
Computer Architecture and Organization
Computer Architecture EKT 422
Computer Architecture CSE 3322 Lecture 3 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/3/09 Read 2.8.
Chapter 10 Instruction Sets: Characteristics and Functions Felipe Navarro Luis Gomez Collin Brown.
Topics covered: Instruction Set Architecture CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
What is a program? A sequence of steps
V 0.41 C Arithmetic operators OperatorDescription +, -addition (i+j), subtraction (i-j) *, /multiplication (i*j), division (i/j) ++, --increment (i++),
PIC12F629/675. “Wide variety” 8-84 pin RISC core, 12/14/16bit program word USART/AUSART, I 2 C, ADC, ICSP, ICD OTP/UV EPROM/FLASH/ROM Families: PIC12,
Instruction Sets: Characteristics and Functions  Software and Hardware interface Machine Instruction Characteristics Types of Operands Types of Operations.
Programming PIC 16F84A in Assembly. PIC16F84 pin-out and required external components.
Computer Architecture. Instruction Set “The collection of different instructions that the processor can execute it”. Usually represented by assembly codes,
Microprocessor Systems Design I
Lecture – 5 Assembly Language Programming
Microprocessor Systems Design I
Microprocessor Systems Design I
Assembly Language Programming of 8085
Microprocessor T. Y. B. Sc..
C. K. PITHAWALA COLLEGE OF ENGINEERING AND TECHNOLOGY
Microprocessor Systems Design I
HTP Programme: Assembler
PIC – ch. 2b Md. Atiqur Rahman Ahad.
PIC 16F877.
16.317: Microprocessor System Design I
Microcomputer Programming
PIC18 CH. 4.
Computer Organization and Assembly Language (COAL)
Chapter 8 Central Processing Unit
EECE.3170 Microprocessor Systems Design I
ECEG-3202 Computer Architecture and Organization
Chapter 4 Instruction Set.
EECE.3170 Microprocessor Systems Design I
Chapter 9 Instruction Sets: Characteristics and Functions
EECE.3170 Microprocessor Systems Design I
ECEG-3202 Computer Architecture and Organization
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
8051 ASSEMBLY LANGUAGE PROGRAMMING
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
EECE.3170 Microprocessor Systems Design I
Chapter 10 Instruction Sets: Characteristics and Functions
Presentation transcript:

Instruction formats for the PIC series

ROM encoding Instructions are encoded in binary in ROM. The instructions are fixed format, each occupying 14 bits. The division of the bits into fields is flexible.

byte oriented register ops when d=0 destination = W reg d=1 destination = reg[f] f= 7 bit register selector opcodedf ( reg num )

Bit oriented operations b = 3bit number identifying a bit in an 8 bit register f = 7 bit number identifying one of 128 possible registers opcodebf

Literal ops These generally operate on the w register The second operand is a value specified in the instruction W:= w op k opcodeK=Literal value

Control transfer Used for call or goto K is a 11 bit literal that specifies an address in the program memory opcodeK

Example binary instructions We will look at the binary layout of some of the instructions in the instructionset before going on to look at the way these are accessed in assembler Goto Binary for goto Binary for 6

Remember about registers General registers 128 of them Working or W register Program counter or PC 0 127

Add 3 to W Add literal instruction Value to add =

Add register 33 to w Add reg Destination Is W Register number Is 33 W := W + Reg[33]

Add w to register Add reg Destination Is reg 33 Register number Is 33 Reg[33] := w + reg[33] This is what Differs from Last Instruction

Disadvantages of binary Hard to remember Very hard to remember for complex instructionsets Allows no variation in word lengths between different processor models ( PICs come with 12, 14 and 16 bit instructions )

Assembler Replaces each binary instruction with a line of text Opcodes replaced by mnemonic names Operands specified as symbolic labels or decimal or hex numbers Software package translates to binary

Assembler process

What assembler looks like start clrw main movlw 0x35 movwf mulplr ; test 0x35 times 0x2D movlw 0x2D movwf mulcnd call_m call mpy_S ; The result is in file ; registers H_byte & L_byte ; and should equal 0x0951 labels opcodes Operands comments Comments start with ;

A simple example What we want to compute is Y:= x+5 We must associate these variables x,y with registers. We must select machine instructions that will perform the calculation

Assign variables X assume it is 8 bit integer We will put it in register 20h We will put Y in register 21h General registers Special registers 0 20h 7f Register bank

Analyse possible data flows 1. W := x 2. W:=w+5 3. Y:=w YES 1.W:=5 2.W:=w+x 3.Y:=w YES W:=x Y:=w Y:=y+5 NO, cant add 5 to y

MOVLW 5 ; w:=5 ADDWF 20h,0 ; w:= w + reg[20h] MOVWF 21h ; y:=w Y:=x+5 0 indicates w is dest

Outline the instructions We will now look at the instructionset of the PIC processor. There are 35 instructions

Register addition ADDWF f,d Add reg[f] to w and store in either w or reg[f] depending on d, if d=0 then store in w, else in reg[f] If reg[24h] =6 and w=4 then ADDWF 24h,1 Sets reg[24h] to 10

Addition of a constant ADDLW const Add const to w and store in w If w=4 then ADDLW 24h Sets w to 28h

andwf ANDWF f,d And reg[f] with w and store in either w or reg[f] depending on d, if d=0 then store in w, else in reg[f] If W = and reg[20h]= ANDWF 20h,0 will set w to

ANDLW ANDLW const And const with w and store in w If W = and const= 6= ANDLW 6 will set w to

Clear registers Clrf f set reg[f] to zero Eg CLRF 40 ; reg[40]:=0 Clrw set w register to zero

MOVE OPERATIONS MOVFW f Moves contents of register f to the W register MOVWF f Moves the W reg to register f MOVLW const Moves the literal constant to the W register Last two letters are memonics FW,WF,LW

NOP NOP stands for NO oPeration It is an opcode that does nothing Its binary pattern is This is similar to MOVWF whose pattern is FFFF Destination bit Destination register Destination=w

subtractions This can be done by using complement or subtract operations, subtract is not strictly needed COMF f,d This sets either reg[f] or w to –reg[f] For example if x is in reg[32] and y in reg[33] then x:=x-y would be done by COMF 33,0 ; w:=-y ADDWF 32,1 ; x:=x+w

Suppose we want reg[32]:=reg[33]-reg[40] Initial values Binary Code Values manipulated Comf 40, 0 ; w Addwf 33,0 ; w Movwf 32 ; reg[32] Complement continued Carry bit

SUBWF Subtract w from f SUBWF f,d This has two forms SUBWF f,0 ; w:= reg[f]-w SUBWF f,1 ; reg[f]:= reg[f]-w Comf 33,0 ; w:=-y Addwf 32,1 ; x:=x+w MOVFW 33 ;w:=y SUBWF 32,1;x:=x-w Instead of

Decrement register Decf f, d Decrements reg[f] and stores result in either reg[f] or w depending on d DECF 50,1 Subtracts 1 from register 50 DECF 50,0 Sets w := reg[50] -1

Decrement and skip DECFSZ f,d Meaning of f, and d fields as before If the result of decrementing is zero, skip the next instruction Top: ;some instructions DECFSZ 38,1 GOTO Top ; some other instructions Reg[38] holds the number of times to go round loop

Incrementing INCF and INCFSZ work like DECF and DECFSZ except that they increment In this case you would load a negative number into your count register and count up towards zero. Alternatively, count up, and skip when the result would have been 256. Incfsz 50,1; means reg[50] := reg[50]+1 if reg[50] is 0 then skip next instruction

Inclusive or IORWF f,d Example If w= and reg[40]= IORWF 40,0 Will set w= or

Inclusive or Literal IORLW const Example If w= IORLW 7 Will set w= or

Exclusive or XORWF f,d Example If w= and reg[40]= XORWF 40,0 Will set w= xor

Exclusive or Literal XORLW const Example If w= XORLW 7 Will set w= xor

Bit operations BCF f,b set bit b of register f to 0 BSF f,b set bit b of register f to 1 Eg BCF 34,1 Clears bit 1 of register 34

Test instructions BTFSC f,b ; bit test skip on clear BTFSS f,b ; bit test skip on set Eg INCF 33 BTFSC 33,4 GOTO OVERFLOW ; goto overflow when ; reg 33 >7

GOTO GOTO label Eg GOTO home ….. home MOVLW 7 …. Transfers control to the label

CALL and RETURN Thare used for subroutines or procedures. CALL foo …. foo ; start of procedure …. ; body of procedure RETURN; end of procedure

CALL continued When a call occurs the PC+1 is pushed onto the stack and then the PC is loaded with the address of the label When return occurs the stack is popped into the PC transferring control to the instruction after the original call.

example call source Init call increment goto Init increment incf CountL return labels

Example call and return Address opcode assembler CALL 0x GOTO 0x5 7 0AA2 INCF 0x22, F ; increment reg 0x RETURN at start we have state of the stack

Next step Address opcode assembler CALL 0x GOTO 0x5 7 0AA2 INCF 0x22, F RETURN stack holds address to return to

just before return

after return stack pointer is retracted