I'm relatively new as far as assembly programming for PIC's go, actually yesterday was the first day I used assembly language. I'm trying to program a PIC16F84 to perform pretty simple operations. I need it to increment when the opcode(stored in 0x22) is 0x00, decrement when its 0x01, complement when its 0x02, and clear when it's 0x03. The operations need to be performed on registers 0x30 through 0x37, depending on what 0x20 is. If 0x20 is a value of 2, then operations will be performed twice (the value of the register will be decremented until 0 is reached) I coded what I thought would be the correct way of doing this but for some reason it the program likes to run the clear operation repeatedly. If anyone can just look over my code and see where the problem is that would be very much appreciated.
My code is as follows:
list P=16F84
include P16F84.INC
; Define the direction bit types
f equ 1
w equ 0
; Define the data storage locations
org 0x20
cnt res 1 ;the number of instructions to execute(1<=n<=8)
acc res 1 ;the accumulator
org 0x30
prg res 8 ;location of the program
; start defining the program
; no interrupts, so start at 0x0
org 0x0
movf 0x20, w
movwf 0x40
Fetch movlw 0x20
movwf FSR
movf INDF, w
movwf 0x22
call EXE
incf FSR,f
decfsz 0x40, f
goto Fetch
goto endless
EXE
BTFSS 0x22, 0
goto Bit_0_is_0
goto Bit_0_is_1
Bit_0_is_0 BTFSS 0x22,1
incf 0x30,0
comf 0x30,0
Bit_0_is_1 BTFSS 0x22,1
decf 0x30, 0
clrf 0x30
return
endless nop
goto endless
end
My code is as follows:
list P=16F84
include P16F84.INC
; Define the direction bit types
f equ 1
w equ 0
; Define the data storage locations
org 0x20
cnt res 1 ;the number of instructions to execute(1<=n<=8)
acc res 1 ;the accumulator
org 0x30
prg res 8 ;location of the program
; start defining the program
; no interrupts, so start at 0x0
org 0x0
movf 0x20, w
movwf 0x40
Fetch movlw 0x20
movwf FSR
movf INDF, w
movwf 0x22
call EXE
incf FSR,f
decfsz 0x40, f
goto Fetch
goto endless
EXE
BTFSS 0x22, 0
goto Bit_0_is_0
goto Bit_0_is_1
Bit_0_is_0 BTFSS 0x22,1
incf 0x30,0
comf 0x30,0
Bit_0_is_1 BTFSS 0x22,1
decf 0x30, 0
clrf 0x30
return
endless nop
goto endless
end