pic assembly launguge refference

27
PIC Assembly Language Reference - 243  Appendix D: PIC Assembly Language Reference PIC Assembly is the lowest-lev el programming lanugage for Microchip PIC microcontroll ers. These processors are used on the LogoChip and LogoChip modules, the LogoBoard, the PIC Foundation, and every layer in the Tower system.  When using PIC Assembly , user programs are entered on a desktop computer and assembled into byte codes that are transferred to the PIC processor through the serial port of the host computer . Our assembly lang uage differs in some ways fro m the commercially-a vailable one . It is designed to be more human-readable than the standard instruction set, and can be easily modied to support other processors while retaining its user-friendly naming scheme.  As in all assembly-level programming, computati on is perfor med in an “accumulator” scratch register ,  which is modied as needed by the different processor instr uctions .  The basic instruction for mat uses square brackets to frame each instruction: [instruction argument] Program location labels are dened by plain text, with no brackets: program-label Constants are used to dene memory location s for both built-in registers and variab le storage. A con- stant is dened like this: [const name address] Memory addresses can be denoted either in decimal or hexidecimal format, as indicated by placing a “$” character in front of the number.  The status register, at memory location “$03”, is a special one o n the processor . It has user-readab le ags that represent different conditions , which can be triggered by the results of various instructions . In most cases, the two status ags that one would be most concerned with are: • C - The car ry ag, which is set when an instruction overows a register . • Z - The zero ag, which is set when the result of an instruction is “0”.

Upload: kishore435

Post on 09-Apr-2018

226 views

Category:

Documents


0 download

TRANSCRIPT

8/7/2019 PIC Assembly Launguge Refference

http://slidepdf.com/reader/full/pic-assembly-launguge-refference 1/27

PIC Assembly Language Reference - 243

 Appendix D: PIC Assembly Language Reference

PIC Assembly is the lowest-level programming lanugage for Microchip PIC microcontrollers. These

processors are used on the LogoChip and LogoChip modules, the LogoBoard, the PIC Foundation,

and every layer in the Tower system.

 When using PIC Assembly, user programs are entered on a desktop computer and assembled into byte

codes that are transferred to the PIC processor through the serial port of the host computer.

Our assembly language differs in some ways from the commercially-available one. It is designed to be

more human-readable than the standard instruction set, and can be easily modied to support other

processors while retaining its user-friendly naming scheme.

 As in all assembly-level programming, computation is performed in an “accumulator” scratch register, which is modied as needed by the different processor instructions.

 The basic instruction format uses square brackets to frame each instruction:

[instruction argument]

Program location labels are dened by plain text, with no brackets:

program-label

Constants are used to dene memory locations for both built-in registers and variable storage. A con-

stant is dened like this:

[const name address]

Memory addresses can be denoted either in decimal or hexidecimal format, as indicated by placing a

“$” character in front of the number.

 The status register, at memory location “$03”, is a special one on the processor. It has user-readable

ags that represent different conditions, which can be triggered by the results of various instructions.

In most cases, the two status ags that one would be most concerned with are:

• C - The carry ag, which is set when an instruction overows a register.

• Z - The zero ag, which is set when the result of an instruction is “0”.

8/7/2019 PIC Assembly Launguge Refference

http://slidepdf.com/reader/full/pic-assembly-launguge-refference 2/27

244 - PIC Assembly Language Reference

Program Flow 

bsr - branch subroutine 246

rts - return from subroutine 246

rtv - return from subroutine with value 247

bra - unconditional branch 247

rti - return from interrupt 248

Register Manipulation

lda - load accumulator 248

ldan - load accumulator with number 248

sta - store accumulator 249

tst - test 249

clr - clear 250

clr - clear accumulator 250

inc - increment 251

linc - load and increment 251

incsz - increment skip if zero 252

lincsz - load and increment skip if zero 252

dec - decrement 253ldec - load and decrement 253

decsz - decrement skip if zero 254

ldecsz - load and decrement skip if zero 254

rol - rotate left 255

lrol - load and rotate left 255

ror - rotate right 256

lror - load and rotate right 256

com - complement 257

lcom - load and complement 257

swap - swap 258

lswap - load and swap 258

 What follows, is a list of all instructions currently supported in the PIC Assembler. The instructions

are organized by their functionality, for ease of reference when the exact name is not known. The list

below represents the order in which their detailed descriptions and examples of use can be found on

the subsequent pages:

8/7/2019 PIC Assembly Launguge Refference

http://slidepdf.com/reader/full/pic-assembly-launguge-refference 3/27

