I've just run out of registers for a very complicated algo. However I'm not currently using ebp or esp.

What do I have to do to allow me to use these safely for the algo. No locals, procedures or stack usage takes place in it.

Posted on 2001-11-08 17:17:16 by Eóin
Hi E?in !

You may use ebp the way you like ! In my opinion it's a damned stupid rule to reserve this register for addressing local variables only. It is a relict from implementing hll-syntax in assembler. (See also the enter / leave-stuff ...)

And also you can access local vars using the esp-register. The only restriction may be in 16-bit code without segment-overriding, because bp is assigned to ss instead of ds by default, but driving windows ss und ds have the same values !

Using the esp is a bit difficult because before overriding the esp-register you have to lock all interrupts. (It may be that there are still some IRQ-events which cannot be canceled by the CLI-instruction - I'm not sure at all !)

Even if you success in locking all interrupts you cannot do calls to sub-routines easily ...

But what about (mis)using the mmx-registers ?

Greetings, CALEB
Posted on 2001-11-08 17:29:22 by Caleb
Do not, I repeat, do NOT use the esp register for anything
but the stack. This leads to all kinds of errors.

If you don't use locals, just push/pop ebp (or "USES EBP"),
and you'll be fine messing with ebp.

Reserving ebp for locals/var access is not stupid/relic. It
makes the work of the assembler easier (doesn't have
to monitor pushes/pops to access through esp).

and it makes your code so much easier to follow in a debugger :)
Posted on 2001-11-08 17:40:03 by f0dder
I'm working on macros to allow 'non-frame' coding w/o having to monitor stack usage, but you must use macros instead of push/pop/call/ret. All kinds of fun coding can happen with these macros. :) Like organizing the code into logical layers and returns to several frames down. I've got some bugs to work out still. One of the primary benefits is you get EBP for your own uses.
Posted on 2001-11-08 18:09:42 by bitRAKE

In your situation you can use EBP but unless you want endless messy problems, leave ESP alone, it more hassle than its worth.

What I tend to do when I am developing a messy algo is to mainly use memory operands when I am designing it and once its running, I start replacing them with registers on the basis of what runs faster with or without registers.

If you manage it properly, you rarely have to use the stack and memory operands are not always slower. Its good practice doing the optimisations after as well.


Posted on 2001-11-08 19:46:22 by hutch--