Code working as supposed only after declaring dummy variables.

Started by trastikata, May 11, 2021, 11:36 AM

Previous topic - Next topic

trastikata

Hello Les,

I have a piece of code which is not working as supposed unless I declare byte array as dummy (unused) variables. I tested it and found that the compiler creates three different assembler codes without dummy variables, with the dummy array at the beginning and at the end of the DIM statements. The code without the dummy array doesn't works as supposed. Any suggestions as to why?

Thanks

No dummy array
RECEIVE_LOOP
    movlb 0X00
F1_002575 equ $ ; In [RX_2_04.BAS] While DIO0 = 0
_lbl__969
    btfsc PORTA,1,0
    bra _lbl__970
F1_002576 equ $ ; In [RX_2_04.BAS] GoSub __USBCheckBusStatus
    call __USBCheckBusStatus
    call __USBDriverService
F1_002577 equ $ ; In [RX_2_04.BAS] DelayUs 100
    movlw 100
    call __Delay_Us_
F1_002578 equ $ ; In [RX_2_04.BAS] GoSub CALCULATE_RSSI_SHORT_USB
    call CALCULATE_RSSI_SHORT_USB
F1_002579 equ $ ; In [RX_2_04.BAS] USB_BUFFER = "#" + Str$(SDEC RSSI_S_SHORT)
    lfsr 0,USB_BUFFER
    movlw 35
    movwf POSTINC0,0
    movlw 2
    movwf BPFH,0
    clrf GEN4H,0
    movff RSSI_S_SHORTH,PP2H
    movff RSSI_S_SHORT,PP2
    call __sdec__ASCII__out
    clrf INDF0,0
F1_002580 equ $ ; In [RX_2_04.BAS] GoSub USB_TRANSMIT
    call USB_TRANSMIT
F1_002581 equ $ ; In [RX_2_04.BAS] if tUSB_Attached = 1  Then
    btfss bUSB_Flags,0,0
    bra _lbl__972
F1_002582 equ $ ; In [RX_2_04.BAS] if _DataAvailable  = 1  Then
variable max_params=10,return_type=2,return_var=PBS_VAR0,_DataAvailable_return=1,prm_count=0
    call __DataAvailable
    movwf return_var
    movlw 1
    subwf PBS_VAR0,W,0
    bnz _lbl__974
F1_002583 equ $ ; In [RX_2_04.BAS] _ReadReport
variable max_params=10,_ReadReport_return=0,prm_count=0
    call __ReadReport
F1_002584 equ $ ; In [RX_2_04.BAS] Temp = RXReport[0]
    movlb 0X06
    movf RXReport,W,1
    movlb 0X01
    movwf Temp,1
F1_002585 equ $ ; In [RX_2_04.BAS] Clear Temp
    clrf Temp,1
F1_002586 equ $ ; In [RX_2_04.BAS] DelayMs 1
    movlw 1
    call __delay_ms_
F1_002587 equ $ ; In [RX_2_04.BAS] GoSub __USBCheckBusStatus
    movlb 0X00
    call __USBCheckBusStatus
    call __USBDriverService
F1_002588 equ $ ; In [RX_2_04.BAS] goto RECEIVE_LOOP_OUT
    bra RECEIVE_LOOP_OUT
F1_002589 equ $ ; In [RX_2_04.BAS] endif
_lbl__974
    bra _lbl__975
_lbl__972
F1_002590 equ $ ; In [RX_2_04.BAS] else
F1_002591 equ $ ; In [RX_2_04.BAS] tUSB_Attached = 0
    bcf bUSB_Flags,0,0
F1_002592 equ $ ; In [RX_2_04.BAS] goto USB_DISCONNECTED
    goto USB_DISCONNECTED
F1_002593 equ $ ; In [RX_2_04.BAS] endif
_lbl__975
F1_002594 equ $ ; In [RX_2_04.BAS] Wend
    bra _lbl__969
_lbl__970
F1_002596 equ $ ; In [RX_2_04.BAS] goto RECEIVE_SUB
    goto RECEIVE_SUB


Dummy array at the beginning

RECEIVE_LOOP
    movlb 0X00
F1_002575 equ $ ; In [RX_2_04.BAS] While DIO0 = 0
_lbl__969
    btfsc PORTA,1,0
    bra _lbl__970
F1_002576 equ $ ; In [RX_2_04.BAS] GoSub __USBCheckBusStatus
    call __USBCheckBusStatus
    call __USBDriverService
F1_002577 equ $ ; In [RX_2_04.BAS] DelayUs 100
    movlw 100
    call __Delay_Us_
F1_002578 equ $ ; In [RX_2_04.BAS] GoSub CALCULATE_RSSI_SHORT_USB
    call CALCULATE_RSSI_SHORT_USB
F1_002579 equ $ ; In [RX_2_04.BAS] USB_BUFFER = "#" + Str$(SDEC RSSI_S_SHORT)
    lfsr 0,USB_BUFFER
    movlw 35
    movwf POSTINC0,0
    movlw 2
    movwf BPFH,0
    clrf GEN4H,0
    movff RSSI_S_SHORTH,PP2H
    movff RSSI_S_SHORT,PP2
    call __sdec__ASCII__out
    clrf INDF0,0
F1_002580 equ $ ; In [RX_2_04.BAS] GoSub USB_TRANSMIT
    call USB_TRANSMIT
F1_002581 equ $ ; In [RX_2_04.BAS] if tUSB_Attached = 1  Then
    btfss bUSB_Flags,0,0
    bra _lbl__972
