Playing with Notepad.exe code, I found some strange code procedures...

One oh this is in the RegisterClassEx procedure:

push ebp
mov ebp, esp
sub esp, 30h ; Space for WNDCLASSEX structure
mov , 30h ; cbSize member of WNDCLASSEX
push ebx
push edi
push 29h ; nIndex, system metric or configuration setting
; to retrieve (SM_CYMIN, minimum height in pixel)
call ds:GetSystemMetrics
cmp eax, 1 ; <-- THIS IS STRANGE !!!
mov eax, 7F01h
adc eax, 0FFFFFFFFh
xor ebx, ebx
push eax ; lpCursorName
push ebx ; hInstance
call ds:LoadCursorA
etc. etc.

The proggie call a GetSystemMetrics API, compare it's return value with one, but don't use the result in any way (???)

Anyone know why ???

BTW, it's very strange even the way to put 7F00h (IDC_WAIT == the hourglass cursor) into eax:

mov eax, 7F01h
adc eax, 0FFFFFFFFh


All the programs are coded this way ???

Bye, Saiwa
Posted on 2001-11-02 03:25:44 by Saiwa
I didnt look up in my asm book, but I think, the <cmp> sets the
flags, including the (c)arry flag. The <adc> adds with set carry
-1 (0FFFFFFFFh) plus 1 (carry flag) = 0, otherwise if not set only -1.

This is a nice example of "optimized" C compiler output, which is
normally far from optimized :)

I saw similar crap that was compiled from something like this:
x = (flag ? 2 : 1), where the compiler did a <test> and then
<sbc>, <adc> and so on ...
Posted on 2001-11-02 03:49:32 by beaster
The scarry thing for me is when you get used to reading this kind of code! ;)
This code might be faster than a branch, if the pipeline is deep enough - P4?
Posted on 2001-11-02 04:17:57 by bitRAKE
Ok, this is a little more clear... but I can't still understand the call to GetSystemMetric API.

BTW, this is a good example about different behaviours of C and ASM: what You write in ASM is what will be executed !!! (Maybe a Crusader thread...)

Thanx, Saiwa
Posted on 2001-11-02 04:19:03 by Saiwa