gcc and asm

General FreeBASIC programming questions.
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: gcc and asm

Post by jj2007 »

deltarho[1859] wrote:With PowerBASIC EBX, ESI and EDI are automatically pushed at the beginning of a procedure and automatically popped before exiting the procedure. This is to conform to the Windows programming conventions. FreeBASIC does not mention anything about preserving registers.
Not sure if it is mentioned somewhere, but FreeBasic does save and restore esi edi ebx in a non-naked function. Why that is, no idea, it makes little sense to allow Assembly code but then non trust the coder that he knows what he's doing. I use naked functions only since the moment when I discovered this behaviour.
deltarho[1859]
Posts: 4310
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: gcc and asm

Post by deltarho[1859] »

marcov wrote:This (the PB thing) is not normal. Normal is that callee saves non-volatile registers only IF these are used, not always. That would be unnecessary slowing, and prevent assembler users from achieving maximum performance.
Agreed. PB used to be 16-bit producing 32-bit binaries. It is now 32-bit producing 32-bit binaries. That and the fact that Bob Zale passed away eight years ago last November with PB being frozen ever since may account for some improvements not happening when they should have by now. Having said that, the 'PB thing' may not have changed. Bob had some ideas carved in stone. I moaned about PB's RND for quite a while before he died, but he took no notice even when I showed that PractRand figured it to be one of the worst generators it had ever looked at. Image
deltarho[1859]
Posts: 4310
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: gcc and asm

Post by deltarho[1859] »

@jj2007

I mentioned "FreeBASIC does not mention anything about preserving registers." in the context of the Naked description.
fxm
Moderator
Posts: 12110
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: gcc and asm

Post by fxm »

KeyPgAsm → fxm [inside a naked procedure, there is no register preservation]
KeyPgNaked → fxm [inside a naked procedure, there is no register preservation]
deltarho[1859]
Posts: 4310
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: gcc and asm

Post by deltarho[1859] »

@fxm

Tell me they have just been added otherwise I shall shoot myself.
fxm
Moderator
Posts: 12110
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: gcc and asm

Post by fxm »

Yes, I just made these two updates.
deltarho[1859]
Posts: 4310
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: gcc and asm

Post by deltarho[1859] »

Flaming heck fxm I had my grandfather's twelve-bore under my chin. Image
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: gcc and asm

Post by jj2007 »

deltarho[1859] wrote:@jj2007

I mentioned "FreeBASIC does not mention anything about preserving registers." in the context of the Naked description.
Yes, your comment was correct, sorry. It was fxm who posted misleading info.
fxm wrote:Not only in naked procedure, but in any asm block
deltarho[1859]
Posts: 4310
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: gcc and asm

Post by deltarho[1859] »

To be fair to fxm I think that it was a badly written statement rather than a misunderstanding because he took on board my comments and quickly added two warnings to the Wiki; which will no doubt appear in the chm file in due course. Had a warning existed in the description of Naked in Help this thread may not have been started. In addition, my code would not have posted because I never intended to go public with it. I would have done had it put pressure on PCG32II.
fxm
Moderator
Posts: 12110
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: gcc and asm

Post by fxm »

Allow me to restore the true context of my sentence in its original post:
fxm wrote:
deltarho[1859] wrote:This thread has been worthwhile because I now know that if we use any of the volatile registers in Naked, then they should be preserved.

Perhaps fxm can mention that in the documentation.
Not only in naked procedure, but in any asm block.

Paragraph already existing on the ASM documentation page:
Register Preservation
  • When an Asm block is opened, the registers ebx, esi, and edi are pushed to the stack, when the block is closed, these registers are popped back from the stack. This is because these registers are required to be preserved by most or all OS's using the x86 CPU. You can therefore use these registers without explicitly preserving them yourself. You should not change esp and ebp, since they are usually used to address local variables.
Therefore, my updates immediately after in the two documentation pages:
- In ASM documentation page:
When an Asm block is opened, the registers ebx, esi, and edi are pushed to the stack, when the block is closed, these registers are popped back from the stack. This is because these registers are required to be preserved by most or all OS's using the x86 CPU. You can therefore use these registers without explicitly preserving them yourself. You should not change esp and ebp, since they are usually used to address local variables.
Note: Inside a Naked procedure, there is no such register preservation.
- In NAKED documentation page:
Naked allows the programmer to write procedures without the compiler generating any prolog/epilog code.
This is useful when writing small, fast functions in Asm without any unnecessary overhead (so, no register preservation for such Asm blocks).
Post Reply