From Microprocessors: From Assembly Language to C Using thePIC18Fxx2

This chapter examines additional features of the PIC18Fxx2 instruction set architecture in the context of unsigned 8-bit arithmetic, bitwise logical, and shift operations. These operations are used to implement equality, inequality, and comparison tests for conditional code execution and loop control.


After reading this chapter, you will be able to:

  • Describe the operation of the bit manipulation instructions of the PIC18 instruction set.

  • Translate C language statements that perform 8-bit addition, subtraction, bitwise logical, and shift operations into PIC18 instruction sequences.

  • Translate C language statements that perform 8-bit zero, nonzero, equality, inequality, and unsigned comparison operations into PIC18 instruction sequences.

  • Translate C conditional statements and loop structures such as do-while, while-do, and for{} into PIC18 instruction sequences.


Table 4.1 lists the C language arithmetic and logical operators discussed in this book. As seen in the previous chapter, the arithmetic/logic unit (ALU) implements these operations in the processor data path. The previous chapter covered some of the arithmetic capabilities of the ALU such as addition, subtraction, increment, and decrement. The bitwise logical operators & (AND), (OR), ^ (XOR), and ~ (complement) comprise the logical operations performed by the ALU.

Table 4.1: C Language Arithmetic and Logical Operators



+, -

(+) addition, (-) subtraction

++, --

(++) increment, (--) decrement

*, /

(*) multiplication, (/) division

>>, <<

right shift (>>), left shift (<<)

&, , ^

bitwise AND (&), OR (),...

Products & Services
Arithmetic Logic Units (ALU)
Arithmetic logic units (ALU) perform arithmetic and logic operations on binary data inputs. In some processors, the ALU is divided into two units: an arithmetic unit (AU) and a logic unit (LU).
Microprocessor and IC Programmers, Compilers, and Debuggers
Microprocessor and IC programmers, compilers and debuggers are programs that translate high-level language codes into assembly (machine) code, or track and correct errors (bugs) in program code.
Microprocessor Chips (MPU)
Microprocessor chips (MPU) are silicon devices that serve as the central processing unit (CPU) in computers. They contain thousands of electronic components and use a collection of machine instructions to perform mathematical operations and move data from one memory location to another.
Computers are programmable electronic devices that accept data, execute prerecorded instructions, perform mathematical and logical operations, and output results.
Digital Signal Processors (DSP)
Digital signal processors (DSPs) are specialized microprocessors designed specifically for digital signal processing, usually in real-time. DSPs can also be used to perform general-purpose computations, but are not optimized for this function.

Topics of Interest

This chapter applies the arithmetic, logical, and shift operations discussed in the previous chapter to extended precision operands; that is, operands that are larger than 8 bits. Furthermore, signed...

Bit manipulation is an important aspect of many high-level languages. This chapter discusses the logical and bit manipulation instructions supported by the assembly language. Assembly language...

This chapter examines various higher math topics such as multiplication and division operations for unsigned and signed integers, floating-point number representation, saturating arithmetic, BCD...

This chapter introduces the hardware side of the PIC18Fxx2 by exploring reset behavior and parallel port IO. In addition, the nuances of writing C code for PIC18Fxx2 applications are examined. 8.1...

VeSPA Instruction Set Mnemonic Opcode Operation Decimal Binary NOP 0 00000 No operation ADD 1 00001 Addition SUB 2 00010 Subtraction OR 3 00011 Bit-wise logical OR AND 4 00100 Bit-wise logical AND NOT...

Product Announcements
Renesas Electronics Corporation
Honeywell Sensing and Internet of Things
Renesas Electronics Corporation