flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
revolution 06 Mar 2009, 03:12
Remember that local variables are on the stack. So each time the procedure is called it would need to initialise the stack with the string.
Code: proctest: sub esp,8 ;make space for string mov byte[esp+0],'a' mov byte[esp+1],'b' mov byte[esp+2],'c' mov byte[esp+3],13 mov byte[esp+4],10 mov byte[esp+5],0 mov eax,esp ;point to the beginning of the string invoke MessageBox,HWND_DESKTOP,eax,"test",MB_OK |
|||
![]() |
|
nazha 06 Mar 2009, 03:17
Thanks!
|
|||
![]() |
|
Tomasz Grysztar 06 Mar 2009, 04:06
The macros can do it automatically for you, too, but you need to use the "locals" macro:
Code: proc proctest locals var1 TCHAR 'abc',13,10 endl invoke MessageBox,HWND_DESKTOP,addr var1,"test",MB_OK ret endp endp |
|||
![]() |
|
rugxulo 09 Mar 2009, 01:41
nazha wrote:
Hey, isn't that a girl's name? I only ask since everybody here on this forum always whines because everyone's a dude. (Not trying to pry ....) |
|||
![]() |
|
nazha 18 Mar 2009, 05:53
no, nazha(哪吒, baby-faced Nezha) is a heavenly general's name from Chinese classical novel <<Journey to the West>>.
|
|||
![]() |
|
rugxulo 19 Mar 2009, 04:16
Okay, just curious since my great-grandfather's sister was named that (but you probably pronounce it differently, tom_tobias probably knows how, not me!!).
![]() |
|||
![]() |
|
fatygant 04 Feb 2012, 11:53
Tomasz Grysztar wrote: The macros can do it automatically for you, too, but you need to use the "locals" macro: Tomasz, has something changed since the time you gave nazha the hint above? My FASM complains about the following piece of code with 'illegal instruction' error in blue line declaration (and all following too of course): Code: proc CreateDeviceResources locals blue D2D1_COLOR_F 0.0,0.0,1.0,1.0 brushproperties D2D1_BRUSH_PROPERTIES 1.0,<1.0,0.0,0.0,1.0,0.0,0.0> RenderTargetProperties D2D1_RENDER_TARGET_PROPERTIES \ D2D1_RENDER_TARGET_TYPE_DEFAULT,\ <DXGI_FORMAT_UNKNOWN,D2D1_ALPHA_MODE_UNKNOWN>,\ 0.0,0.0,\ D2D1_RENDER_TARGET_USAGE_NONE,\ D2D1_FEATURE_LEVEL_DEFAULT HwndRenderTargetProperties D2D1_HWND_RENDER_TARGET_PROPERTIES endl ... ; proc code goes here endp Even worse: it complains about uninitialized version of above too. The only version which assembles fine is: Code: proc CreateDeviceResources local blue:D2D1_COLOR_F ;0.0,0.0,1.0,1.0 local brushproperties:D2D1_BRUSH_PROPERTIES ;1.0,<1.0,0.0,0.0,1.0,0.0,0.0> local RenderTargetProperties:D2D1_RENDER_TARGET_PROPERTIES; D2D1_RENDER_TARGET_TYPE_DEFAULT,\ ;<DXGI_FORMAT_UNKNOWN,D2D1_ALPHA_MODE_UNKNOWN>,\ ; 0.0,0.0,\ ; D2D1_RENDER_TARGET_USAGE_NONE,\ ; D2D1_FEATURE_LEVEL_DEFAULT local HwndRenderTargetProperties:D2D1_HWND_RENDER_TARGET_PROPERTIES ; proc code goes here endp Why? I can initialize the structures in the code - no problem. But why I can't do it within locals? |
|||
![]() |
|
JohnFound 04 Feb 2012, 12:11
Hm, don't you all think, the above approach to the constants is highly bloated and what is worse, the bloat is hidden from the programmer behind the macros. Initializing local variables is OK, but initializing local constants is really excessive.
|
|||
![]() |
|
revolution 04 Feb 2012, 12:12
fatygant: Show how you have defined D2D1_COLOR_F and the other structures. Did you use struct/ends for some other method?
|
|||
![]() |
|
fatygant 04 Feb 2012, 16:31
The structures definition is quite ordinary IMO:
Code: struct D3DCOLORVALUE
r dd ?
g dd ?
b dd ?
a dd ?
ends
D2D_COLOR_F equ D3DCOLORVALUE
D2D1_COLOR_F equ D2D_COLOR_F
struct D2D1_BRUSH_PROPERTIES
opacity dd ?
transform D2D_MATRIX_3X2_F
ends
struct D2D_MATRIX_3X2_F
_11 dd ?
_12 dd ?
_21 dd ?
_22 dd ?
_31 dd ?
_32 dd ?
ends
D2D1_MATRIX_3X2_F equ D2D_MATRIX_3X2_F
struct D2D1_RENDER_TARGET_PROPERTIES
type dd ?
pixelFormat D2D1_PIXEL_FORMAT
dpiX dd ?
dpiY dd ?
usage dd ?
minLevel dd ?
ends
struct D2D1_HWND_RENDER_TARGET_PROPERTIES
hwnd dq ?
pixelSize D2D_SIZE_U
presentOptions dd ?,?
ends
struct D2D_SIZE_U
width dd ?
height dd ?
ends
D2D1_SIZE_U equ D2D_SIZE_U
struct D2D1_PIXEL_FORMAT
format dd ?
alphaMode dd ?
ends |
|||
![]() |
|
LocoDelAssembly 04 Feb 2012, 19:28
I don't know if this is the proper fix, but the following modification (besides arranging the structure declarations in such a way they don't have forward references to other structures) works:
Code: ;D2D_COLOR_F equ D3DCOLORVALUE D2D_COLOR_F fix D3DCOLORVALUE ;D2D1_COLOR_F equ D2D_COLOR_F D2D1_COLOR_F fix D3DCOLORVALUE ; Notice I'm not chaining the definitions because fasm will replace only once |
|||
![]() |
|
fatygant 04 Feb 2012, 20:47
Loco, amazing - it really works now. Thank you!
I am reading about equ and fix directives - but I only understand the inner workings of the first one... fix sounds like Chinese to me. No offense to Chinese meant. |
|||
![]() |
|
LocoDelAssembly 04 Feb 2012, 21:22
This may help to understand how equ and fix works:
Code: TEST2 equ ASSEMBLY TEST3 fix ASSEMBLY3 TEST4 equ TEST2 TEST5 fix TEST3 ; Using macro to enable backtick use macro tests { display `TEST1, 13, 10 display `TEST2, 13, 10 display `TEST3, 13, 10 display `TEST4, 13, 10 display `TEST5, 13, 10 } tests display '---', 13, 10 match sym, TEST1{display `sym, 13, 10} match sym, TEST2{display `sym, 13, 10} match sym, TEST3{display `sym, 13, 10} match sym, TEST4{display `sym, 13, 10} match sym, TEST5{display `sym, 13, 10} output wrote: TEST1 |
|||
![]() |
|
fatygant 05 Feb 2012, 10:03
Loco, perhaps I am intellectualy disabled but I still don't get it (why it worked without struct initialization?). Anyhow, thank you very much for your efforts to make the whole thing more clear to me. And for fixing the bug of course!
|
|||
![]() |
|
LocoDelAssembly 05 Feb 2012, 18:38
Not only the initialization fails, fasm's preprocessor doesn't even recognize D2D1_COLOR_F as an structure in your original code and hence you get the invalid instruction error (because fasm's assembler stage thinks you are using the non-existent "blue" instruction followed by D2D1_COLOR_F operand). With fix, the preprocessor replaces all the symbols that match any of the fixes declared earlier, and THEN it begins normal preprocessing of the line (which this time it will be recognized as a structure invocation because after fixing the preprocessor will see "blue D3DCOLORVALUE ..."). With equ, unless you use match directive first, the preprocessor will see "blue D2D1_COLOR_F ..." and since D2D1_COLOR_F is not an struct, the preprocessor will pass the line to the assembler stage verbatim.
PS: In case I haven't been clear enough above, what I meant is that with the following code you should also get illegal instruction error even though there are no initializations here: Code: locals blue D2D1_COLOR_F brushproperties D2D1_BRUSH_PROPERTIES RenderTargetProperties D2D1_RENDER_TARGET_PROPERTIES HwndRenderTargetProperties D2D1_HWND_RENDER_TARGET_PROPERTIES endl |
|||
![]() |
|
fatygant 05 Feb 2012, 19:44
Loco, this is strange... I came back to the errorneus equ version of my struct declaration and I of course still get the error: 'illegal instruction' but assembler claims it can not recognize the instruction... and now surprise: blue D3DCOLORVALUE (see enclosed picture). Seeing this error I had not suspected equ to be my problem (D2D1_COLOR_F was properly recognized as D3DCOLORVALUE). And when I was talking about the version which assembles fine - I meant the one wit local blue:D2D1_COLOR_F instead of locals-endl pair.
I hope you are not totally bored yet with all my doubts and you will take a look at this one more time... ![]()
|
||||||||||||||||||||
![]() |
|
LocoDelAssembly 05 Feb 2012, 20:31
Sorry, when I've said "verbatim" it is not so literal, before passing the line to the assembler stage, all equates are resolved, so the assembler gets "blue D3DCOLORVALUE" which means nothing to it.
I didn't notice that the local version worked, but that is because local is a macro and the variable(s) are passed as parameters, and since them are processed with match, the equates are resolved. Search for "macro local" in \INCLUDE\MACRO\PROC32.INC so you can see how match is used there and also "macro locals" where you'll see that it doesn't process your locals declarations one by one but instead it redefines basic data definition directives so it can detect what are you defining between locals and endl. |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.