View previous topic :: View next topic |
Author |
Message |
Zvoc47
Joined: 02 Apr 2015 Posts: 21
|
Posted: Tue Apr 07, 2015 9:26 am Post subject: Error when trying to write to a variable using inline assemb |
|
|
I want to write the stack pointer to the variables StkL and StkH. The error I get is that BASCOM is expecting a label instead of a variable. If I use {}, I'll only get one byte of the address, but I want to get both low and high bytes.
Code: | Dim StkL As Byte
Dim StkH As Byte
$asm
LDS r16, SPL
LDS r17, SPH
LDI r30, LOW(StkL)
LDI r31, HIGH(StkL)
ST X, r16
ldi r30, LOW(StkH)
Ldi r31, HIGH(StkH)
st X, r17
$end asm |
Can you help me?
(BASCOM-AVR version : 2.0.7.8 ) |
|
Back to top |
|
|
Zvoc47
Joined: 02 Apr 2015 Posts: 21
|
Posted: Tue Apr 07, 2015 9:43 am Post subject: |
|
|
Solved it myself. It gave me zeros in the simulator, but on real MCU, the values were correct. The simulator failed to simulate $3D and $3E which are the CPU_SPL and CPU_SPH. Please fix this.
My code was:
Code: | Dim StkL As Byte
Dim StkH As Byte
LOADADR StkL, Z
$asm
lds r16, $3D
ST Z, r16
$end asm
LOADADR StkH, Z
$asm
lds r16, $3E
ST Z, r16
$end asm
Print "Prvo SPH=";StkH;" SPL=";StkL
SPH=$2F
LOADADR StkL, Z
$asm
lds r16, $3D
ST Z, r16
$end asm
LOADADR StkH, Z
$asm
lds r16, $3E
ST Z, r16
$end asm
Print "Drugo SPH=";StkH;" SPL=";StkL
Enable Interrupts
Print "Hello World!"
Stop | [/code] |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5905 Location: Holland
|
Posted: Tue Apr 07, 2015 9:24 pm Post subject: |
|
|
why so complex?
Dim StkL As Byte
Dim StkH As Byte
stkl = SPL
stkh = SPH
or :
dim wSTK as Word
wSTk=SP ' sp is defined as word too
About the sim : i will change it. the memory offset of the registers is not available in xmega and thus lower regs are pointing to the wrong memory. _________________ Mark |
|
Back to top |
|
|
|
|
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
|
|