-4

80386-80686+: isn't recommended use of EBX register by software programmers, because is a particular register of CPU, or couldn't it be used because the O.S. (as for as Windows) need it for some reasons...?

But if i save it into the stack before using it (and restore it on exit) what problems could exist ? What may be the consequences ?

With this simply routine to emulate sprites management I use the EBX register, but it seems, only under Windows 7.0 and ACER machines the video game i've created slow down. is only a doubt...

my answer: Because each program need of data area or (16 Bit) data segment and the EBX register in Delphi is used to save this data pointer each write to EBX slow down my program.

Procedure Sub_MoveSprite; Assembler;

/* Sub-ROUTINE per MoveSprite (FlipX-FlipY).

 INPUT:

    EAX= Attributi immagine.
    EBX= Scarto X per origine.
    ECX= Quantità X di Pixel per LINEA.
    EDX= Quantità Y di linee da trasf.
    EBP= Scarto X per destinazione.
    ESI= OFFSET per origine.
    EDI= OFFSET per destinaz */

Asm

     Push  EBP
     Push  EBX
     Push  ECX

     BT    EAX,Def_Target_DirX_D
     SbB   EBP,EBP
     LEA   EBP,[2*EBP+1]

     BT    EAX,Def_Source_DirX_D
     SbB   EBX,EBX
     LEA   EBX,[2*EBX+1]

@@01:Mov   AL,[ESI]
     Cmp   AL,AH
     JE    @@00
     Mov   [EDI],AL
@@00:Add   ESI,EBX
     Add   EDI,EBP
     Loop  @@01

     Mov   ECX,[ESP]

     Add   ESI,[ESP+4]
     Add   EDI,[ESP+8]

     Dec   EDX
     JNE   @@01

     Add   ESP,12

End;

Excuse me, mr. Peter Cordes, but I answer only one cause of setbacks. My tests are: INTEL COMPAQ NX7400 portable 2 GHz with 2 GB of RAM, AMD ASUS X53U portable 1 GHz with 2 GB of RAM and SVGA RADEON, AMD SEMPRON (tm) 2400+, 1.68 GHz, 1 GB of RAM, SVGA NVIDIA GeForce 6600, main. O.S. Windows XP. But I only had a suspicion on it problem that causes some little-time blink-breaks on running of a my software. This problem was also mentioned by some Stack Overflow users (EBX register).

The code are all that seems uses ASM on Borland Delphi 7.0 and access to EBX register after previously push it on the stack on entry code en pop it from the stack on exit.

I state that I use a strategy of polling and non a management of events by objects, with exception for to the main form, that uses a system timer that does the main-program-procedure, more management events OnPaint (which does not synchronize the optical brush, but this is not the problem ), OnActivate, OnCreate, OnDestroy, FormKeyUp/ Down and MouseClick.

The problem is that my software goes slightly jerky at a distance of variable frequencies and I do not even understand what it depends on.

I nested the code here. Why other code colud be needed to explained all? Now, why, except for the cpu: INTEL/AMD 80386+, PENTIUM (double core) and others similar that i've used for tests i have explained all, perhaps.

