100% found this document useful (1 vote)
148 views

Assembly Program Assembly Commands PIC 16F84A Instruction Set

The document outlines assembly language syntax and instructions for the PIC16F84A microcontroller. It discusses assembly commands, which are composed of labels, mnemonics, operands, and comments. It then provides examples of over 30 instructions including MOVLW, MOVWF, BCF, BSF, CALL, RETURN, ADDWF, SUBWF, ANDWF, XORWF and others. The instructions manipulate data in registers and I/O ports through operations like moving data, testing/setting bits, increments, additions and logical operations.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
148 views

Assembly Program Assembly Commands PIC 16F84A Instruction Set

The document outlines assembly language syntax and instructions for the PIC16F84A microcontroller. It discusses assembly commands, which are composed of labels, mnemonics, operands, and comments. It then provides examples of over 30 instructions including MOVLW, MOVWF, BCF, BSF, CALL, RETURN, ADDWF, SUBWF, ANDWF, XORWF and others. The instructions manipulate data in registers and I/O ports through operations like moving data, testing/setting bits, increments, additions and logical operations.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

12/15/2014

TOPIC OUTLINE: ASSEMBLY LANGUAGE

Assembly Program Syntax


 rules by which the words in a program
 Assembly Commands are combined to form commands to a
 PIC 16F84A Instruction computer

Set

ASSEMBLY LANGUAGE ASSEMBLY LANGUAGE


Assembly Commands
Assembly Commands
 composed of the following columns:
 composed of the following columns:
b. Command
a. Label
- consists of mnemonic form of the
- used to equate to a value or indicate
instruction for the processor
a program destination address for
- only mnemonics specified in the
jumps
instruction set may be used
- human-readable alias for an address
Mnemonic
in memory
-human-readable representation of each
opcode

ASSEMBLY LANGUAGE ASSEMBLY LANGUAGE


Assembly Commands Literal Value Specifications
 composed of the following columns: TYPE SYNTAX EXAMPLE
c. Operand
- the operator's argument in an Binary B ‘binary_digits’ B ‘00001101’

assembly language instruction Octal O ‘octal_digits’ O ‘123’


- may be data or register contents to
Decimal D ‘digits’ D ‘255’
be used in the instruction
H ‘hex_digits’ H ‘9F’
Hexadecimal
0xhex_digits 0x9F

1
12/15/2014

ASSEMBLY LANGUAGE SINGLE REGISTER OPERATIONS

Assembly Commands
 composed of the following columns:
d. Comment
- always begins with a semicolon
- explanatory text on any line of code
that can help the programmer and
user to understand the program
- have no effect on the operation of
the program

REGISTER PAIR OPERATIONS PROGRAM EXECUTION

PROGRAM BIN1 ASSEMBLY LANGUAGE


Instructions Set
• MOVLW
- Write constant in W register
Syntax: [label] MOVLW k

Example:
MOVLW 0x5A

2
12/15/2014

ASSEMBLY LANGUAGE ASSEMBLY LANGUAGE


Instructions Set Instructions Set
• MOVWF • MOVF
- Copy W to F - Copy f to d
Syntax: [label] MOVWF f Syntax: [label] MOVF f , d
Example:
Example: MOVLW 55H
MOVLW 55H MOVWF 05H
MOVWF 05H MOVF 05H , 0
MOVWF PORTB

ASSEMBLY LANGUAGE ASSEMBLY LANGUAGE


Instructions Set Instructions Set
• BCF • BSF
- Reset bit b in f - Set bit b in f
Syntax: [label] BCF f , b Syntax: [label] BSF f , b

Example: Example:
MOVLW 1FH MOVLW 10H
MOVWF PORTA MOVWF PORTB
BCF PORTA , 0 BSF PORTB , 4

ASSEMBLY LANGUAGE ASSEMBLY LANGUAGE


Instructions Set Instructions Set
• GOTO • RETURN
- Jump to address - Return from a subprogram
Syntax: [label] GOTO k Syntax: [label] RETURN

Example: Example:
GOTO on RETURN
on MOVLW 0x0F
MOVWF PORTB

3
12/15/2014

ASSEMBLY LANGUAGE
ASSEMBLY LANGUAGE
Instructions Set
• CALL Instructions Set
- Call a program • BTFSC
Syntax: [label] CALL k - Test bit b in f, skip if it is zero
Syntax: [label] BTFSC f , b
Example:
CALL on Example:
GOTO start BTFSC PORTA , 0
on MOVLW 0x0F GOTO off
MOVWF PORTB GOTO on
RETURN

ASSEMBLY LANGUAGE ASSEMBLY LANGUAGE


Instructions Set Instructions Set
• BTFSS • INCF
- Test bit b in f, skip if it is one - Increment f
Syntax: [label] BTFSS f , b Syntax: [label] INCF f , d

Example: Example:
BTFSS PORTA , 0 MOVLW 00H
GOTO off MOVWF PORTB
GOTO on INCF PORTB , 1

ASSEMBLY LANGUAGE ASSEMBLY LANGUAGE


