View previous topic :: View next topic |
Author |
Message |
peterfido
Joined: 29 Mar 2007 Posts: 25
|
Posted: Sat Jul 26, 2014 10:14 pm Post subject: Config Base = 0 und Inline ASM. Error in Bascom or only in S |
|
|
Hallo,
folgender Code gibt bei mir im Simulator die falsche Adresse für LED(0) aus:
Code: |
$regfile = "m328def.dat"
$hwstack = 40
$swstack = 40
$framesize = 40
$crystal = 8000000
$baud = 9600
Config Base = 0
Dim A As Byte
Dim Leds(450) As Byte
Dim W As Word
Dim B(2) As Byte At W Overlay
Do
A = 0
Gosub Adresseholen
Print W
A = 1
Gosub Adresseholen
Print W
Loop
End
Adresseholen:
$asm
push xl
push xh
clr xh
Loadadr Leds(a) , X
sts {b(1)},xl
sts {b(2)},xh
pop xh
pop xl
$end Asm
Return
|
Dabei ist mir aufgefallen, dass die Variable A trotz config base=0 überschrieben wird.
Getestet mit Bascom 2.0.7.7.
(BASCOM-AVR version : 2.0.7.7 ) _________________ Greetings
Peterfido
BASCOM 2.0.7.7 |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Sat Jul 26, 2014 11:07 pm Post subject: |
|
|
First, this is an English spoken Forum.
What is then the wrong address, i.e. where it points to?
The shown ASM code is crap, afaik the LoadAdr helper function is resolved at compile time, which forbids to use a variable as index. Further by calling a subroutine the XL/XH registers don't need to be saved, the compiler assumes them as destroyed. Only for YL/YH it's different. To clear XH makes no sense either, as XH is overwritten anyway by the following LoadAdr var, X. |
|
Back to top |
|
|
O-Family
Joined: 23 May 2010 Posts: 320 Location: Japan
|
Posted: Sun Jul 27, 2014 1:09 am Post subject: |
|
|
You are setting the base of the index to 0.
Therefore, it is necessary to also set the write-in index of XL and XH to 0.
sts {b(0)},xl
sts {b(1)},xh |
|
Back to top |
|
|
peterfido
Joined: 29 Mar 2007 Posts: 25
|
Posted: Sun Jul 27, 2014 5:26 am Post subject: |
|
|
Perfekt, Thanks. My Mistake.
But the Compiler could Rise an Error, that b(2) is out of bound. _________________ Greetings
Peterfido
BASCOM 2.0.7.7 |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Sun Jul 27, 2014 9:02 am Post subject: |
|
|
peterfido wrote: | But the Compiler could Rise an Error, that b(2) is out of bound. |
It likely has something to do with using it in an ASM block. Assembler is rather for people, who know what they do ;D
If placed within Basic-code, a b(2) rises an out-of-bounds error.
This weird construct:
Code: | Dim W As Word
Dim B(2) As Byte At W Overlay
sts {b(0)},xl
sts {b(1)},xh |
is correctly written as:
Code: | sts {W},xl
sts {W+1},xh |
If done this way, the base of the index is no issue.
So don't complain about the compiler, pick your own nose. |
|
Back to top |
|
|
O-Family
Joined: 23 May 2010 Posts: 320 Location: Japan
|
Posted: Sun Jul 27, 2014 9:59 am Post subject: |
|
|
I presented correction about the mistake in a program.
In order to know the memory address to which the variable is assigned, it is realizable only by BASIC command.
A = 0
W = Varptr(leds(a))
Print Hex(w)
A = 1
W = Varptr(leds(a))
Print Hex(w) |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Sun Jul 27, 2014 10:15 am Post subject: |
|
|
O-Family wrote: | I presented correction about the mistake in a program. |
My post was rather directed to the TO.
Quote: | In order to know the memory address to which the variable is assigned, it is realizable only by BASIC command. |
That "only" however is not correct. The LoadAdr var, reg loads reg with the address of var, and if reg is saved then to a variable, the variable contains the address of var. |
|
Back to top |
|
|
peterfido
Joined: 29 Mar 2007 Posts: 25
|
Posted: Sun Jul 27, 2014 10:33 am Post subject: |
|
|
Ah - OK.
The Loadadr in Assembly is checked for Bound. Because Loadadr is a Bascom intern Function.
The STS in Assembly is not checked for Bounds. _________________ Greetings
Peterfido
BASCOM 2.0.7.7 |
|
Back to top |
|
|
|