View previous topic :: View next topic |
Author |
Message |
Netzman
Joined: 25 Nov 2005 Posts: 127 Location: Graz
|
Posted: Wed Mar 25, 2015 9:50 pm Post subject: Bylabel and RampZ |
|
|
Hi,
I want to get the address of a label passed to a sub, which works fine if it is located in the first 64K. When the address points to a higher location, RampZ would be needed to be loaded with the correct page value, which works with the Loadlabel and Restore statements, but not with the Bylabel parameter.
I've written a small program to test this in the simulator (the attached archive contains the test program and the 64K dummy data include):
Code: | $regfile = "xm128a1def.dat"
'$regfile = "m128def.dat"
$crystal = 1000000
$hwstack = 32
$swstack = 32
$framesize = 32
$sim
Config Submode = New
Sub Print_address(byref Address As Word)
Local Rampz_val As Byte
Rampz_val = Rampz
Print " - adr: " ; Address
Print " rampz: " ; Rampz_val
Print " readrampz: " ; ___readrampz
End Sub
Sub Test_bylabel(bylabel Address As Word)
Print_address Address
End Sub
Sub Test_loadlabel(byref Address As Word)
Print_address Address
End Sub
Sub Test_restore()
Local Address As Word
Address = R9
Shift Address , Left , 8
Address = Address + R8
Print_address Address
End Sub
Dim Labeladdress As Word
Print "Bylabel:"
Test_bylabel Firstpage
Test_bylabel Secondpage
Print ""
Print "Loadlabel:"
Labeladdress = Loadlabel(firstpage)
Test_loadlabel Labeladdress
Labeladdress = Loadlabel(secondpage)
Test_loadlabel Labeladdress
Print ""
Print "Restore:"
Restore Firstpage
Test_restore
Restore Secondpage
Test_restore
Print ""
End
Firstpage:
$include "64K_block.inc"
Secondpage: |
It loads the address in 3 different ways, first as mentioned with Bylabel, then per Loadlabel and last per Restore.
Compiled for the XMega128, i get this output:
Code: | Bylabel:
- adr: 878
rampz: 0
readrampz: 0
- adr: 878
rampz: 0
readrampz: 0
Loadlabel:
- adr: 878
rampz: 0
readrampz: 0
- adr: 878
rampz: 1
readrampz: 0
Restore:
- adr: 878
rampz: 0
readrampz: 0
- adr: 878
rampz: 1
readrampz: 1 |
Loadlabel and Restore work like expected, but Bylabel doesn't alter the RampZ register or anything related (or do I miss something?).
Strangely, when compiled for the Mega128, Bylabel seems to set RampZ every time to 1, Loadlabel and Restore still work the same:
Code: | Bylabel:
- adr: 462
rampz: 1
readrampz: 0
- adr: 462
rampz: 1
readrampz: 0
Loadlabel:
- adr: 462
rampz: 0
readrampz: 0
- adr: 462
rampz: 1
readrampz: 0
Restore:
- adr: 462
rampz: 0
readrampz: 0
- adr: 462
rampz: 1
readrampz: 1 |
Changing the data type of the bylabel variable to Dword does not make any difference.
(Edit: not true, changed every Word to Dword, it does work at least for the Mega128. Still the Xmega version does not.)
(BASCOM-AVR version : 2.0.7.8 ) _________________ LCD Menu | Proportional Fonts |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Fri Mar 27, 2015 9:30 pm Post subject: |
|
|
from the help :
Use BYLABEL to pass the address of a label. BYLABEL will pass the word address. It will not work for processors with multiple 64 KB pages.
So it isn't suppose to work. Supporting 24 bit pointers would require some changes. Since this is some work,and we never know if an option is actually used, it was not included.
But since you made these nice apps i will have a look into it. _________________ Mark |
|
Back to top |
|
|
Netzman
Joined: 25 Nov 2005 Posts: 127 Location: Graz
|
Posted: Fri Mar 27, 2015 9:48 pm Post subject: |
|
|
Hi Mark,
Doh, also just found out my answer is in the help
That raised a second question, which you also have already answered, why it is limited to <64K.
Because of that limitation, portable code, which should also run on >64k devices, would need the Restore/Loadlabel/Function call combination. Now that it's clear for me I can do it this way in the mean time.
Thanks for explaining this and thanks for having a look into it!
Br _________________ LCD Menu | Proportional Fonts |
|
Back to top |
|
|
Zvoc47
Joined: 02 Apr 2015 Posts: 21
|
Posted: Fri Apr 03, 2015 11:43 pm Post subject: |
|
|
I'm a newbie and I would like to know would loading data from Flash at an inputted location give me the correct data.
For example if I type 0x01234, would I get 0x01234 or 0x00234?
P.S. I'm trying to figure out how BASCOM works so I can't test it right now. |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Sat Apr 04, 2015 7:50 am Post subject: |
|
|
first you need to use &H instead of 0x.
second, i have no idea what you want. you want to input some address and read the flash? you could use peekh() which will load the proper address and thus returns the right byte.
I advise to check out the samples (file, open sample) and the PDF of bascom. _________________ Mark |
|
Back to top |
|
|
|