Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Bylabel and RampZ

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
Netzman

Bascom Expert



Joined: 25 Nov 2005
Posts: 112
Location: Graz

austria.gif
PostPosted: Wed Mar 25, 2015 9:50 pm    Post subject: Bylabel and RampZ Reply with quote

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
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 4975
Location: Holland

blank.gif
PostPosted: Fri Mar 27, 2015 9:30 pm    Post subject: Reply with quote

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
View user's profile Visit poster's website
Netzman

Bascom Expert



Joined: 25 Nov 2005
Posts: 112
Location: Graz

austria.gif
PostPosted: Fri Mar 27, 2015 9:48 pm    Post subject: Reply with quote

Hi Mark,

Doh, also just found out my answer is in the help Smile
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
View user's profile Visit poster's website
Zvoc47

Bascom Member



Joined: 02 Apr 2015
Posts: 21

PostPosted: Fri Apr 03, 2015 11:43 pm    Post subject: Reply with quote

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
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 4975
Location: Holland

blank.gif
PostPosted: Sat Apr 04, 2015 7:50 am    Post subject: Reply with quote

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
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum