flat assembler
Message board for the users of flat assembler.

Index > Windows > LOWORD HIWORD method

Author
Thread Post new topic Reply to topic
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 27 Aug 2008, 02:13
Hello, i was wondering if this is the best way to get LOWORD and HIWORD from a param in my window procedure?
Is there maybe a different way?
Code:
; in data section
g_width dd ?
g_height dd ?

; in window procedure
.wmsize:
   mov eax,[lparam]
   mov ebx,eax
   and eax,0xFFFF
   shr ebx,16
   mov [g_width],eax  ; LOWORD(lParam)
   mov [g_height],ebx ; HIWORD(lParam)

    


Also, one other thing...
How can i divide g_width and g_height into a float? (g_aspect = (float)g_width / (float)g_height)
I read the manual but what im coming up with just crashes.
Ok, thanks for your replies...
Post 27 Aug 2008, 02:13
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20303
Location: In your JS exploiting you and your system
revolution 27 Aug 2008, 02:20
How are you defining "best"? Best in what way? Easiest to understand? Least typing? Lowest CPU cycles used? Smallest code generated? Other?
Post 27 Aug 2008, 02:20
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 27 Aug 2008, 02:50
Code:
   mov   eax, [lparam]
   movzx edx, ax
   shr   eax, 16
   mov   [g_width], edx  ; LOWORD(lParam)
   mov   [g_height], eax ; HIWORD(lParam)    


But it is just another way, it doesn't mean that it is better nor worse.
Post 27 Aug 2008, 02:50
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 27 Aug 2008, 03:02
revolution wrote:
How are you defining "best"? Best in what way? Easiest to understand? Least typing? Lowest CPU cycles used? Smallest code generated? Other?

Yes, all of those...

LocoDelAssembly: Very nice!
Post 27 Aug 2008, 03:02
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 27 Aug 2008, 06:23
And now i need some help on how to divide those two numbers...

psuedo C code:

float g_aspect = (float)g_width / (float)g_height

In the manual it references using fild and fdiv with st0 and st1 but when i try to implement a solution i just end up crashing my program. "cry..."

I tested for a divide by zero but thats not whats causing problems, its just that i never fooled with FPU before.

Can someone convert my psuedo code to 32bit assembly?
Post 27 Aug 2008, 06:23
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 27 Aug 2008, 07:08
Code:
fild [g_width] ;Maybe you forgot FILD!?
fild [g_height]
fdiv
fstp
    

Something like that... haven't done float coding that much
I can give you SSE though
Code:
movd xmm0,edx ;before saving to g_width
cvtdq2ps xmm0,xmm0
movd xmm1,eax ;before saving to g_height
cvtdq2ps xmm1,xmm1
divps xmm0,xmm1
cvtps2dq xmm0,xmm0
movd eax,xmm0 ;Save back to eax
    

Really simple and unoptimized!!!
Post 27 Aug 2008, 07:08
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 27 Aug 2008, 07:28
back to first question: what is wrong with obvious solution?
Code:
mov ax, word [somewhere]     ;loword
mov bx, word [somewhere+2]  ;hiword    
Post 27 Aug 2008, 07:28
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20303
Location: In your JS exploiting you and your system
revolution 27 Aug 2008, 07:43
bitshifter wrote:
revolution wrote:
How are you defining "best"? Best in what way? Easiest to understand? Least typing? Lowest CPU cycles used? Smallest code generated? Other?

Yes, all of those...
But some of those are mutually exclusive, you can't have them all. You need to decide which is most important to you.
Post 27 Aug 2008, 07:43
View user's profile Send private message Visit poster's website Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 789
Location: Adelaide
sinsi 27 Aug 2008, 08:22
vid wrote:
back to first question: what is wrong with obvious solution?
Code:
mov ax, word [somewhere]     ;loword
mov bx, word [somewhere+2]  ;hiword    

Code:
movzx eax,word[lparam]
movzx edx,word[lparam+2] ;possible access violation here (1 in a 1000000)
    


As for the float, do you want the answer as a float or an integer?
Post 27 Aug 2008, 08:22
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 27 Aug 2008, 08:23
vid wrote:
back to first question: what is wrong with obvious solution?
Code:
mov ax, word [somewhere]     ;loword
mov bx, word [somewhere+2]  ;hiword    

Yes, i had played with similar method also.
Code:
proc WindowProc hwnd,umsg,wparam,lparam
...
movzx eax,word[esp+16] ; LOWORD(lparam)
mov [g_width],eax
movzx eax,word[esp+18] ; HIWORD(lparam)
mov [g_height],eax
    

Looks like you can skin this cat in many ways.
I am just learning so some of these options are unclear.
Post 27 Aug 2008, 08:23
View user's profile Send private message Reply with quote
Pinecone_



Joined: 28 Apr 2008
Posts: 180
Pinecone_ 04 Nov 2008, 14:31
how is
Code:
movzx edx,word[lparam+2]    
possible access violation?
Post 04 Nov 2008, 14:31
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 04 Nov 2008, 15:03
it's not.
Post 04 Nov 2008, 15:03
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.