0% found this document useful (0 votes)
3 views27 pages

Assembly Instruction Reference Guide

The document provides a reference guide for assembly instructions related to data manipulation, bit manipulation, and program flow. It includes detailed descriptions, syntax, operands, operations, and examples for various instructions such as ADDLW, ANDLW, BCF, and BTFSS. Additionally, it outlines the effects of these instructions on status register flags and common program patterns.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views27 pages

Assembly Instruction Reference Guide

The document provides a reference guide for assembly instructions related to data manipulation, bit manipulation, and program flow. It includes detailed descriptions, syntax, operands, operations, and examples for various instructions such as ADDLW, ANDLW, BCF, and BTFSS. Additionally, it outlines the effects of these instructions on status register flags and common program patterns.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 27

Assembly Instruction Reference Guide

Data Manipulation Instructions


ADDLW - Add Literal and W

What it does: Adds an 8-bit literal value to the W register. Syntax: [label] ADDLW k Operands: 0 ≤ k ≤ 255
Operation: (W) + k → (W) Status Affected: C, DC, Z Example:

MOVLW 5 ; Load W with 5


ADDLW 10 ; Add 10 to W, W now equals 15
ADDWF - Add W and f

≤ 127, d ∈ {0,1} Operation: (W) + (f) → (destination) Status Affected: C, DC, Z Example:
What it does: Adds the W register to the contents of register f. Syntax: [label] ADDWF f,d Operands: 0 ≤ f

MOVLW 5 ; Load W with 5


MOVWF 20 ; Store 5 in register 20
ADDWF 20,1 ; Add W (5) to register 20, store result in register 20 (now 10)
ANDLW - AND Literal with W

What it does: Performs a bitwise AND between an 8-bit literal and the W register. Syntax: [label] ANDLW k
Operands: 0 ≤ k ≤ 255 Operation: (W) AND k → (W) Status Affected: Z Example:

MOVLW 0xF5 ; Load W with 11110101


ANDLW 0x0F ; AND with 00001111, W now equals 00000101 (0x05)
ANDWF - AND W with f

Operands: 0 ≤ f ≤ 127, d ∈ {0,1} Operation: (W) AND (f) → (destination) Status Affected: Z Example:
What it does: Performs a bitwise AND between W register and register f. Syntax: [label] ANDWF f,d

MOVLW 0xAA ; Load W with 10101010


MOVWF 30 ; Store in register 30
MOVLW 0xF0 ; Load W with 11110000
ANDWF 30,1 ; AND W (11110000) with register 30 (10101010)
; Result in register 30 is 10100000

Bit Manipulation Instructions


BCF - Bit Clear f

What it does: Clears a specific bit in register f. Syntax: [label] BCF f,b Operands: 0 ≤ f ≤ 127, 0 ≤ b ≤ 7
Operation: 0 → (f<b>) Status Affected: None Example:

MOVLW 0xFF ; Load W with 11111111


MOVWF 40 ; Store in register 40
BCF 40,3 ; Clear bit 3 of register 40, now contains 11110111
BSF - Bit Set f

What it does: Sets a specific bit in register f. Syntax: [label] BSF f,b Operands: 0 ≤ f ≤ 127, 0 ≤ b ≤ 7
Operation: 1 → (f<b>) Status Affected: None Example:

MOVLW 0x00 ; Load W with 00000000


MOVWF 50 ; Store in register 50
BSF 50,6 ; Set bit 6 of register 50, now contains 01000000

Program Flow Instructions


BTFSS - Bit Test f, Skip if Set

What it does: Tests a bit in register f and skips the next instruction if that bit is set. Syntax: [label] BTFSS
f,b Operands: 0 ≤ f ≤ 127, 0 ≤ b ≤ 7 Operation: skip if (f<b>) = 1 Status Affected: None Example:

MOVLW 0x04 ; Load W with 00000100


MOVWF 60 ; Store in register 60
BTFSS 60,2 ; Test bit 2 of register 60, it's set (1), so skip next instruction
MOVLW 0xFF ; This instruction is skipped
MOVLW 0x22 ; W is loaded with 0x22
BTFSC - Bit Test f, Skip if Clear

What it does: Tests a bit in register f and skips the next instruction if that bit is clear. Syntax: [label] BTFSC
f,b Operands: 0 ≤ f ≤ 127, 0 ≤ b ≤ 7 Operation: skip if (f<b>) = 0 Status Affected: None Example:

MOVLW 0x08 ; Load W with 00001000


MOVWF 70 ; Store in register 70
BTFSC 70,0 ; Test bit 0 of register 70, it's clear (0), so skip next instruction
MOVLW 0x33 ; This instruction is skipped
MOVLW 0x44 ; W is loaded with 0x44

Status Register Flags


These instructions affect status flags in various ways:

 Z (Zero): Set when the result of an operation is zero


 C (Carry): Set when an addition produces a carry or when a subtraction produces a borrow
 DC (Digit Carry): Set when an addition or subtraction operation produces a carry from the 4th bit (used for BCD
operations)

Common Program Patterns


Bit Checking and Branching
BTFSC PORTA,0 ; Check if bit 0 of PORTA is clear
GOTO BIT_IS_SET ; Skip if bit is set
; Code for when bit is clear
GOTO CONTINUE
BIT_IS_SET:
; Code for when bit is set
CONTINUE:
Register Clearing
MOVLW 0x00 ; Load W with 0
MOVWF COUNTER ; Clear the COUNTER register
Bit Toggle
MOVLW 0x01 ; Load W with 00000001
XORWF FLAGS,1 ; Toggle bit 0 of FLAGS register

You might also like