8/7/2019 PIC Assembly Launguge Refference

http://slidepdf.com/reader/full/pic-assembly-launguge-refference 4/27

8/7/2019 PIC Assembly Launguge Refference

http://slidepdf.com/reader/full/pic-assembly-launguge-refference 5/27

PIC Assembly Language Reference - 247

rtv - return from subroutine with valueProgram Flow 

Description

Returns from a subroutine with a value stored in the accumulator. The top value on the stack 

is popped and loaded into the program counter, returning to the program location of the most

recently called bsr instruction.

Usage Format

[rtv number]

The number argument is the value to return.

Status Flags Affected

  None

bra - unconditional branchProgram Flow 

Description

Branches to a given memory location.

Usage Format

[bra address]

 

 The address argument is a number corresponding to a program memory location, usually 

specied by the name of a location label.

Status Flags Affected  None

8/7/2019 PIC Assembly Launguge Refference

http://slidepdf.com/reader/full/pic-assembly-launguge-refference 6/27

248 - PIC Assembly Language Reference

rti - return from interruptProgram Flow 

Description

Returns from an interrupt. The top value on the stack is popped and loaded into the program

counter, returning to the program location at the time of interrupt.

Usage Format

[rti]

Status Flags Affected

  None

lda - load accumulatorRegister Manipulation 

Description

Loads the accumulator with the contents of a register.

Usage Format

[lda register]

 

 The register argument is the address of any register.

Status Flags Affected

  Z

ldan - load accumulator with numberRegister Manipulation 

Description

Loads the accumulator with a number.

8/7/2019 PIC Assembly Launguge Refference

http://slidepdf.com/reader/full/pic-assembly-launguge-refference 7/27

PIC Assembly Language Reference - 249

Usage Format

[ldan number]

 

 The number argument is the value to be loaded into the accumulator.

Status Flags Affected

  None

sta - store accumulatorRegister Manipulation 

Description

Stores the contents of the accumulator in a register.

Usage Format

[lda register]

 

 The register argument is the address of any register.

Status Flags Affected

  Z

tst - testRegister Manipulation 

Description

 Tests the value of a register and sets the zero ag if the contents of the register is equal to“0”.

Usage Format

[tst register]

 

8/7/2019 PIC Assembly Launguge Refference

http://slidepdf.com/reader/full/pic-assembly-launguge-refference 8/27

250 - PIC Assembly Language Reference

 The register argument is the address of any register.

Status Flags Affected

  Z

clr - clearRegister Manipulation 

Description

Sets the contents of a register to “0”.

Usage Format

[clr register]

 

 The register argument is the address of any register.

Status Flags Affected

  Z

clra - clear accumulatorRegister Manipulation 

Description

Sets the contents of the accumulator to “0”.

Usage Format

[clra]

Status Flags Affected

  Z

8/7/2019 PIC Assembly Launguge Refference

http://slidepdf.com/reader/full/pic-assembly-launguge-refference 9/27

PIC Assembly Language Reference - 251

inc - incrementRegister Manipulation 

Description

Increments the contents of a register and stores the result in the register.

Usage Format

[inc register]

 

 The register argument is the address of any register.

Status Flags Affected

  Z

linc - load and incrementRegister Manipulation 

Description

Increments the contents of a register and stores the result in the accumulator.

Usage Format

[linc register]

 

 The register argument is the address of any register.

Status Flags Affected

  Z

8/7/2019 PIC Assembly Launguge Refference

http://slidepdf.com/reader/full/pic-assembly-launguge-refference 10/27

8/7/2019 PIC Assembly Launguge Refference

http://slidepdf.com/reader/full/pic-assembly-launguge-refference 11/27

PIC Assembly Language Reference - 253

dec - decrementRegister Manipulation 

Description

Decrements the contents of a register and stores the result in the register.

Usage Format

[dec register]

 

 The register argument is the address of any register.

Status Flags Affected

  Z

ldec - load and decrementRegister Manipulation 

Description

Decrements the contents of a register and stores the result in the accumulator.

Usage Format

[ldec register]

 

 The register argument is the address of any register.

Status Flags Affected

  Z

8/7/2019 PIC Assembly Launguge Refference

http://slidepdf.com/reader/full/pic-assembly-launguge-refference 12/27

254 - PIC Assembly Language Reference

decsz - decrement skip if zeroRegister Manipulation 

Description

Decrements the contents of a register and stores the result in the register. If the result of the

operation is zero, the next program instruction is skipped.

Usage Format

[decsz register]

 

 The register argument is the address of any register.

