Pic Single-Chip assembly language learning (I.)

Source: Internet
Author: User

1, assembly language statement format:

Designator opcode (instruction mnemonic) operand;
(label) (opcode) (operand) (comment)

2. Common pseudo-directives

a.equ--Symbol name Assignment pseudo-directive
Format: symbol name Equnn

b.org--program start address define pseudo-directives
Format: orgnnnn

c.end--program end pseudo-directive
Format: END

d.list--List option pseudo-directive
Format: LIST [optional, Options, ...]

E.include: Transfer into external program file pseudo-directive
Format: INCLUDE "file name"


2. Branch program Structure

--A few notes about the application of the instructions in the program:
(1) All logical operations (with, or, XOR) and arithmetic operations (plus, minus) that require 2 numbers of participants need to be placed in W in advance. For the use of the subtraction command more attention, should be pre-placed in the "W," or "pre-put" in the number of W, in the operation as a meiosis, and the number of registers as a meiosis.
(2) A conditional jump instruction often needs to follow an unconditional jump instruction, in order to achieve long-distance transfer and the branch of the program.
(3) pic Microcontroller instruction system is not set up a dedicated stop instruction, you can use a jump to their own unconditional jump instruction Goto to achieve.

3. PIC microcontroller directive

Consists of 3 basic types of directives:
A. Byte manipulation class directives
B. bit operation class Instruction
C. Immediate count and control operation class directives

For byte Operations directive,f--> file Register identifier,d--> target Register identifier

Description: The target identifier specifies where the operation results are stored:
D=0 operation result deposited W Register
D=1 operation result is stored in the specified file register, d default value is 1

4. Instruction Set

5. Example

1;--------------------------------------------------------2 3 ; Sequential program Structure4 , 20H Unit low 4-bit out of 21H, high four-bit out of deposit to 22H5 ; key points: ANDLW and Swapf6 7;---------------------------------------------------------8MOVF 20H,0to send the contents of a 20H unit to a person W9 ANDLW 0FH; W high four-bit clear 0 low 4-bit remains unchangedTen MOVWF 21H; send the lower 4 bits after splitting to 21H OneSwapf 20H,0the 20H unit content is high and the low half byte is swapped and sent W A  - ANDLW 0FH, then the W high four bits clear 0 low four bits remain unchanged - MOVWF 22H; Send the split high four bits to the 22H unit the  -  -;-------------------------------------------------------- -  + ; Branch Program Structure - ; 20H and 21H units in RAM hold 2 numbers to find large deposits in 22H units + point: Two number subtraction, judging the value of the flag bit C A  at;--------------------------------------------------------- - status EQU 03H; Define status register address is 03H -C EQU0; Define the rounding/Borrow flag C has an address of 0 in status -MOVF 20H0to send the contents of a 20H unit to a person W -SUBWF 21H0using the contents of the 21H unit minus the contents of W, the result exists in W -BTFSS status,c; if c=1, without borrow, the number in the 21H unit is large, jumping to F21big inGOTO F20big; if c=0, with borrow, the 20H unit is larger, then jumps to F20big -      toF21big movf 21H,0to deposit the contents of 21H into the W register + MOVWF 22H; then dump it to the 22H unit. - GOTO STOP; Skip the following two instructions to the end of the program the          *F20big movf 20H,0to deposit the contents of 20H into the W register $ MOVWF 22H; then dump it to the 22H unit.Panax Notoginseng  - stop GOTO Stop; task complete, stop, stand still the  +  A;-------------------------------------------------------- the  + ; Cyclic program Structure - in the data memory, 50 cells starting from address 30H are all written to 00H $ ; Important: The indirection register FSR as the address pointer $  -;--------------------------------------------------------- - COUNT EQU 20H; Specify the 20H unit as the counter (i.e. loop variable) the FSR EQU 04H; define FSR Register address of 04H - indf EQU 00H; set INDF register address is 00HWuyi MOVLW D50; the counter initial value 50 is fed into W the MOVWF COUNT; then turn 50 into the counter (as the operating value of the loop variable) - MOVLW 30H; put 30H (start address) into W Wu MOVWF FSR; turn 30H into Register FSR (used as address pointer) -          About NEXT CLRF indf; Clear 0 of the units specified with the FSR content as addresses $INCF FSR,1address pointer content plus 1, pointing to the next cell -Decfsz COUNT,1, the count is reduced by 1, and the result is 0. Skip to the next instruction to stop - Goto next; Jump back and perform the next loop - stop GOTO Stop; Execute the statement after the loop is completed to achieve downtime A  +;-------------------------------------------------------- the  - ; sub-Program Structure $ 3-digit maximum is placed in a 40H unit the  the;--------------------------------------------------------- the STATUS EQU 03H the C EQU 00H - X EQU 20H in Y EQU 21H the Z EQU 22H the;-------------------------------------------------------- About  the ; Main program the  the;--------------------------------------------------------- +  -MAIN movf 30H,0 the MOVWF XBayiMOVF 21H,0 the MOVWF Y the Call SUB -MOVF Z,0 - MOVWF X theMOVF 32H,0 the MOVWF Y the Call SUB theMOVF Z,0 - MOVWF 40H the Stop GOTO Stop the;-------------------------------------------------------- the 94 ; subroutine: (Entry parameters: X and y, exit parameters: Z) the  the;--------------------------------------------------------- theSUB movf X,0to send x content to a person W98SUBWF Y,0        ; Y content minus W content, results are deposited w AboutBTFSS status,c; if c=1, does not occur borrow, executes next, otherwise jumps - GOTO X_big101         102Y_big movf Y,0The data in Y is fed into w103 MOVWF z; and then dump it to Z.104 GOTO theend; Skip the following two to the end the         106X_big movf X,0The data in X is fed into W107 MOVWF z; and then dump it to Z.108TheEND return; sub-program returns

Pic Single-Chip assembly language learning (I.)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.