flat assembler
Message board for the users of flat assembler.
Index
> Windows > Problem in allocating values to the fields of a structure |
Author |
|
mns 24 Dec 2020, 16:56
When I allocate values to the members of D3DXCOLOR structure as below assembled program don't work correctly(desired colour won't show) ,
(all files are attached). Code: ;------------------------------------RenderFrame-------------------------------------------- proc RenderFrame push ebx esi edi colorStrct2 D3DXCOLOR 1.0,0.3,0.2,0.8 cominvk devCntxt, ClearRenderTargetView,[BkBuffRndrTrgtVw],colorStrct2 cominvk swapchain,Present,0, 0 pop edi esi ebx ret endp ;---------------------------------------------------------------------------------------------- but if the values were allocated as below assembled program worked correctly. Code: proc RenderFrame push ebx esi edi mov [colorStrct1.r],1.0 mov [colorStrct1.g],0.3 mov [colorStrct1.b],0.2 mov [colorStrct1.a],0.8 cominvk devCntxt, ClearRenderTargetView,[BkBuffRndrTrgtVw],colorStrct1 cominvk swapchain,Present,0, 0 pop edi esi ebx ret endp Please someone can help (I'm trying to learn directx 11 with FASM from a tutorial written in C++ and if the previous one is working, I can apply that to other structures and it will reduce great deal of code typing)
|
|||||||||||
24 Dec 2020, 16:56 |
|
mns 24 Dec 2020, 18:40
Thank you very much Roman for the help, the second solution worked well and first solution brings the desired colour but the program crashes after few seconds.
Still I don't understand the original problem. Is it a problem of struct macro? |
|||
24 Dec 2020, 18:40 |
|
bitshifter 24 Dec 2020, 18:49
the problem is executing data not code
_________________ 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. |
|||
24 Dec 2020, 18:49 |
|
Roman 24 Dec 2020, 20:40
I think need
section '.code' code readable writeable executable And check esp. Maybe esp flowed. using this for see on window border info: Code: cinvoke sprintf,pText,'ESP %d',esp invoke SetWindowText,[hwnd],pText in data: pText db 128 dup (0) |
|||
24 Dec 2020, 20:40 |
|
mns 25 Dec 2020, 03:22
Thank you very much Roman and bitshifter for your kind replies.
Roman I tried to display esp register using your code (by importing -msvcrt, 'msvcrt.dll' )but the program crashesd. When allocated the values to the structure, in the section '.data' , program worked fine. It seems declaring the structure locally made the program to crash. |
|||
25 Dec 2020, 03:22 |
|
revolution 25 Dec 2020, 03:31
It isn't that you declared them locally that causes the problem. It is that you declared them inline with executable code. The CPU tries to execute that data because that is what it sees as the next instruction.
If you declared them either before or after the executable code then it would be fine, but you have to make sure the values are properly initialised each time, since the stack only lasts as long as the function is active. |
|||
25 Dec 2020, 03:31 |
|
mns 25 Dec 2020, 04:34
Thank you revolution.
(bear with me if this question is foolish) if the structure defined as local variable as below, Code: locals colorStrct2 D3DXCOLOR 1.0,0.3,0.2,0.8 endl will it still be declaring inline with executable code? |
|||
25 Dec 2020, 04:34 |
|
revolution 25 Dec 2020, 04:36
locals/endl is a good place for the structure. It exists on the stack, not in the code stream.
|
|||
25 Dec 2020, 04:36 |
|
mns 25 Dec 2020, 04:46
Thank you revolution. But then the assembler complain as, it is invalid value, when it use in
cominvk devCntxt, ClearRenderTargetView,[BkBuffRndrTrgtVw],colorStrct2 and if used as below cominvk devCntxt, ClearRenderTargetView,[BkBuffRndrTrgtVw],[colorStrct2] it assembled but the program crashes. |
|||
25 Dec 2020, 04:46 |
|
revolution 25 Dec 2020, 04:52
You need the address of the structure:
Code: cominvk devCntxt, ClearRenderTargetView,[BkBuffRndrTrgtVw],addr colorStrct2 |
|||
25 Dec 2020, 04:52 |
|
mns 25 Dec 2020, 08:22
thanks revolution. so then it should be
Code: cominvk devCntxt, ClearRenderTargetView,[BkBuffRndrTrgtVw],colorStrct2 which make compiler to complain as "invalid value". (when colorStrct2 declared as local variable.) any help is appreciated. |
|||
25 Dec 2020, 08:22 |
|
revolution 25 Dec 2020, 08:23
I posted the syntax above. Use addr
|
|||
25 Dec 2020, 08:23 |
|
mns 26 Dec 2020, 10:31
(sorry to take long time to respond)
Thank you very much revolution, your solution worked. (I had to change include file from WIN32A.inc to WIN32AX.inc for addr ). I thought a variable without Square Brackets mean address of the variable in FASM. anyway thanks again. |
|||
26 Dec 2020, 10:31 |
|
revolution 26 Dec 2020, 10:38
mns wrote: I thought a variable without Square Brackets mean address of the variable in FASM. When the address is a stack location there is no fixed value. It is computed at runtime. So when you put addr it generates something like: Code: lea edx,[ebp+offset] push edx Code: push address Code: push <ebp+offset> ; no such instruction exists |
|||
26 Dec 2020, 10:38 |
|
mns 26 Dec 2020, 10:48
revolution, now I understand thank you very much.
|
|||
26 Dec 2020, 10:48 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.