Instructions Set Instructions Set
• DECF • INCFSZ
- Decrement f - Increment f, skip = 0
Syntax: [label] DECF f , d Syntax: [label] INCFSZ f , d
Example:
Example: start MOVLW 00H
MOVLW 1FH MOVWF PORTA
MOVWF PORTA inc INCFSZ PORTA , 1
DECF PORTA , 0 GOTO inc
GOTO start

4
12/15/2014

ASSEMBLY LANGUAGE ASSEMBLY LANGUAGE


Instructions Set Instructions Set
• DECFSZ • ADDLW
- Decrement f, skip = 0 - Add W to a constant
Syntax: [label] DECFSZ f , d Syntax: [label] ADDLW k
Example: Example:
start MOVLW 1FH MOVLW 25H
MOVWF PORTA ADDLW 34H
dec DECFSZ PORTA , 1
GOTO dec
GOTO start

ASSEMBLY LANGUAGE ASSEMBLY LANGUAGE


Instructions Set Instructions Set
• ADDWF • SUBLW
- Add W to F - Subtract W from a constant
Syntax: [label] ADDWF f , d Syntax: [label] SUBLW k
Example: Example:
MOVLW 22H MOVLW 22H
MOVWF PORTA SUBLW 55H
MOVWF PORTB
ADDWF PORTA , 0
ADDWF PORTB , 1

ASSEMBLY LANGUAGE ASSEMBLY LANGUAGE


Instructions Set Instructions Set
• SUBWF • ANDLW
- Subtract W from f - Logic AND W with constant
Syntax: [label] SUBWF f , d Syntax: [label] ANDLW k
Example: Example:
MOVLW 22H MOVLW 22H
MOVWF PORTA ANDLW 10H
SUBWF PORTA , 1

5
12/15/2014

ASSEMBLY LANGUAGE ASSEMBLY LANGUAGE


Instructions Set Instructions Set
• ANDWF • IORLW
- Logic AND W with f - Logic OR W with constant
Syntax: [label] ANDWF f , d Syntax: [label] IORLW k
Example: Example:
MOVLW 22H MOVLW 22H
MOVWF PORTA IORLW 1AH
MOVLW 10H
ANDWF PORTA , 1

ASSEMBLY LANGUAGE ASSEMBLY LANGUAGE


Instructions Set Instructions Set
• IORWF • XORLW
- Logic OR W with f - Logic Exclusive OR W with constant
Syntax: [label] IORWF f , d Syntax: [label] XORLW k
Example: Example:
MOVLW 22H MOVLW B5H
MOVWF PORTB XORLW 1AH
MOVLW 13H
IORWF PORTB , 0

ASSEMBLY LANGUAGE ASSEMBLY LANGUAGE


Instructions Set Instructions Set
• XORWF • RLF
- Logic Exclusive OR W with f - Rotate f to the left through CARRY
Syntax: [label] XORWF f , d Syntax: [label] RLF f , d
Example: Example:
MOVLW B5H MOVLW 1AH
MOVWF PORTB MOVWF PORTB
XORWF PORTB , 1 RLF PORTB , 1

6
12/15/2014

ASSEMBLY LANGUAGE ASSEMBLY LANGUAGE


Instructions Set Instructions Set
• RRF • COMF
- Rotate f to the right through CARRY - Complement f
Syntax: [label] RLF f , d Syntax: [label] COMF f , d
Example: Example:
MOVLW 1AH MOVLW 1AH
MOVWF PORTB MOVWF PORTB
RRF PORTB , 0 COMF PORTB , 0

ASSEMBLY LANGUAGE ASSEMBLY LANGUAGE


Instructions Set Instructions Set
• CLRW • CLRF
- Write 0 in W - Write 0 in f
Syntax: [label] CLRW Syntax: [label] CLRF f
Example: Example:
MOVLW 1AH MOVLW 1AH
CLRW MOVWF PORTA
CLRF PORTA

ASSEMBLY LANGUAGE ASSEMBLY LANGUAGE


Instructions Set Instructions Set
• SWAPF • RETLW
- Copy the nibbles from f to d crosswise - Return from a subprogram w/ constant
Syntax: [label] SWAPF f , d in W
Example: Syntax: [label] RETLW k
MOVLW 1AH Example:
MOVWF PORTA
SWAPF PORTA , 0 RETLW 0x23

7
12/15/2014

ASSEMBLY LANGUAGE ASSEMBLY LANGUAGE


Instructions Set Instructions Set
• RETFIE • NOP
- Return from interrupt routine - No operation
Syntax: [label] RETFIE Syntax: [label] NOP
Example: Example:
MOVLW 23H
RETFIE MOVWF PORTB
NOP
NOP

ASSEMBLY LANGUAGE ASSEMBLY LANGUAGE


Instructions Set Instructions Set
• CLRWDT • SLEEP
- Initialize watchdog timer - Standby mode
Syntax: [label] CLRWDT Syntax: [label] SLEEP
Example: Example:
CLRWDT SLEEP

ASSEMBLY LANGUAGE ASSEMBLY LANGUAGE


SEATWORK SEATWORK
1. Write a program to load a value 0AH, 3. Write a program to add the values
and 1FH into PORTA and PORTB 16H and CDH. Place the result in the
respectively. W register.
2. Write a program to get data from 4. Write a program to get data from
PORTA and send it to the PORTB PORTA. Add the value 05H to it and
continuously. send it to PORTB

You might also like