Status Flags Affected

  None

ldecsz - load and decrement skip if zeroRegister Manipulation 

Description

Decrements the contents of a register and stores the result in the accumulator. If the resultof the operation is zero, the next program intsruction is skipped.

Usage Format

[ldecsz register]

 

 The register argument is the address of any register.

Status Flags Affected  None

8/7/2019 PIC Assembly Launguge Refference

http://slidepdf.com/reader/full/pic-assembly-launguge-refference 13/27

PIC Assembly Language Reference - 255

rol - rotate leftRegister Manipulation 

Description

 The contents of a register are rotated to the left through the carry ag and the result is stored

in the register.

Usage Format

[rol register]

 

 The register argument is the address of any register.

Status Flags Affected

  C

lrol - load and rotate leftRegister Manipulation 

Description

 The contents of a register are rotated to the left through the carry ag and the result is storedin the accumulator.

Usage Format

[lrol register]

 

 The register argument is the address of any register.

Status Flags Affected  C

8/7/2019 PIC Assembly Launguge Refference

http://slidepdf.com/reader/full/pic-assembly-launguge-refference 14/27

8/7/2019 PIC Assembly Launguge Refference

http://slidepdf.com/reader/full/pic-assembly-launguge-refference 15/27

8/7/2019 PIC Assembly Launguge Refference

http://slidepdf.com/reader/full/pic-assembly-launguge-refference 16/27

258 - PIC Assembly Language Reference

swap - swapRegister Manipulation 

Description

 The upper and lower halves of a register are swapped and the result is stored in the register.

Usage Format

[swap register]

 

 The register argument is the address of any register.

Status Flags Affected

  None

lswap - load and swapRegister Manipulation 

Description

 The upper and lower halves of a register are swapped and the result is stored in the accumula-

tor.

Usage Format

[lswap register]

 

 The register argument is the address of any register.

Status Flags Affected

  None

8/7/2019 PIC Assembly Launguge Refference

http://slidepdf.com/reader/full/pic-assembly-launguge-refference 17/27

PIC Assembly Language Reference - 259

bset - bit setBit Manipulation 

Description

Makes the value of a given bit of a register equal to “1”.

Usage Format

[bset bit register]

 

 The bit argument is any bit number (from 0 to 7) and the register argument is the address of 

any register.

Status Flags Affected

  None

bclr - bit clearBit Manipulation 

Description

Makes the value of a given bit of a register equal to “0”.

Usage Format

[bclr bit register]

 

 The bit argument is any bit number (from 0 to 7) and the register argument is the address of 

any register.

Status Flags Affected  None

8/7/2019 PIC Assembly Launguge Refference

http://slidepdf.com/reader/full/pic-assembly-launguge-refference 18/27

260 - PIC Assembly Language Reference

btss - bit test skip if setBit Manipulation 

Description

 Tests the value of a given bit of a register. If it is equal to “1,” the next program instruction

is skipped.

Usage Format

[btss bit register]

 

 The bit argument is any bit number (from 0 to 7) and the register argument is the address of 

any register.

Status Flags Affected

  None

btsc - bit test skip if clearBit Manipulation 

Description Tests the value of a given bit of a register. If it is equal to “0,” the next program instruction

is skipped.

Usage Format

[btsc bit register]

 

 The bit argument is any bit number (from 0 to 7) and the register argument is the address of 

any register.

Status Flags Affected

  None

8/7/2019 PIC Assembly Launguge Refference

http://slidepdf.com/reader/full/pic-assembly-launguge-refference 19/27

PIC Assembly Language Reference - 261

add - add Arithmetic 

Description

 Adds the contents of the accumulator to a reguster and stores the result in the accumulator.

Usage Format

[add register]

 

 The register argument is the address of any register.

Status Flags Affected

  Z, C

addm - add to memory Arithmetic 

Description

 Adds the contents of the accumulator to a register and stores the result in the register.

Usage Format

[addm register]

The register argument is the address of any register.

Status Flags Affected

  Z, C

8/7/2019 PIC Assembly Launguge Refference

http://slidepdf.com/reader/full/pic-assembly-launguge-refference 20/27

262 - PIC Assembly Language Reference

addn - add number Arithmetic 

Description

 Adds the conents of the accumulator to a number and stores the result in the accumulator.

Usage Format

[addn number]

The number argument is the value to be added to.

Status Flags Affected

  Z, C

sub - subtract Arithmetic 

Description

Subtracts the contents of the accumulator from a register and stores the result in the accu-

mulator.

Usage Format

[sub register]

 

 The register argument is the address of any register.

