Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
116 user(s) are online (107 user(s) are browsing Forums)

Members: 1
Guests: 115

amigait, more...

Support us!

Headlines

 
  Register To Post  

DSI error in assembler code
Home away from home
Home away from home


See User information
C code that works!

*((unsigned int *) (&output)) = *((unsigned int *) (&input));

// GCC loads r11 whit input address
 
10003b0:       3d 20 01 01     lis     r9,257
 10003b4
:       39 69 00 40     addi    r11,r9,64

// GCC loads r9 whit output address
 
10003b8:       3d 20 01 01     lis     r9,257
 10003bc
:       39 29 00 48     addi    r9,r9,72

// GCC loads input address (r9) in to r0
 
10003c0:       80 09 00 00     lwz     r0,0(r9)

// GCC store r0 outout address (r11)
 
10003c4:       90 0b 00 00     stw     r0,0(r11)


This code crash!!!

asm(
" lwz 3,0(%1) \t\n"
" li 4,0 \t\n"
" stwbrx 3,4,%0"
:: "r" (&output), "r" (&input) );

// inline asm loads r11 whit input address
 
10003c8:       3d 20 01 01     lis     r9,257
 10003cc
:       39 69 00 40     addi    r11,r9,64

// inline asm loads r0 whit outout address
 
10003d0:       3d 20 01 01     lis     r9,257
 10003d4
:       38 09 00 48     addi    r0,r9,72

// inline asm trys to load from r0 and crash
 
10003d8:       80 60 00 00     lwz     r3,0(0)

// not executed ...

  
10003dc:       38 80 00 00     li      r4,0
 10003e0
:       7c 64 5d 2c     stwbrx  r3,r4,r11

(NutsAboutAmiga)

Basilisk II for AmigaOS4
AmigaInputAnywhere
Excalibur
and other tools and apps.
Go to top
Re: DSI error in assembler code
Quite a regular
Quite a regular


See User information
@LiveForIt

So where is the register dump from the crash? What values were actually in the registers? Are those values what you expected?

You seem to have your "input" and "output" addresses reversed.

cheers
tony
Go to top
Re: DSI error in assembler code
Not too shy to talk
Not too shy to talk


See User information
@LiveForIt

The lwz is reading from 0(0), you probably meant 0(r0). Try using a different register.

Go to top
Re: DSI error in assembler code
Just popping in
Just popping in


See User information
@LiveForIt

Quote:

LiveForIt wrote:

asm(
    
" lwz 3,0(%1) \t\n"
    " li 4,0 \t\n"
    " stwbrx 3,4,%0"
    
:: "r" (&output), "r" (&input) );


r0 can never be used as an address, it will always be 0 when used in such a way.

To ensure that a register is taken that works as a memory address, use the "b" constraint. Also, for memory references themselves (as in the lwz), you can use use "m".

Finaly, stwbrx is defined as

stwbrx rs, ra, rb

and the effective address is (ra|0)+(rb), so the code can be compressed llike this (since r0 is automatically used as constant 0, no need to load an additional register with it):

asm(
    
" lwz 3,%1\t\n"
    " stwbrx 3,0,%0"
    
:: "b" (&output), "m" (input) : "3" );


Note that this also adds r3 to the globbered registers, meaning that their value is undefined after the asm statement (otherwise, the compiler might assume that r3 wasn't change, which it was).

You might want to check if this works better for you.

Go to top
Re: DSI error in assembler code
Home away from home
Home away from home


See User information
@tfrieden

Thanks, I it works now.

(NutsAboutAmiga)

Basilisk II for AmigaOS4
AmigaInputAnywhere
Excalibur
and other tools and apps.
Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2024 The XOOPS Project