Inline Assembler

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Schlowski.

Hello,

in the manual is written:

- The registers available registers are : eax, ebx, edx, esi, edi and ebp. All other must be always preserved.

What about ecx? Forgotten to mention it?

When I use inline assembler inside a procedure and have to push ecx, the offsets for local variables get wrong for 4 bytes (it's clear if you think about this, but takes me a few hours to realize , but the /commented option helped me finally - great option!)

For now I ignored to save ecx and it seems to work fine, but makes me a little nervous to rely on this without "official" ok...

And what about direction flag? Is it save to STD or CLD or could this break some other code generated by PureBasic?

Bjoerg
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by El_Choni.

If you look at the procedure "epilogue" asm code, you'll see that five registers are pushed, I don't remember which ones, but ecx is, for sure. The direction flag is not preserved.

When using inline asm in procedures, you'd better use global variables for, as you've seen, local variables are stored in stack and PB doesn't watch your pushes or pops.

Hope it helps,

El_Choni
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Schlowski.
If you look at the procedure "epilogue" asm code, you'll see that five registers are pushed, I don't remember which ones, but ecx is, for sure. The direction flag is not preserved.

When using inline asm in procedures, you'd better use global variables for, as you've seen, local variables are stored in stack and PB doesn't watch your pushes or pops.

Hope it helps,

El_Choni
That was what I saw in the /commented output. But I don't like global variables, after a while I run out of good and unique names.

But when I use inline assembler in the main program I still don't know if to save ecx or not, maybe it is used by PureBasic and destroying ecx will lead to a crash later on which would be bad to track down...

Bjoerg
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Rings.

Bjoern,
nice to hear that more people are familar in asm.
/Commented is Cool :wink:

Its a long way to the top if you wanna .....CodeGuru
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Schlowski.
Bjoern,
nice to hear that more people are familar in asm.
/Commented is Cool :wink:

Its a long way to the top if you wanna .....CodeGuru
Hi Rings,

yes, assembler is fun, even if it's sometimes hard to find your own errors...
It's a few years ago since I last programmed in assembler, the ease of mixing PureBasic for the 'normal' tasks and assembler for the speedy part forced me to directly buy PureBasic the same day I stumbled over a link to it.

And the community in this forum is far beyond the people in the german forum! It's nice to 'talk' to other people without flames and I'm the greates coder etc.

BTW, my name is Björg with 'g' at the end, unusual but not as difficult as my family name
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.


You can use 'ecx' without any problem both in Procedure and global program, PB save it for you. It's only a fault in the manual. BTW, PB use the stack instead of 'ebp' (common on C compiler) to handle local variable for an obvious reason: saving one of the 8 registers for other use and optimisations. Unfortunately, PUSH doesn't modify the internal stack offset because if a CALL is used, then PB will be totally lost (CALL can free previous pushed arguments). So be very careful when mixing BASIC and ASM in procedure (this problem never arise in the main part).

Fred - AlphaSND
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Franco.

You can use 'ecx' without any problem both in Procedure and global program, PB save it for you. It's only a fault in the manual. BTW, PB use the stack instead of 'ebp' (common on C compiler) to handle local variable for an obvious reason: saving one of the 8 registers for other use and optimisations. Unfortunately, PUSH doesn't modify the internal stack offset because if a CALL is used, then PB will be totally lost (CALL can free previous pushed arguments). So be very careful when mixing BASIC and ASM in procedure (this problem never arise in the main part).

Fred - AlphaSND
Fred, maybe it's a good idea to write these (and others...) suggestion/rules of yours in the manual...
Just a thought



Have a nice day...
Franco

Sometimes you have to go a lonely way to accomplish genius things.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Rings.
the ease of mixing PureBasic for the 'normal' tasks and assembler for the speedy part forced me to directly buy PureBasic the same day
that is the point , Bjoerg
:)


Its a long way to the top if you wanna .....CodeGuru
Post Reply