flat assembler
Message board for the users of flat assembler.

Index > Windows > Very Noobish Question

Author
Thread Post new topic Reply to topic
Misha06



Joined: 18 May 2009
Posts: 8
Misha06 18 May 2009, 18:28
Hello,

I am trying to make a simple window with a dynamic text field, an input field, and a button to initialize a long arithmetic computation.

Could somebody point me to a source where I could find a reference to the API functions I will need...

Also, I'm wonder what is the basic structure of a Win32 FASM program - is there some sort of Window class I need to initialize before I begin?

I am familiar with C# and Java.


Last edited by Misha06 on 19 May 2009, 00:31; edited 1 time in total
Post 18 May 2009, 18:28
View user's profile Send private message Reply with quote
pelaillo
Missing in inaction


Joined: 19 Jun 2003
Posts: 878
Location: Colombia
pelaillo 18 May 2009, 22:01
Please look at the MINIPAD example in fasm download. It has everything you need except the arithmetic computation. The menu will do the same work as the button you want (the button could be added later).

The structure of the example is what a win32 fasm program should look like.
Post 18 May 2009, 22:01
View user's profile Send private message Yahoo Messenger Reply with quote
Misha06



Joined: 18 May 2009
Posts: 8
Misha06 19 May 2009, 00:26
Thank you for your help,

I was wondering about this piece of code:
Code:
Include '%fasminc%/win32ax.inc'
.data
msgBoxCaption db 'Caption',0
value         db 65
NumberOfLoops db 10
.code 
        start:
                mov eax,value
                mov ecx,NumberOfLoops
                CodeToSpin:
                         invoke  MessageBox, NULL, eax, msgBoxCaption, MB_OK
                Loop CodeToSpin
                invoke  ExitProcess,0
       .end start
    



I am expecting the program to count by decrements of 1, displaying the letter "K" - The first letter displays but then the program crashes. What am I doing wrong?
Post 19 May 2009, 00:26
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 19 May 2009, 02:33
Quote:

What am I doing wrong?

Several error here, one is that you moved to ecx the address of NumberOfLoops rather than its actual content (ten). Since the size of the variable is a byte and ECX is a dword (i.e., four bytes), you have to use "movzx ecx, [NumberOfLoops]" (note the square brackets).

But then, a second problem arises, you are using a register considered volatile for the stdcall calling convention, this is, its contents may be destroyed (you have to always assume this will happen not matter whether a particular API function preserves it or not), along with EAX and EDX after a function call.

So, to solve this problem you have to either, use another register (e.g., ESI, EBX or EDI) and replace the loop instruction with "dec reg/jnz CodeToSpin" (reg is the one you have selected), or you can use "push ecx" before calling MessageBox and "pop ecx" immediately after the function call.

And the last problem is that you are passing to MessageBox the address of a byte value. Note that in Assembly none of the data types descend from Object so this means there is no ToString() method binded to them which also means that MessageBox will not receive the expected null-terminated string. So, value declaration should be "value db 75, 0" or "value db 'K', 0". Then on the MessageBox call you need to use a different register than EAX because it is volatile and hence not preserved after MessageBox call (or just pass the address of the variable).

Check if this is what you are expecting:
Code:
Include '%fasminc%/win32ax.inc' 
.data
msgBoxCaption db 'Caption',0

value         db 75, 0 ; It was working before but just by coincidence (the 10 below is "\n" and what comes later is garbage that probably was zero when you executed the program).
NumberOfLoops db 10

.code
        start:
                movzx ecx, [NumberOfLoops]
                CodeToSpin:
                         push    ecx
                         invoke  MessageBox, NULL, value, msgBoxCaption, MB_OK
                         pop     ecx
                Loop CodeToSpin
                invoke  ExitProcess,0
       .end start    
Post 19 May 2009, 02:33
View user's profile Send private message Reply with quote
Misha06