Paolo Fassin
  • 361
  • 2
  • 11
  • 3
    If anything, that's due to delphi. In normal code you may very well use `EBX` it's just another callee-saved register) – Jester Jan 06 '18 at 16:28
  • 'save it into the stack before using it (and restore it on exit) what problems could exist ?' - I would hope none:) – Martin James Jan 06 '18 at 16:38
  • Slows down compared to what? You haven't shown the code that this is even slower than. You also didn't say what CPU you're testing on, or anything required to answer the performance question (e.g. profiling with performance counters to see what's running slower). – Peter Cordes Jan 07 '18 at 05:09
  • Dearest Jester, perhaps I have not explained it well: it is obvious that I can use the EBX register also in delphi. I wondered for myself a question to which the only obvious answer is not the one you gave: I speak of performance, not anything else. I added my answer: Because each program need of data area or (16 Bit) data segment and the EBX register in Delphi is used to save this data pointer each write to EBX slow down my program... – Paolo Fassin Jan 27 '18 at 21:18
  • Excuse me, mr. Peter Cordes, but I answer only one cause of setbacks. My tests are: INTEL COMPAQ NX7400 portable 2 GHz with 2 GB of RAM, AMD ASUS X53U portable 1 GHz with 2 GB of RAM and SVGA RADEON, AMD SEMPRON (tm) 2400+, 1.68 GHz, 1 GB of RAM, SVGA NVIDIA GeForce 6600, main. O.S. Windows XP. But I only had a suspicion on it problem that causes some little-time blink-breaks on running of a my software. This problem was also mentioned by some Stack Overflow users (EBX register). to be continued ... – Paolo Fassin Apr 11 '18 at 21:39
  • (continue) The code are all that seems uses ASM on Borland Delphi 7.0 and access to EBX register after previously push it on the stack on entry code en pop it from the stack on exit. To be continued ... – Paolo Fassin Apr 11 '18 at 21:40
  • (continue) I state that I use a strategy of polling and non a management of events by objects, with exception for to the main form, that uses a system timer that does the main-program-procedure, more management events OnPaint (which does not synchronize the optical brush, but this is not the problem ), OnActivate, OnCreate, OnDestroy, FormKeyUp/ Down and MouseClick. To be continued ... – Paolo Fassin Apr 11 '18 at 21:42
  • (continue) The problem is that my software goes slightly jerky at a distance of variable frequencies and I do not even understand what it depends on. (finish). – Paolo Fassin Apr 11 '18 at 21:43
  • And, excuse me sir., but I nested the code here. Why other code colud be needed to explained all? Now, why, except for the cpu: INTEL/AMD 80386+, PENTIUM (double core) and others similar that i've used for tests i have explained all, lost I 2 points of reputation ? I'm beginner on Stack Overflow... – Paolo Fassin Apr 11 '18 at 22:05
  • *This problem was also mentioned by some Stack Overflow users (EBX register).* Yes, people have mentioned EBX on stack overflow. But what about it? Can you include some links? I've never used Delphi for anything, so if something is weird about using EBX in Delphi, I have no idea. Jester's first comment says everything I know: it's just another call-preserved reg. I haven't voted on this question because I don't know enough about Delphi to know if the entire question is nonsense, or if there's a real issue anywhere in this mess. – Peter Cordes Apr 12 '18 at 12:26
  • I still have no idea what you're measuring, or trying to explain. All you've mentioned are some subjective "software gets jerky" stuff with a huge amount of code involved. No [mcve] of a correctness or performance problem. If you care about performance, your first step should be to avoid [the slow `loop` instruction](https://stackoverflow.com/questions/35742570/why-is-the-loop-instruction-slow-couldnt-intel-have-implemented-it-efficiently). – Peter Cordes Apr 12 '18 at 12:28
  • I supposed that EBX register in old Intel CPU and in real mode threats it as a part of DS segment register if OS is Windows XP and a program run at 32 bit when an 16 bit application (es. T.S.R.) is loaded into the R.A.M. But I've no specified it. Wrong question ? – Paolo Fassin Oct 06 '19 at 14:05

1 Answers1

2

It depends entirely on the platform (OS) and the "calling conventions". See "register preservation" here: https://en.wikipedia.org/wiki/X86_calling_conventions

Caller-saved registers (aka "volatile registers") are used to hold temporary quantities that need not be preserved across calls. Callee-saved registers (aka "non-volatile registers") are used to hold long-lived values that should be preserved across calls.

If your software routine doesn't follow the rules for EBX for your particular system, then you will likely create undefined behavior. A caller may expect EBX to not be touched, OR, you may find EBX modified after your code calls a subroutine.

payne
  • 13,833
  • 5
  • 42
  • 49
  • I use call convenction that use EAX, EDX, ECX registers parameters', in this order, without stack-frame as explained after. I not ask to solve obvious problem. – Paolo Fassin Jan 06 '18 at 16:51
  • All right, thank you. You've solved my first doubt. What do you think about my graphic-sprite-emulation routine ? – Paolo Fassin Jan 06 '18 at 16:57