Professional Documents
Culture Documents
The instruction set is highly orthogonal and is grouped into four basic categories:
An Assembly language instruction consists of four fields: [label] mnemonic [operands] [; comment]
Byte-oriented operations
Most byte-oriented instructions have three operands: 1. The file register (specified by f) 2. The destination of the result (specified by d) 3. The accessed memory (specified by a) The file register designator f specifies which file register is to be used by the instruction. The destination designator d specifies where the result of the operation is to be placed. If d is zero, the result is placed in the WREG register. If d is one, the result is placed in the file register specified in the instruction.
Byte-oriented operations
Bit-oriented operations
All bit-oriented instructions have three operands: 1. The file register (specified by f) 2. The bit in the file register (specified by b) 3. The accessed memory (specified by a)
The bit field designator b selects the number of the bit affected by the operation, while the file register designator f represents the number of the file in which the bit is located.
Bit-oriented operations
Literal operations
The literal instructions may use some of the following operands: A literal value to be loaded into a file register (specified by k) The desired FSR register to load the literal value into (specified by f) No operand required (specified by )
Literal operations
Control operations
The control instructions may use some of the following operands: A program memory address (specified by n) The mode of the CALL or RETURN instructions (specified by s) The mode of the table read and table write instructions (specified by m) No operand required (specified by )
Control operations
All instructions are a single word, except for four double-word instructions. All single-word instructions are executed in a single instruction cycle, unless a conditional test is true or the program counter is changed as a result of the instruction. In these cases, the execution takes two instruction cycles with the additional instruction cycle(s) executed as a NOP.
Example
ORG REG0 REG1 REG2 MOVLW MOVWF MOVLW MOVWF ADDWF MOVWF SLEEP 0x20 EQU 0x00 EQU 0x01 EQU 0x02 0x37 REG0,0 0x92 REG1,0 REG0,0 REG2, 0
Arithmetic Instructions (1 of 3)
Arithmetic Instructions (2 of 3)
Arithmetic Instructions (3 of 3)
Logic Instructions
Branch Instructions
First we use a text editor to type in a program. PIC microcontrollers, we use the MPLAB IDE, which has a text editor, assembler, linker, simulator, and much more all in one software package. Source file has the extension "asm". The "asm" extension for the source file is used by an assembler in the next step.
The assembler converts the instructions into machine code. The assembler will produce an object file and an error file.
The extension for the object file is "0". The extension for the error file, which contains any syntax errors and their line numbers, is "err". Assemblers require a third step called linking. The link program takes one or more object files and produces a hex file, a list file, a map file, an intermediate object file, and a debug file. After a successful link, the hex file is ready to be burned into the PIC's program ROM and is downloaded into the PIC Trainers
PIC assembler provides us the error file with the extension of "err" and this is the file we examine to see the nature of syntax errors. The 1st (list) and map files are very useful to the programmer. The list shows the binary and source code. The map file shows the memory layout of used and unused memory locations.
(a) PIC I 8F2220 with 4 KB With 4K of on-chip ROM memory space, we have 4096 bytes (4 x 1024 = 4096). This maps to address locations of 0000 to OFFFH. Notice that 0 is always the first location.
(b) PICI8F2410 with 16 KB With 16K of on-chip ROM memory space, we have 16,384 bytes (16 x 1024 = 16,384),which gives 0000-3FFFH.
(c) PICI8F458 with 32 KB With 32K we have 32,768 bytes (32 x 1024 = 32,768). Converting 32,768 to hex, we get 8000H; therefore, the memory space is 0000 to 7FFFH.
For this reason, in the PIC system, the first opcode must be burned into memory location OOOOOH of program ROM because this is where it looks for the first instruction when its booted. We achieve this by using the ORG statement in the source program.
;PIC Assembly Language Program To Add Some Data. ;store sum in fileReg location lOH. SUM EQU 10H ; RAM loe 10H for sum ORG OH ;start at address 0 MOVLW 25H ;WREG = 25 ADDLW Ox34 ;add 34H to WREG ADDLW 11H ;add 11H to WREG ADDLW D'18' ;W W + 12H = 7CH ADDLW lCH ;W = W + lCH = 98H ADDLW B' 00000110' ;W = W + 6 = 9EH MOVWF SUM ;save the sum in loc 10H HERE GOTO HERE ;stay here forever END ;end of asm source file
For the PICI8, the internal data bus between the code ROM and the CPU is 16 bits.