Joined: 18 May 2009
Posts: 8
Misha06 19 May 2009, 03:12
This is exactly what I was looking for, thank you very much - for now my problems are solved.
Post 19 May 2009, 03:12
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 19 May 2009, 05:18
This reminds me that we don't have a "coming from HLL"-section that describes:
Code:
                C & related     ASM & related
                =============== ================
address:        &memory         memory
content:        memory          [memory]

byte:           char            db (define byte)
two bytes:      short int       dw (..word)
four bytes:     int             dd (..dword)
eigth bytes:    longlong        dq (..qword)
    

etc. Smile
Post 19 May 2009, 05:18
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 19 May 2009, 17:14
Also this for pointers and dereferencing them...
Code:
               C & related     ASM & related 
               =============== ================ 
pointer:        memory         memory 
derefed:       *memory         [memory]
    

_________________
Coding a 3D game engine with fasm is like trying to eat an elephant,
you just have to keep focused and take it one 'byte' at a time.
Post 19 May 2009, 17:14
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20514
Location: In your JS exploiting you and your system
revolution 19 May 2009, 17:18
So does "*&" give me the value of a variable?
Code:
int a, b;
a=0;
b=4;
a += *&b;    
Post 19 May 2009, 17:18
View user's profile Send private message Visit poster's website Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 19 May 2009, 17:26
NonSyntaxically, yes.

a += *(int*)&b;

asm is so much easier than C/C++ for doing this stuff...
Post 19 May 2009, 17:26
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20514
Location: In your JS exploiting you and your system
revolution 19 May 2009, 17:29
So b loses it's int type when the & is put there?
Post 19 May 2009, 17:29
View user's profile Send private message Visit poster's website Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 19 May 2009, 17:34
The type cast is required for pointer to know its size (type)

_________________
Coding a 3D game engine with fasm is like trying to eat an elephant,
you just have to keep focused and take it one 'byte' at a time.
Post 19 May 2009, 17:34
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20514
Location: In your JS exploiting you and your system
revolution 19 May 2009, 18:04
But b is already an int.
Post 19 May 2009, 18:04
View user's profile Send private message Visit poster's website Reply with quote
manfred



Joined: 28 Feb 2009
Posts: 43
Location: Racibórz, Poland
manfred 19 May 2009, 19:21
* and & have same priority and associativity (associa... whatever), so, regardless of variable's type, *&foo returns foo... But I'm not sure.

_________________
Sorry for my English...
Post 19 May 2009, 19:21
View user's profile Send private message Visit poster's website Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2465
Location: Bucharest, Romania
Borsuc 20 May 2009, 00:55
revolution wrote:
So does "*&" give me the value of a variable?
why do you ask? is it illogical to you? Confused

_________________
Previously known as The_Grey_Beast
Post 20 May 2009, 00:55
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20514
Location: In your JS exploiting you and your system
revolution 20 May 2009, 01:32
Just trying to understand a little more about it. C has always been an enigma with me.
Post 20 May 2009, 01:32
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 20 May 2009, 02:13
However, I must say that bitshifter's table may not be really accurate. If we suppose for a moment that "memory" is of type "int *", then I would construct the table this way:

Code:
               C & related     ASM & related 
               =============== ================ 
reference:      &memory        memory
pointer:        memory         [memory] 
derefed:       *memory         reg <- [memory] / [reg] ([[memory]] if double indirection were supported)     
Post 20 May 2009, 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: 20514
Location: In your JS exploiting you and your system
revolution 20 May 2009, 02:19
So in my example above, does b lose it's int type when the & is put there?
Post 20 May 2009, 02:19
View user's profile Send private message Visit poster's website Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 20 May 2009, 06:22
No, for instance these retain their type without need of type casting...

int a = 0;
int *b = &a;
int *c = b;
int d = *c;

_________________
Coding a 3D game engine with fasm is like trying to eat an elephant,
you just have to keep focused and take it one 'byte' at a time.
Post 20 May 2009, 06:22
View user's profile Send private message 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.