Tag: value addressing CFS top instruction specifying unit main SWA
Sequential program Structure
20H Unit Low 4-bit out of 21H, high four-bit out of the deposit to 22H
Highlights: ANDLW and SWAPF
MOVF 20H,0 ;将20H单元的内容送人W ANDLW 0FH ;W高四位清零低4位保持不变 MOVWF 21H ;将拆分后的低4位送21H SWAPF 20H,0 ;将20H单元内容高、低半字节换位后送W ANDLW 0FH ;再将W高四位清0低四位保持不变 MOVWF 22H ;将拆分后的高四位送22H单元
Branch Program Structure
20H and 21H units in RAM hold 2 numbers to find large deposits in 22H units
Important: Two number subtraction, judging the value of the flag bit C
STATUS EQU 03H ;定义STATUS寄存器地址为03HC EQU 0 ;定义进位/借位标志C在STATUS中得地址为0 MOVF 20H 0 ;将20H单元的内容送人W SUBWF 21H 0 ;用21H单元的内容减去W中的内容,结果存在W中 BTFSS STATUS,C ;若C=1,没借位,则21H单元中的数大,跳到F21BIG GOTO F20BIG ;若C=0,有借位,20H单元中得数较大,则跳至F20BIG F21BIG MOVF 21H,0 ;将21H中的内容存入W寄存器 MOVWF 22H ;再将它转存到22H单元 GOTO STOP ;跳过下面两条指令到程序末尾 F20BIG MOVF 20H,0 ;将20H中的内容存入W寄存器 MOVWF 22H ;再将它转存到22H单元STOP GOTO STOP ;任务完成,停机,原地踏步
Cyclic program Structure
In data memory, 50 cells starting at address 30H are all written to 00H
Important: The indirection register FSR as the address pointer
COUNT EQU 20H ;指定20H单元作为循坏次数计数器(即循环变量)FSR EQU 04H ;定义FSR寄存器地址为04HINDF EQU 00H ;设定INDF寄存器地址为00H MOVLW D50 ;把计数器初值50送入W MOVWF COUNT ;再把50转入计数器(作为循环变量的操作值) MOVLW 30H ;把30H(起始地址)送入W MOVWF FSR ;再把30H转入寄存器FSR(用作地址指针) NEXT CLRF INDF ;把以FSR内容为地址所指定的单元清0 INCF FSR,1 ;地址指针内容加1,指向下一单元 DECFSZ COUNT,1 ;计数值减1,结果为0就跳过到下一条指令到STOP处 GOTO NEXT ;跳转回去并执行下一次循环STOP GOTO STOP ;循环结束之后执行该语句,实现停机
Sub-Program Structure
3-digit Max put into 40H unit
STATUS EQU 03HC EQU 00HX EQU 20HY EQU 21HZ EQU 22H
Main program
MAIN MOVF 30H,0 MOVWF X MOVF 21H,0 MOVWF Y CALL SUB MOVF Z,0 MOVWF X MOVF 32H,0 MOVWF Y CALL SUB MOVF Z,0 MOVWF 40HSTOP GOTO STOP
Sub-Program
Subroutines: (Entry parameters: X and y, exit parameters: Z)
SUB MOVF X,0 ;将X内容送人W SUBWF Y,0 ;Y内容减去W内容,结果存入W BTFSS STATUS,C ;若C=1,没有发生借位,执行下一条,否则跳转 GOTO X_BIG Y_BIG MOVF Y,0 ;将Y中的数据送入W MOVWF Z ;再将它转存到Z GOTO THEEND ;跳过下面两条到末尾 X_BIG MOVF X,0 ;将X中的数据送入W MOVWF Z ;再将它转存到ZTHEEND RETURN ;子程序返回
Pic Compilation Getting Started sample