I downloaded Assembly Optimization Tips by Mark Larson
The first thing in that is to free up all 8 CPU registers for use in my code.
Can someone explain how to make good use of that kind of programming and if there is some example code it's even better.
/Henke
Port, it is useful according to logic of maximization of registers use and minimizction memory use. Say you write a huge procedure with a bunch of variables so put them in regs not mem/stack...
asmfan knows what he's talking about here. In order, from fastest to slowest: registers, stack, memory. Memory can be 10-1000x slower than registers... so if you can put one of your working values into a register, versus a stack or memory location, then the routine will run much faster. :U
For general assembly programming, do not bother with freeing all the registers. The only improvment this manifests is in a loop or when that particular code is called many times. Keep in mind if that routine is called many times, the process of freeing the registers is fairly slow and might nullify or even reverse the speed gain. If all else fails, benchmark your code!
(And if you have an AMD system, check out AMD's developer pages for the CodeAnalyst... very useful program-bottleneck analysis software.)
Any example code?
I want to know how to use this even if I never will use this etc ;)
/Henke
Because you really want it:
LOCAL counter:DWORD
mov counter, 1000000
_loop:
sub counter, 1
... some code ...
cmp counter, 0
jnz _loop
is better if rewritten like: (if the looped code doesn't use ecx, of course)
mov ecx, 1000000
_loop:
sub ecx, 1
... some code which doesn't use ecx ...
cmp ecx, 0
jnz _loop
Hope you get the point.
Yup, but free all 8 registers?
/Henke
I'm not sure if you can free up esp, but here's some code that could do it. ebp can be used freely if your parameters are in registers and you don't have local variables.
; ebx/esi/edi must preserved, according to the stdcall convention
push esi
push edi
push ebx
; backup ebp and esp
push ebp
mov espbackup, esp
... code that can use all eight registers, but no local vars/stack ....
; restore registers
mov esp, espbackup
pop ebp
pop ebx
pop edi
pop esi
But I recommend limiting yourself to 6 registers or eventually 7 if you don't need local variables.
Thanks!
/Henke