F1_002582 equ $ ; In [RX_2_04.BAS] if _DataAvailable  = 1  Then
variable max_params=10,return_type=2,return_var=PBS_VAR0,_DataAvailable_return=1,prm_count=0
    call __DataAvailable
    movwf return_var
    movlw 1
    subwf PBS_VAR0,W,0
    bnz _lbl__974
F1_002583 equ $ ; In [RX_2_04.BAS] _ReadReport
variable max_params=10,_ReadReport_return=0,prm_count=0
    call __ReadReport
F1_002584 equ $ ; In [RX_2_04.BAS] Temp = RXReport[0]
    movlb 0X06
    movf RXReport,W,1
    movlb 0X00
    movwf Temp,1
F1_002585 equ $ ; In [RX_2_04.BAS] Clear Temp
    clrf Temp,1
F1_002586 equ $ ; In [RX_2_04.BAS] DelayMs 1
    movlw 1
    call __delay_ms_
F1_002587 equ $ ; In [RX_2_04.BAS] GoSub __USBCheckBusStatus
    call __USBCheckBusStatus
    call __USBDriverService
F1_002588 equ $ ; In [RX_2_04.BAS] goto RECEIVE_LOOP_OUT
    bra RECEIVE_LOOP_OUT
F1_002589 equ $ ; In [RX_2_04.BAS] endif
_lbl__974
    bra _lbl__975
_lbl__972
F1_002590 equ $ ; In [RX_2_04.BAS] else
F1_002591 equ $ ; In [RX_2_04.BAS] tUSB_Attached = 0
    bcf bUSB_Flags,0,0
F1_002592 equ $ ; In [RX_2_04.BAS] goto USB_DISCONNECTED
    goto USB_DISCONNECTED
F1_002593 equ $ ; In [RX_2_04.BAS] endif
_lbl__975
F1_002594 equ $ ; In [RX_2_04.BAS] Wend
    bra _lbl__969
_lbl__970
F1_002596 equ $ ; In [RX_2_04.BAS] goto RECEIVE_SUB
    goto RECEIVE_SUB

Dummy array at the end

RECEIVE_LOOP
    movlb 0X00
F1_002577 equ $ ; In [RX_2_04.BAS] While DIO0 = 0
_lbl__969
    btfsc PORTA,1,0
    bra _lbl__970
F1_002578 equ $ ; In [RX_2_04.BAS] GoSub __USBCheckBusStatus
    call __USBCheckBusStatus
    call __USBDriverService
F1_002579 equ $ ; In [RX_2_04.BAS] DelayUs 100
    movlw 100
    call __Delay_Us_
F1_002580 equ $ ; In [RX_2_04.BAS] GoSub CALCULATE_RSSI_SHORT_USB
    call CALCULATE_RSSI_SHORT_USB
F1_002581 equ $ ; In [RX_2_04.BAS] USB_BUFFER = "#" + Str$(SDEC RSSI_S_SHORT)
    lfsr 0,USB_BUFFER
    movlw 35
    movwf POSTINC0,0
    movlw 2
    movwf BPFH,0
    clrf GEN4H,0
    movff RSSI_S_SHORTH,PP2H
    movff RSSI_S_SHORT,PP2
    call __sdec__ASCII__out
    clrf INDF0,0
F1_002582 equ $ ; In [RX_2_04.BAS] GoSub USB_TRANSMIT
    call USB_TRANSMIT
F1_002583 equ $ ; In [RX_2_04.BAS] if tUSB_Attached = 1  Then
    btfss bUSB_Flags,0,0
    bra _lbl__972
F1_002584 equ $ ; In [RX_2_04.BAS] if _DataAvailable  = 1  Then
variable max_params=10,return_type=2,return_var=PBS_VAR0,_DataAvailable_return=1,prm_count=0
    call __DataAvailable
    movwf return_var
    movlw 1
    subwf PBS_VAR0,W,0
    bnz _lbl__974
F1_002585 equ $ ; In [RX_2_04.BAS] _ReadReport
variable max_params=10,_ReadReport_return=0,prm_count=0
    call __ReadReport
F1_002586 equ $ ; In [RX_2_04.BAS] Temp = RXReport[0]
    movlb 0X06
    movf RXReport,W,1
    movlb 0X00
    movwf Temp,1
F1_002587 equ $ ; In [RX_2_04.BAS] Clear Temp
    clrf Temp,1
F1_002588 equ $ ; In [RX_2_04.BAS] DelayMs 1
    movlw 1
    call __delay_ms_
F1_002589 equ $ ; In [RX_2_04.BAS] GoSub __USBCheckBusStatus
    call __USBCheckBusStatus
    call __USBDriverService
F1_002590 equ $ ; In [RX_2_04.BAS] goto RECEIVE_LOOP_OUT
    bra RECEIVE_LOOP_OUT
F1_002591 equ $ ; In [RX_2_04.BAS] endif
_lbl__974
    bra _lbl__975
_lbl__972
F1_002592 equ $ ; In [RX_2_04.BAS] else
F1_002593 equ $ ; In [RX_2_04.BAS] tUSB_Attached = 0
    bcf bUSB_Flags,0,0
F1_002594 equ $ ; In [RX_2_04.BAS] goto USB_DISCONNECTED
    goto USB_DISCONNECTED
F1_002595 equ $ ; In [RX_2_04.BAS] endif
_lbl__975
F1_002596 equ $ ; In [RX_2_04.BAS] Wend
    bra _lbl__969
_lbl__970
F1_002598 equ $ ; In [RX_2_04.BAS] goto RECEIVE_SUB
    goto RECEIVE_SUB