Lecture – 4 PIC18 Family Instruction Set 1. Outline Literal instructions. Bit-oriented instructions. Byte-oriented instructions. Program control instructions.

Slides:



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

REGISTER TRANSFER LANGUAGE (RTL)
Machine Instructions Operations
1/1/ / faculty of Electrical Engineering eindhoven university of technology Introduction Part 2: Data types and addressing modes dr.ir. A.C. Verschueren.
INSTRUCTION SET ARCHITECTURES
Machine Instructions Operations 1 ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson Slides4-1.ppt Modification date: March 18, 2015.
Lecture - 2 Number systems and computer data formats
The CPU Revision Typical machine code instructions Using op-codes and operands Symbolic addressing. Conditional and unconditional branches.
Instruction Set Architecture & Design
TK 2633 Microprocessor & Interfacing Lecture 3: Introduction to 8085 Assembly Language Programming (2) 1 Prepared By: Associate Prof. Dr Masri Ayob.
Memory - Registers Instruction Sets
Room: E-3-31 Phone: Dr Masri Ayob TK 2633 Microprocessor & Interfacing Lecture 1: Introduction to 8085 Assembly Language.
8051 ASSEMBLY LANGUAGE PROGRAMMING
Lecture – 5 Assembly Language Programming
9/20/6Lecture 21 -PIC Architecture1 PIC Architecture Instruction Set.
Lecture - 3 PIC18 family architecture and program development
9/20/6Lecture 21 -PIC Architecture1 PIC Architecture Programmers Model and Instruction Set.
Lecture 18 Last Lecture Today’s Topic Instruction formats
The 8051 Microcontroller and Embedded Systems
Khaled A. Al-Utaibi  Introduction  Arithmetic Instructions  Basic Logical Instructions  Shift Instructions  Rotate Instructions.
CoE3DJ4 Digital Systems Design
Machine Instruction Characteristics
Directives, Memory, and Stack. Directives Special commands to the assembler May or may not generate machine code Categories by their function Programming.
Embedded System Spring, 2011 Lecture 10: Arithmetic, Logic Instruction and Programs Eng. Wazen M. Shbair.
PIC18F Programming Model and Instruction Set
Dr. José M. Reyes Álamo 1.  Review: ◦ Statement Labels ◦ Unconditional Jumps ◦ Conditional Jumps.
Microprocessors Monday, Apr. 13 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University.
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
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.
Chapter 2-2 Assembly Instructions Number Systems Number Systems Assembly Instructions Assembly Instructions Branch Branch Next Lecture Next Lecture  Addressing.
Module : Algorithmic state machines. Machine language Machine language is built up from discrete statements or instructions. On the processing architecture,
A summary of TOY. 4 Main Components Data Processor Control Processor Memory Input/Output Device.
Computer Architecture Lecture 03 Fasih ur Rehman.
Chapter 10 Instruction Sets: Characteristics and Functions Felipe Navarro Luis Gomez Collin Brown.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
Arithmetic and Logic Instructions
What is a program? A sequence of steps
Group # 3 Jorge Chavez Henry Diaz Janty Ghazi German Montenegro.
V 0.41 C Arithmetic operators OperatorDescription +, -addition (i+j), subtraction (i-j) *, /multiplication (i*j), division (i/j) ++, --increment (i++),
Chapter 7 Bit Manipulation. 7.1 Logical Operations.
Instruction Sets. Instruction set It is a list of all instructions that a processor can execute. It is a list of all instructions that a processor can.
8085 INTERNAL ARCHITECTURE.  Upon completing this topic, you should be able to: State all the register available in the 8085 microprocessor and explain.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Control Unit.
Microprocessor & Assembly Language
Computer and Information Sciences College / Computer Science Department CS 206 D Computer Organization and Assembly Language.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization.
Computer Architecture. Instruction Set “The collection of different instructions that the processor can execute it”. Usually represented by assembly codes,
Lecture – 5 Assembly Language Programming
Control Unit Lecture 6.
Microprocessor Systems Design I
Microprocessor Systems Design I
Assembly Language Programming of 8085
ARM Registers Register – internal CPU hardware device that stores binary data; can be accessed much more rapidly than a location in RAM ARM has.
Microprocessor Systems Design I
Microprocessor and Assembly Language
PIC – ch. 2b Md. Atiqur Rahman Ahad.
Microcomputer Programming
A Closer Look at Instruction Set Architectures: Expanding Opcodes
PIC18 CH. 4.
Shift & Rotate Instructions)
Programmer’s View of the EAGLE
ECEG-3202 Computer Architecture and Organization
Chapter 4 Instruction Set.
Shift & Rotate Instructions)
EECE.3170 Microprocessor Systems Design I
ECEG-3202 Computer Architecture and Organization
Chapter 5 Arithmetic and Logic Instructions
MIPS Assembly.
MIPS assembly.
COMPUTER ORGANIZATION AND ARCHITECTURE
Presentation transcript:

Lecture – 4 PIC18 Family Instruction Set 1

