augustinetez
Active Member
Just curious as to whether there might be a better way of doing IF_THEN routines in ASM as opposed to below code.
Background:
Processor is 16F628A - already set from an old project so not changeable (at this stage).
The routine is to select a group of 4 bytes from a table of 16 bytes depending in the inputs RA6 & 7 (switches), 4 options available.
The code below is only performed once on power-up to set a selected value.
There is a bit of jiggery-pokery (not shown) to shift what are bits 6 & 7 of PORTA to bits 0 & 1 of the IF_index register (so I don't have to count higher than 3 )
The code within the ////////////////////////// marks are what I have used before in other projects and am asking about.
Once this routine has been performed, it drops through to more set-up code for other variables.
Background:
Processor is 16F628A - already set from an old project so not changeable (at this stage).
The routine is to select a group of 4 bytes from a table of 16 bytes depending in the inputs RA6 & 7 (switches), 4 options available.
The code below is only performed once on power-up to set a selected value.
There is a bit of jiggery-pokery (not shown) to shift what are bits 6 & 7 of PORTA to bits 0 & 1 of the IF_index register (so I don't have to count higher than 3 )
The code within the ////////////////////////// marks are what I have used before in other projects and am asking about.
Once this routine has been performed, it drops through to more set-up code for other variables.
Code:
; Using RA6 & 7 input data, obtain the if_table entry and
; copy IF offset from table and store in ioff_3..0
;
clrf temp ; Clear the temp variable
movlw FREQ_COUNT ; There are four bytes to copy
movwf count ; Set up count variable
movlw ioff_0 ; Get target address
movwf FSR ; Store in pointer register
;////////////////////////////////////////////////////////////////////////////////
movf IF_index,f
btfsc STATUS,Z
goto get_if_loop ; If IF_index is '0' get values from table starting at index 0
movfw IF_index ;
xorlw 1
btfsc STATUS,Z
goto index_1 ; If IF_index is '1' get values from table starting at index 4
movfw IF_index ;
xorlw 2
btfsc STATUS,Z
goto index_2 ; If IF_index is '2' get values from table starting at index 8
movfw IF_index ;
xorlw 3
btfsc STATUS,Z
goto index_3 ; If IF_index is '3' get values from table starting at index 12
clrf temp ; Error checking - if index value is other than 0->3
goto get_if_loop ; set index to 0
index_1
movlw d'4'
movwf temp
goto get_if_loop ;
index_2
movlw d'8'
movwf temp
goto get_if_loop ;
index_3
movlw d'12'
movwf temp
;////////////////////////////////////////////////////////////////////////////////
get_if_loop
movf temp,w ; Get the if_table index into W
call if_table ; Get a if_table byte
movwf INDF ; Store it into ioff_3..0
incf FSR,f ; Point to next higher offset byte, ioff_0..3
incf temp,f ; Increment table index
decfsz count,f ; Decrement loop count
goto get_if_loop ; loop while more bytes remain