flat assembler
Message board for the users of flat assembler.

Index > Windows > Problem in allocating values to the fields of a structure

Author
Thread Post new topic Reply to topic
mns



Joined: 20 Dec 2007
Posts: 141
Location: Piliyandala,Sri lanka
mns
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 Confused

(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)


Description:
Download
Filename: direct3d_4.zip
Filesize: 35.89 KB
Downloaded: 247 Time(s)

Post 24 Dec 2020, 16:56
View user's profile Send private message Send e-mail Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1088
Roman
Do this.
Code:
proc       RenderFrame

  push            ebx esi edi

   
   cominvk         devCntxt, ClearRenderTargetView,[BkBuffRndrTrgtVw],colorStrct2

   cominvk         swapchain,Present,0, 0

   pop     edi esi ebx
    ret
colorStrct2         D3DXCOLOR     1.0,0.3,0.2,0.8
 endp
    

Or this for one time to init somthing like texture or buffer:
Code:
proc       RenderFrame

  push            ebx esi edi

   jmp @f              ;this method not good for render or loops.
   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
    


When CPU in code step to colorStrct2, CPU flies away to the galaxies Smile
Post 24 Dec 2020, 17:46
View user's profile Send private message Reply with quote
mns



Joined: 20 Dec 2007
Posts: 141
Location: Piliyandala,Sri lanka
mns
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?
Post 24 Dec 2020, 18:40
View user's profile Send private message Send e-mail Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 786
Location: Massachusetts, USA
bitshifter
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.
Post 24 Dec 2020, 18:49
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1088
Roman
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)
    
Post 24 Dec 2020, 20:40
View user's profile Send private message Reply with quote
mns



Joined: 20 Dec 2007
Posts: 141
Location: Piliyandala,Sri lanka
mns
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. Sad


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. Confused
Post 25 Dec 2020, 03:22
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 18472
Location: In your JS exploiting you and your system
revolution
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.
Post 25 Dec 2020, 03:31
View user's profile Send private message Visit poster's website Reply with quote
mns



Joined: 20 Dec 2007
Posts: 141
Location: Piliyandala,Sri lanka
mns
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? Confused
Post 25 Dec 2020, 04:34
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 18472
Location: In your JS exploiting you and your system
revolution
locals/endl is a good place for the structure. It exists on the stack, not in the code stream.
Post 25 Dec 2020, 04:36
View user's profile Send private message Visit poster's website Reply with quote
mns



Joined: 20 Dec 2007
Posts: 141
Location: Piliyandala,Sri lanka
mns
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.
Post 25 Dec 2020, 04:46
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 18472
Location: In your JS exploiting you and your system
revolution
You need the address of the structure:
Code:
cominvk devCntxt, ClearRenderTargetView,[BkBuffRndrTrgtVw],addr colorStrct2    
Post 25 Dec 2020, 04:52
View user's profile Send private message Visit poster's website Reply with quote
mns



Joined: 20 Dec 2007
Posts: 141
Location: Piliyandala,Sri lanka
mns
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. Sad
Post 25 Dec 2020, 08:22
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 18472
Location: In your JS exploiting you and your system
revolution
I posted the syntax above. Use addr
Post 25 Dec 2020, 08:23
View user's profile Send private message Visit poster's website Reply with quote
mns



Joined: 20 Dec 2007
Posts: 141
Location: Piliyandala,Sri lanka
mns
(sorry to take long time to respond)
Thank you very much revolution, your solution worked. Very Happy
(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. Confused
anyway thanks again.
Post 26 Dec 2020, 10:31
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 18472
Location: In your JS exploiting you and your system
revolution
mns wrote:
I thought a variable without Square Brackets mean address of the variable in FASM. Confused
It does. But it is a fixed address.

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    
Compare to just a plain address:
Code:
push address    
That is why the plain address can't work with stack values, it tries to push a composite value:
Code:
push <ebp+offset> ; no such instruction exists    
Post 26 Dec 2020, 10:38
View user's profile Send private message Visit poster's website Reply with quote
mns



Joined: 20 Dec 2007
Posts: 141
Location: Piliyandala,Sri lanka
mns
revolution, now I understand thank you very much. Very Happy
Post 26 Dec 2020, 10:48
View user's profile Send private message Send e-mail 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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.