Outline Literal instructions. Bit-oriented instructions. Byte-oriented instructions. Program control instructions. 2

Literal instructions (1) A literal is a constant such as a number or ASCII character. Most of the literal addressing instructions operate with the working register or WREG. Most literal instructions use the second byte of the 16-bit instruction to hold the literal data. The first three letters of most of the literal instructions indicate the operation performed by the instruction. The CPU is capable of only a few operations: ADD (addition), AND (logical AND), IOR (inclusive OR), MOV (copy), MUL (multiplication), SUB (subtraction), and XOR (exclusive OR). 3

Literal instructions (2) The last two letters of the opcode indicate something about the instruction. For example, the letter L indicates Literal and the letter W indicates the WREG register. The arithmetic and logic instructions are not complete in the PlC microcontroller. A divide instruction is not implemented in the PlC family, but multiplication is implemented. If division is needed in a system, software must be developed that divides. In general, an arithmetic or logic instruction changes the status register bits. The exception is the multiply instruction, which does not affect any of the status register bits. 4

Literal instructions (3) 5

Example 1 Find the values in the status register after running the following program: _________________________________ N = 1, OV = 1, C = 0, DC = 1, and Z = 0. The result is negative, the result overflow the W register, there was no carry, there was a half-carry or digit carry, and the result is not zero 6

Literal logic instructions The AND operation is often used to selectively clear a single or multiple bits to zero, because when a zero is ANDed with anything the result is zero. The Inclusive-OR (IOR) operation is often used to selectively set a single or multiple bits to one, because when one is Inclusive-ORed with anything the result a one. The Exclusive-OR (XOR) operation selectively inverts a single bit or multiple bits from zero to one or from one to zero, because when a one is Exclusive-ORed with anything the result is inverted. 7

Example 2 Suppose a situation requires that the rightmost two bits (bits 0 and 1) of WREG must be cleared (1) and that bits 6 and 7 need to be set (1). ________________________________________ 8

Example 3 Suppose a situation requires that the leftmost three bits of the W register to be inverted. _________________________ 9

Bit-oriented instructions (1) The bit operations set, clear, and toggle test only a single bit, where the AND, IOR, and XOR byte-oriented instructions change a single bit or multiple bits. Many applications for the microcontroller require the use of the bit-oriented instructions to control and test individual bits in a program. This is especially true when interfacing and controlling I/O devices. The a-bit position is needed only in the assembler when a numeric register file address is used in an instruction to specify either the access bank or the bank select register. If the instruction refers to a register by its name or the name of a memory location instead of its numeric address, the a-bit is not used in a program. 10

Bit-oriented instructions (2) 11

Example 4 Describe the process of the following program: ________________________ Uses the conditional bit-oriented instructions to clear bit zero of WREG only if bit 7 is zero. 12

Byte-oriented instructions (1) The byte-oriented instructions allow variable data to be used in a program, whereas the literal instructions allow constant data to be used in a program. The byte-oriented instructions typically use the W register and a location in the register file to perform some operation. Most of these instructions have three operands: The first is the register file location, the second determines the destination, and the third selects the access bank or a register file bank as determined by the bank select register (BSR). 13

Byte-oriented instructions (2) If the second operand (d-bit) is a 0, then the destination is the WREG, and if the second operand is a 1, then the destination is the register file location. The d-bit is needed only to place the result of an operation into WREG; the default is d = 1 If the third operand (a-bit) is a 0, then the access bank is used for the register file location and if it is a 1, then the bank determined by the BSF. The a-bit is required only when referencing a file register by number; if referenced by a label, the a-bit is not used in an instruction. The default is a = 1. 14

Example 5 This example illustrates a short program that adds the 16-bit number in access bank locations 0x10 and 0x11 to the 16-bit number in access bank locations 0x12 and 0x13. Both numbers are stored using the little endian format. The result is stored at access bank locations 0x14 and 0x15. 15

Rotates (1) The PIC18 family instruction set has four, byte-oriented rotate instructions. Bytes are rotated right or left either through the carry or without the carry. One method of multiplying or dividing is by rotating a number. If a number is rotated left, with a zero placed into the rightmost bit, the number is multiplied by a factor of 2. Likewise, if a number is rotated right with a zero placed in the leftmost bit, it is divided by two. For a signed division by two, the sign bit is rotated into the leftmost bit of the result. If a number can be multiplied or divided by two it can be multiplied or divided by any number. 16

Rotates (2) 17

Division If a division by a power of 2 is needed, it is accomplished by shifting a number to the right. A shift right is accomplished by first clearing the carry flag followed by a RRCF instruction. The answer is rounded up if a carry is found after the last rotate right. The bit test and skip if zero instruction is used to skip the INCF (increment) if the carry was zero. 18

Example 6 This example multiplies a test number of 4 in WREG by a factor of 5 and leaves the result of 20 in WREG. 19

Example 7 This example divides a test number of a 100 (decimal) by 8 and the result of 12.5 left in WREG as 13 (a rounded-up 12.5). 20

