Thought this might be of use for some. My new adjust code for MELT... can it be better?

CheckPos proc uses esi edi

; esi = app left
; edi = app top

push 0
lea eax, [DeskRect]
push eax
push 0
call SystemParametersInfo

lea eax, [AppRect]
push eax
push [hMain]
call GetWindowRect

mov esi, [AppRect.left] ; save app left
mov edi, [] ; save app top

mov ecx, [AppRect.left]
test ecx, ecx ; check to see if left edge is off screen
jns CheckRight ; it's not, check right

FixLeft: ; left edge was off screen
xor esi, esi ; set app left to 0

mov eax, [DeskRect.right]
mov ecx, [AppRect.right]
cmp ecx, eax ; is right edge > desktop right edge?
jng CheckBottom ; nope, now check bottom

FixRight: ; right side off screen
mov esi, eax
sub esi, 450 ; sub window width from desktop right

mov eax, [DeskRect.bottom]
mov ecx, [AppRect.bottom]
cmp ecx, eax ; is bottom edge off screen?
jng CheckTop ; nope, check the top

FixBottom: ; bottom is off screen
mov edi, eax
sub edi, 383 ; sub window height from desktop bottom

mov eax, []
mov ecx, []
test ecx, ecx ; is top off screen?
jns FixIt ; nope, position the window

FixTop: ; top is off screen
xor edi, edi ; set top to 0

push 0
push 0
push edi
push esi
push [hMain]
call SetWindowPos


CheckPos endp
Posted on 2003-05-16 09:14:38 by Gunner
It can be optimized a lot - for example...
lea eax,something
push eax
could be replaced with simply
push OFFSET something

But really, we are talking about a few bytes this way or that - the code is very clean and well written, but makes little use of high level directives which could half the length of the source itself without losing human readability.
Don't you trust the compiler much? Your coding style is very explicit.
Posted on 2003-05-17 10:40:34 by Homer
I trust the assembler somewhat. Since I am an ex-VBer, I try to stay away from .if/.endif stuff. I do use it once in a while. I like to code as it will be assembled into an exe, knowing exactly what is going on. As to making the source smaller, doesn't bother me a bit, just get better at typing :-) this way is also easier for me to understand when I am browsing my source... the nested .if/.endif are a bit confusing to follow sometimes.

How can I replace:
lea eax,something
push eax
with offset something if the vars are local and the address is not known at assembly time?

What do you mean my coding style is very explicit, in a good way I take it?
Posted on 2003-05-17 11:32:09 by Gunner
Take it as a compliment. My code is so unclear and uncommented that I can get headache looking at my codes :). Anyway, push 0 is every byte cosuming. Better to replace with xor reg,reg/sub reg,reg(2 bytes) and push reg (1byte). lea eax, push eax cannot be replaced by offset. And won't it be better to just use eax, edx and ecx so that you do not need to preserve esi and edi?
Posted on 2003-05-17 11:59:02 by roticv