Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Error when trying to write to a variable using inline assemb

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

Bascom Member



Joined: 02 Apr 2015
Posts: 21

PostPosted: Tue Apr 07, 2015 9:26 am    Post subject: Error when trying to write to a variable using inline assemb Reply with quote

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

Bascom Member



Joined: 02 Apr 2015
Posts: 21

PostPosted: Tue Apr 07, 2015 9:43 am    Post subject: Reply with quote

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

Administrator



Joined: 09 Apr 2004
Posts: 6197
Location: Holland

blank.gif
PostPosted: Tue Apr 07, 2015 9:24 pm    Post subject: Reply with quote

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
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