Status Flags Affected

  Z, C (C=0 means result is negative)

8/7/2019 PIC Assembly Launguge Refference

http://slidepdf.com/reader/full/pic-assembly-launguge-refference 21/27

PIC Assembly Language Reference - 263

subm - subtract from memory Arithmetic 

Description

Subtracts the contents of the accumulator from a register and stores the result in the register.

Usage Format

[subm register]

The register argument is the address of any register.

Status Flags Affected

  Z, C (C=0 means result is negative)

subn - subtract number Arithmetic 

Description

Subtracts the contents of the accumulator from a number and stores the result in the accu-

mulator.

Usage Format

[subn number]

The number argument is the value to be subtracted from.

Status Flags Affected

  Z, C (C=0 means result is negative)

8/7/2019 PIC Assembly Launguge Refference

http://slidepdf.com/reader/full/pic-assembly-launguge-refference 22/27

264 - PIC Assembly Language Reference

and - andLogic 

Description

Performs a bit-wise “and” of the contents of the accumulator with a reguster and stores the

result in the accumulator.

Usage Format

[and register]

 

 The register argument is the address of any register.

Status Flags Affected

  Z, C

andm - and memoryLogic 

Description

Performs a bit-wise “and” of the contents of the accumulator with a reguster and stores the

result in the register.

Usage Format

[andm register]

The register argument is the address of any register.

Status Flags Affected

  Z

8/7/2019 PIC Assembly Launguge Refference

http://slidepdf.com/reader/full/pic-assembly-launguge-refference 23/27

PIC Assembly Language Reference - 265

andn - and numberLogic 

Description

Performs a bit-wise “and” of the contents of the accumulator with a number and stores the

result in the accumulator.

Usage Format

[andn number]

The number argument is the value to “and” the accumulator with.

Status Flags Affected

  Z

or - orLogic 

Description

Performs a bit-wise “or” of the contents of the accumulator with a reguster and stores theresult in the accumulator.

Usage Format

[or register]

 

 The register argument is the address of any register.

Status Flags Affected  Z, C

8/7/2019 PIC Assembly Launguge Refference

http://slidepdf.com/reader/full/pic-assembly-launguge-refference 24/27

266 - PIC Assembly Language Reference

orm - or memoryLogic 

Description

Performs a bit-wise “or” of the contents of the accumulator with a reguster and stores the

result in the register.

Usage Format

[orm register]

The register argument is the address of any register.

Status Flags Affected

  Z

orn - or numberLogic 

Description

Performs a bit-wise “or” of the contents of the accumulator with a number and stores theresult in the accumulator.

Usage Format

[orn number]

The number argument is the value to “or” the accumulator with.

Status Flags Affected

  Z

8/7/2019 PIC Assembly Launguge Refference

http://slidepdf.com/reader/full/pic-assembly-launguge-refference 25/27

PIC Assembly Language Reference - 267

xor - exclusive orLogic 

Description

Performs a bit-wise “xor” of the contents of the accumulator with a reguster and stores the

result in the accumulator.

Usage Format

[xor register]

 

 The register argument is the address of any register.

Status Flags Affected

  Z, C

xorm - exclusive or memoryLogic 

Description

Performs a bit-wise “xor” of the contents of the accumulator with a reguster and stores theresult in the register.

Usage Format

[xorm register]

The register argument is the address of any register.

Status Flags Affected

  Z

8/7/2019 PIC Assembly Launguge Refference

http://slidepdf.com/reader/full/pic-assembly-launguge-refference 26/27

268 - PIC Assembly Language Reference

xorn - exclusive or numberLogic 

Description

Performs a bit-wise “or” of the contents of the accumulator with a number and stores the

result in the accumulator.

Usage Format

[xorn number]

The number argument is the value to “xor” the accumulator with.

Status Flags Affected

  Z

nop - no operationSystem Commands 

Description

Does nothing. Usually used to perform precise timing operations.

Usage Format

[nop]

Status Flags Affected

  None

8/7/2019 PIC Assembly Launguge Refference

http://slidepdf.com/reader/full/pic-assembly-launguge-refference 27/27

sleep - sleepSystem Commands 

Description

Puts the processor to sleep, a mode where its power consumption is signicantly reduced. It

cannot perform any computation while in this state, but can be awakened by interrupts.

Usage Format

[sleep]

Status Flags Affected

  None

clrwdt - clear watchdog timerSystem Commands 

Description

Resets the value of the internal watchdog timer.

Usage Format

[clrwdt]

Status Flags Affected

  None