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
Inline Assembler
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
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
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

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Schlowski.
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
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.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
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

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

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Schlowski.
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
Hi Rings,Bjoern,
nice to hear that more people are familar in asm.
/Commented is Cool
Its a long way to the top if you wanna .....CodeGuru
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

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
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
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

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Franco.
Just a thought
Have a nice day...
Franco
Sometimes you have to go a lonely way to accomplish genius things.
Fred, maybe it's a good idea to write these (and others...) suggestion/rules of yours in the manual...
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
Just a thought
Have a nice day...
Franco
Sometimes you have to go a lonely way to accomplish genius things.
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm