Assembly Language For Pic16f877a Microcontroller
Assembly Language For Pic16f877a Microcontroller
PIC ASSEMBLY
LANGUAGE
Lecture (5)
Dr.Tarek Barhoum
2019 -2020
Learning Outcomes
2
At the end of this topic, students should be able to:
Differentiate high level, assembly and machine language
Define the terms : opcode/mnemonic, operand, label, comment,
machine code.
Classify PIC16F877 instruction set into the following groups:
data movement, arithmetic, logic, branch and other instructions.
Explain the function of PIC16F877 status register and the
changes to the flags when related instructions are executed.
Explain the stack process according to LIFO & FIFO concept
and the instructions related to stack.
Programming Language
3
The lowest-level language is called
Machine languages. It means those
languages which are closer to the
understanding of machine rather than
human beings. A machine language thus
comprises a string of binary O’s and 1’s.
Machine language is actually a coded set
of instructions for a particular CPU
(Central Processing Unit), and it is also
known as a machine code.
A machine language is designed to be
used by a computer without the need of
translation.
Machine Language
4
Disadvantage :
1. It is a machine dependent programming language.
Machine dependent means the program designed in one type
of machine or computer could not be run on other type of
computer or machine. So programs designed in the machine
language in one computer are not easily portable to other
computers.
Assembler Process
High-level language
6
High-Level Language overcomes the limitation of
writing a program in Machine and Assembly
language as it is difficult and time consuming.
In High-Level Language, the programs can be
written using simple English words. Examples of
High-Level Language are BASIC, Fortran,
COBOL, C, C++.
Programs written in high-level languages are
translated into machine language by a compiler.
Assembly language syntax
7
An assembly language program consists of statements. The
syntax of an assembly language program statement obeys
the following rules:
ORG - Origin
Sets the current origin to a new value. This is used to set the program or register address
during assembly. For example, ORG 0x00 tells the assembler to assemble all
subsequent code starting at address 0000H.
INCLUDE
An assembler include, or header, file is any file containing valid assembly code.
Usually, the file contains device-specific register and bit assignments. This file may
be “included” in the code so that it may be reused by many programs. As an example,
to add the standard header file for the PIC16F877 device to your assembly code, use:
#INCLUDE P16F877.INC
END
This directive is the last statement in an assembly language program. The END
directive terminates an assembly language program.
PIC Assembly Code
11
Consists of 4 fields: 3
operand
1 2 4
e.g. _2NDLOOP
be an assembler reserved word (mnemonic, directive, etc.).
Instruction format – Label
13
Labels may be up to 32 characters long.
By default they are case sensitive, but case
Here NOP
GOTO Here
Instruction format - Opcode
14
This field consists of a symbolic operation code,
known as op-code.
The opcode describes the operation.
LOGIC Logic operations are carried out on bit ANDWF, ANDLW, IORWF,
pairs in two numbers to give the result IORLW, XORWF, XORLW
which would be obtained if they were fed
to the corresponding logic gate
TEST, SKIP & JUMP make decisions (conditional program BTFSC, BTFSS, DECFSZ,
branches) which depend on some input INCFSZ, GOTO, CALL,
condition or the result of a calculation RETURN, RETLW, RETFIE
59
59
In contrast to the Queue (Q):
onlyone pointer to top element.
PUSH and POP/PULL in different directions.
wrap-around is not needed.
(PUSH)
Direction of
PULL operation 60
The two fundamental operations:
60
1. Push
- push an element on the top
- PUSH should first decrement SP, $00FB
$00FC
then store the data, $00FD
$00FE
- Example:
Note: [ ] means the location pointed by SP
61
2. Pull
61
- pull the top element from the stack
- removes an item from the top of the
list, and returns this value to the caller.
- Instruction used : X = $10, SP=[SP]+1
10
67
References
64
PIC Instruction Set and Some Tips for Programming,
Dr. Charles J. Kim, Howard University
Microchip PIC16F87X Data Sheet
Getting Started with Development Tools,
Microchip.com
Stack, http://en.wikipedia.org