flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
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. |
|||
![]() |
|
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? |
|||
![]() |
|
LocoDelAssembly 19 May 2009, 02:33
Quote:
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 |
|||
![]() |
|
Misha06 19 May 2009, 03:12
This is exactly what I was looking for, thank you very much - for now my problems are solved.
|
|||
![]() |
|
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. ![]() |
|||
![]() |
|
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. |
|||
![]() |
|
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; |
|||
![]() |
|
bitshifter 19 May 2009, 17:26
NonSyntaxically, yes.
a += *(int*)&b; asm is so much easier than C/C++ for doing this stuff... |
|||
![]() |
|
revolution 19 May 2009, 17:29
So b loses it's int type when the & is put there?
|
|||
![]() |
|
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. |
|||
![]() |
|
revolution 19 May 2009, 18:04
But b is already an int.
|
|||
![]() |
|
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... |
|||
![]() |
|
Borsuc 20 May 2009, 00:55
revolution wrote: So does "*&" give me the value of a variable? ![]() _________________ Previously known as The_Grey_Beast |
|||
![]() |
|
revolution 20 May 2009, 01:32
Just trying to understand a little more about it. C has always been an enigma with me.
|
|||
![]() |
|
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) |
|||
![]() |
|
revolution 20 May 2009, 02:19
So in my example above, does b lose it's int type when the & is put there?
|
|||
![]() |
|
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. |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.