Program control instructions (1) The program control instructions modify the flow of a program through conditional branches and function calls. They also provide some control over the operation of a few internal features of the microcontroller. A GOTO is a 32-bit instruction that branches to any program memory location in the program memory. The BRA (branch always) instruction, which also does an unconditional branch, is a 16-bit instruction that has a limited branch range. A BRA instruction contains an 11-bit number stored with it that is not an address, but a distance. 21

Program control instructions (2) 22

Relative branch This distance or displacement, allows the BRA to jump ahead in a program by up to 1,024 bytes from the address of the next instruction in the program or back by up to bytes from the next instruction in the program. This type of branch is often called a relative branch because the instruction is moved to some other part of memory and the distance of the branch remains the same. All of the conditional jumps use this displacement form of addressing, but have an even shorter range of between +127 or -128 bytes from the next instruction in a program. The GOTO is often called an absolute branch because the address is fixed or absolute. A branch (BRA) or conditional branch is often called a relative branch. 23

Example 8 This example tests access bank register 0x10 for the value of 4. If it is 4, a 6 is placed into 0x10 and if it is not, a 9 is placed into 0x10. _______________________________ 24

Summary Literal instructions allow literal or constant data to be used mainly with the WREG. Literal instructions use opcodes such as MOVLW or ADDLW, where the first three letters are the operation and the last two indicate what is operated upon. (L = literal, W = WREG). The ADDLW instruction adds literal data to WREG. For example, the ADDLW 6 instruction adds a 6 to WREG. Other literal instructions are available for subtraction (SUBLW), include- OR (IORLW), exclusive-OR (XORLW), AND (ANDLW), and multiplication (MULLW). There is also a literal return from a procedure (RETLW) that allows a literal to be returned in WREG. 25

Summary Two of the literal instructions do not use WREG. The MOVLB and the LFSR. The bit-oriented instructions allow individual bits to be cleared (BCF), set (BSF), or toggled (BTG). This allows complete control of the state of any bit anywhere in the data memory, including the special function registers. Other bit-oriented instructions are BTFSC and BTFSS, which test a bit and either skip the next instruction if the bit is cleared (BTFSC) or if it is set (BTFSS). There are more byte-oriented instructions than any other type of instruction. All of them work with byte-sized data. The way that the instruction appears indicates the operation of the instruction. 26

Summary For example, an ADDWF adds a byte from the WREG to a register file location or from the register file location to the WREG. The direction of the operation is selectable. The control instructions allow conditions to be tested and then, based on the outcome, can branch to another part of the program. These instruction often implement an if statement. Program constructs are the building blocks of programming. The program constructs most often used are if-then-else, repeat-unti1, while, and function. 27

Questions 1.Select an option that makes the statement TRUE: - This is a literal instruction: a.ADDLW. b.BSF. c.MOVWF. d.ADDWF. 2.Select an option that makes the statement NOT TRUE: - This is a program control instruction: a.BZ. b.GOTO. c.MOVWF. d.BC.

Questions 3. Explain what each of the following literal instructions accomplish: a. MOVLW 0x6A b. XORLW 4 c. MULLW.10 d. MOVLB 2 ____________________________ (a)moves a 0x6A into WREG (b)inverts bit 2 of WREG, (c)multiplies WREG by 10 decimal (d)selects bank 2 by loading BSR with a 2 29

Questions 4. Write a short sequence of instructions that place a 0x0F into WREG and then clear the right most two bits, set the leftmost bit, and invert bit position 5 using only literal instructions to accomplish the task. _________________ MOVLW 0x0F ;place 0x0F into W ANDLW 0xFC ;clear bits 0 and 1 of W IORLW 0x80 ;set bit 7 of W XORLW 0x20 ;invert bit 5 of W 30

Questions Develop a sequence of instructions using only the bit- oriented and literal instructions that will add a 1 to WREG if the carry status register bit is a 1. ______________________ BTFSC STATUS, C ;skip next instruction if C = 0 ADDLW 0x01 ;add 1 if carry = 1

Questions 5. Describe what each of the following instructions accomplish: a. MOVFFWREG,0xl0,0,0 b. ADDWF 0x20, 0 c. ADDWF 0x20, 1, 1 d. DECF0x34 e. INCF 0x34, 1 __________________________ (a)copies WREG into access bank memory location 0x010, (b)adds WREG to location 0x20 in the memory bank selected by BSR with the result in WREG (c)adds WREG to location 0x20 in the memory bank selected by BSR and store the result in the memory bank (d)subtract 1 from access bank location 0x34 in the memory bank specified by BSR (e)add one to the location 0x34 in the memory bank specified by BSR 32

Questions 6. Develop a sequence of instructions that multiply the contents of the WREG register by ten. You may not use the multiply instruction. 33 UDATA Num RES 1 MOVWF Num BCF STATUS, 0 RLCF WREG BCF STATUS, 0 RLCF WREG BCF STATUS, 0 RLCF WREG ADDWF Num, 0