News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Correct current method to alisa variables

Started by TimB, Feb 07, 2023, 08:10 PM

Previous topic - Next topic

TimB


Hi all

I needed to alias some variables to an array. In the past I would just us the "at" method

eg
    Dim ai2cS_TO_M_REGS[ci2cS_TO_M_BUF_LEN] As Byte   ' MASTER Read  Buffer array declare (Master<--Slave)

    Dim bSystemStatusReg as Byte at ai2cM_TO_S_REGS#0
    Dim fLast1HzNCFLowReg as float at ai2cM_TO_S_REGS#1
    Dim fCurrentNCTallyReg as Float at ai2cM_TO_S_REGS#4

But the code produced is wrong the alias points to the wrong address see below

So what is the current method?


ai2cS_TO_M_REGS equ 0x03
variable ai2cS_TO_M_REGS#0=0x03,ai2cS_TO_M_REGS#1=0x04,ai2cS_TO_M_REGS#2=0x05,ai2cS_TO_M_REGS#3=0x06
variable ai2cS_TO_M_REGS#4=0x07,ai2cS_TO_M_REGS#5=0x08,ai2cS_TO_M_REGS#6=0x09,ai2cS_TO_M_REGS#7=0x0A
variable ai2cS_TO_M_REGS#8=0x0B,ai2cS_TO_M_REGS#9=0x0C
bi2cM_TO_S_REG_INDEX equ 0x0D
bi2cS_TO_M_REG_INDEX equ 0x0E
bi2cCASE_SWITCH equ 0x0F
; ADDRESSED VARIABLES
bSystemStatusReg equ 0x00
fLast1HzNCFLowReg equ 0x01
fLast1HzNCFLowRegH equ 0x02
fLast1HzNCFLowRegHH equ 0x03
fLast1HzNCFLowRegHHH equ 0x04
fCurrentNCTallyReg equ 0XFFFFFFFF
fCurrentNCTallyRegH equ 0x00
fCurrentNCTallyRegHH equ 0x01
fCurrentNCTallyRegHHH equ 0x02



top204

#1
What device Tim? So I can reproduce it and see what is going on.

With an 18F device, the code:
    Device = 18F25K20                               ' Tell the compiler what device to compile for
    Declare Xtal = 16                               ' Tell the compiler what frequency the device will be operating at (in MHz)
   
    Symbol My_ByteArray_Len = 32
    Dim My_ByteArray[My_ByteArray_Len] As Byte

    Dim MyByte   As Byte  At My_ByteArray#0
    Dim MyFloat1 As Float At My_ByteArray#1
    Dim MyFloat2 As Float At My_ByteArray#4

Produces the correct assembler code:

; STANDARD VARIABLES
My_ByteArray equ 0x00
variable My_ByteArray#0=0x00,My_ByteArray#1=0x01,My_ByteArray#2=0x02,My_ByteArray#3=0x03
variable My_ByteArray#4=0x04,My_ByteArray#5=0x05,My_ByteArray#6=0x06,My_ByteArray#7=0x07
variable My_ByteArray#8=0x08,My_ByteArray#9=0x09,My_ByteArray#10=0x0A,My_ByteArray#11=0x0B
variable My_ByteArray#12=0x0C,My_ByteArray#13=0x0D,My_ByteArray#14=0x0E,My_ByteArray#15=0x0F
variable My_ByteArray#16=0x10,My_ByteArray#17=0x11,My_ByteArray#18=0x12,My_ByteArray#19=0x13
variable My_ByteArray#20=0x14,My_ByteArray#21=0x15,My_ByteArray#22=0x16,My_ByteArray#23=0x17
variable My_ByteArray#24=0x18,My_ByteArray#25=0x19,My_ByteArray#26=0x1A,My_ByteArray#27=0x1B
variable My_ByteArray#28=0x1C,My_ByteArray#29=0x1D,My_ByteArray#30=0x1E,My_ByteArray#31=0x1F
; ADDRESSED VARIABLES
MyByte equ 0x00
MyFloat1 equ 0x01
MyFloat1H equ 0x02
MyFloat1HH equ 0x03
MyFloat1HHH equ 0x04
MyFloat2 equ 0x04
MyFloat2H equ 0x05
MyFloat2HH equ 0x06
MyFloat2HHH equ 0x07

I have tried larger and smaller arrays and they all work as expected, and create the aliased variables at the correct address'

I've noticed in your code you are aliasing ai2cM_TO_S_REGS and ai2cS_TO_M_REGS, but ai2cM_TO_S_REGS is not present in the listing. Also note that fCurrentNCTallyReg  will clash with fLast1HzNCFLowReg because it is overwriting the last byte of it (address 4). Arrays start at element 0.

TimB


Thanks Les

Sorry I thought I checked the ASM properly.


Tim