flat assembler
Message board for the users of flat assembler.

Index > Main > Hello, I have a few questions...

Author
Thread Post new topic Reply to topic
Hobo



Joined: 05 Jul 2007
Posts: 11
Hobo 27 Jul 2007, 11:43
Hi, I've been using flat assembler for about a month now, seems great so far but a few things i cant figure out and would like answers to have come up Confused

First, i have tried quite alot, however cant seem to figure out how to use the 'Div' command to divide numbers... i usually end up with the "please report this error to Microsoft" thing popping up...

Second, i was looking through the FasmW source code and i noticed that the strings had things like %d in the middle which were replaced with values when run, how does this work?

And third i think might possibly be a glitch in the assembler, however im probably wrong Wink
I noticed that the following code (taken from the middle of a windows WindowProc) worked, while the code underneath it did not.
Code:
                  cmp [wMsg], WM_DESTROY
                      je .WM_DESTROY
                      
                    jmp _DefWindowProc
                  
                    .WM_DESTROY:
                            invoke PostQuitMessage, 0
                           
                            jmp _Handled
                
            _DefWindowProc:
                 invoke DefWindowProc, [hWnd], [wMsg], [wParam], [lParam]
                    jmp _Return    


Code:
                      cmp [wMsg], WM_DESTROY
                      je .WM_DESTROY
              
            _DefWindowProc:
                 invoke DefWindowProc, [hWnd], [wMsg], [wParam], [lParam]
                    jmp _Return
                 
                    .WM_DESTROY:
                            invoke PostQuitMessage, 0
                           
                            jmp _Handled    


The assembler did not recognize the label ".WM_DESTROY" in the second piece of code and i have no idea why...
BTW, the only difference between the two pieces of code is that in the second one, the label .WM_DESTROY is below the call to DefWindowProc...



Thanks in advance for any help Wink
Post 27 Jul 2007, 11:43
View user's profile Send private message Reply with quote
vador



Joined: 12 Nov 2006
Posts: 68
Location: Madagascar
vador 27 Jul 2007, 13:55
About div
Example: to divide a 64-bit number by a 32-bit number:
Code:
mov eax,65536    ; 65536 is the low-order dword of the dividend
mov edx,0           ; 0 is the high-order dword of the dividend
mov ecx,1024      ; 1024 is the divider
div ecx                ; divide what is in edx:eax with ecx
;and now you have the result in eax
    


Last edited by vador on 27 Jul 2007, 14:25; edited 1 time in total
Post 27 Jul 2007, 13:55
View user's profile Send private message Reply with quote
vador



Joined: 12 Nov 2006
Posts: 68
Location: Madagascar
vador 27 Jul 2007, 14:10
search MSDN for the function wsprintf
when you use this function, all %d's are replaced with dword's, and %s's are replaced with strings, and so on...
a little example:

in the data section:
Quote:

szControlString db "1+1=%d",0
szDestString rb 260
...


in the code section:
Quote:

mov eax,2
invoke wsprintf,szDestString,szControlString,eax
invoke MessageBox,0,szDestString,0,MB_OK
...


After that, szDestString will be: "1+1=2". As you see, the %d was replaced by the value of eax
Post 27 Jul 2007, 14:10
View user's profile Send private message Reply with quote
vador



Joined: 12 Nov 2006
Posts: 68
Location: Madagascar
vador 27 Jul 2007, 14:24
Labels starting with a dot (.) are called 'local labels'. They are associated with the previous non-local label.
So you can write:
Code:
label1:                        ;non-local label
   ;some code
   .local_label
   ;some code
   jmp .local_label
label2:
   ;some code
   .local_label
   ;some code
   jmp .local_label
label3:
    


but you cannot do:
Code:
label1:                        ;non-local label
   ;some code
   .local_label1
   ;some code
   jmp .local_label2       ;<=== this gives an error
label2:
   ;some code
   .local_label2
   ;some code
   jmp .local_label2
label3:
    

because .local_label2 is only accessible within the area between label2 and label3. To access .local_label2 from elsewere in the code, you must write:
Code:
label1:                        ;non-local label
   ;some code
   .local_label1
   ;some code
   jmp label2.local_label2       ;<=== this works!
label2:
   ;some code
   .local_label2
   ;some code
   jmp .local_label2
label3:
    
Post 27 Jul 2007, 14:24
View user's profile Send private message Reply with quote
Hobo



Joined: 05 Jul 2007
Posts: 11
Hobo 28 Jul 2007, 09:38
Hey, thanks for you're replies Vador, everything explained nicely and i understand it now Smile
Post 28 Jul 2007, 09:38
View user's profile Send private message Reply with quote
vador



Joined: 12 Nov 2006
Posts: 68
Location: Madagascar
vador 28 Jul 2007, 16:22
i didnt' know i could explain something nicely in english...
Post 28 Jul 2007, 16:22
View user's profile Send private message Reply with quote
Hobo



Joined: 05 Jul 2007
Posts: 11
Hobo 29 Jul 2007, 00:54
Haha lol well you managed Smile i couldn't even tell english wasn't your first language Razz

I have another question now lol (Should go in Windows section, but i figured i wouldn't make another topic just for something that im sure can be simply solved)

I've been trying to set cursor for a particular control within my main window, I'm pretty sure it can be done by subclassing the WM_SETCURSOR notification (http://msdn2.microsoft.com/en-us/library/ms648382.aspx) but i haven't been able to do it... If you run the code below, you'll be able to see more clearly what i want to be done... ( it shows a window which explains exactly what i want )

Code:
FORMAT PE GUI 4.0
Entry _Main

include '%fasminc%\Win32A.inc'

section '.data' data readable writeable

 _Window.Class db 'Pinecone', 0
    _Window.Text db 'Change cursor on the box', 0
     _LabelText db 'I want to change the cursor on the box to the left to IDC_CROSS...', 0
     
    _StaticClass db 'Static', 0
       
    _ErrorMessage db 'Startup Failed.', 0
     
    _FontName db 'Microsoft Sans Serif', 0
    
    WC WNDCLASS 0, WindowProc, 0, 0, NULL, NULL, NULL, COLOR_BTNFACE + 1, 0, _Window.Class
      
    Msg MSG
     
    _FontObject dd  ?
   
section '.code' code readable executable
      _Main:
          invoke GetModuleHandle, 0
           mov [WC.hInstance], eax
             
            invoke LoadIcon, IDI_APPLICATION
            mov [WC.hIcon], eax
         
            invoke LoadCursor, IDC_ARROW, 0
             mov [WC.hCursor], eax
               
            invoke RegisterClass, WC
            test eax, eax
               jz .Error
           
            invoke CreateWindowEx, NULL, _Window.Class, _Window.Text, WS_VISIBLE + WS_CAPTION + WS_SYSMENU,150, 150, 220, 120, HWND_DESKTOP, 0, [WC.hInstance], NULL
            test eax, eax
               jz .Error
           
            .MessageLoop:
                   invoke GetMessage, Msg, NULL, 0, 0
                  cmp eax, 1
                  jb .ExitProcess
                     jne .MessageLoop
                    invoke TranslateMessage, Msg
                        invoke DispatchMessage, Msg
         jmp .MessageLoop
            
    .ExitProcess:
           invoke ExitProcess, 0
       .Error:
         invoke MessageBox, HWND_DESKTOP, _ErrorMessage, NULL, MB_ICONERROR + MB_OK
          jmp .ExitProcess
            
    proc WindowProc hWnd, wMsg, wParam, lParam
          push ebx esi edi
            
            cmp [wMsg], WM_DESTROY
              je .WM_DESTROY
              
            cmp [wMsg], WM_CREATE
               je .WM_CREATE
               
            .DefWindowProc:
                 invoke DefWindowProc, [hWnd], [wMsg], [wParam], [lParam]
                    jmp .Return
                 
                    .WM_CREATE:
                             invoke CreateFont, 16, 0, 0, 0, 0, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_RASTER_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FIXED_PITCH + FF_DONTCARE, _FontName
                         mov [_FontObject], eax
                              
                            invoke CreateWindowEx, WS_EX_CLIENTEDGE, _StaticClass, NULL, WS_VISIBLE + WS_CHILD + SS_BLACKRECT, 10, 10, 80, 70, [hWnd], 0, [WC.hInstance], NULL
                                  
                            invoke CreateWindowEx, NULL, _StaticClass, _LabelText, WS_VISIBLE + WS_CHILD + SS_CENTER , 100, 10, 100, 70, [hWnd], 0, [WC.hInstance], NULL
                                        
                            invoke SendMessage, eax, WM_SETFONT, [_FontObject], FALSE
                           
                            jmp .Handled
                        
                    .WM_DESTROY:
                            invoke DeleteObject, _FontObject
                            invoke PostQuitMessage, 0
                   
            .Handled:
                       xor eax, eax
                .Return:    
                    pop edi esi ebx
                     ret
 endp
                
section '.idata' import data readable writeable

   library Kernel, 'Kernel32.dll',\
         User, 'User32.dll',\
             GDI, 'GDI32.dll'
                  
    import  Kernel,\
           GetModuleHandle, 'GetModuleHandleA',\
            ExitProcess, 'ExitProcess'
                        
    import  User,\
             CreateWindowEx, CreateWindowExA',\
                RegisterClass, RegisterClassA',\
          GetMessage, 'GetMessageA',\
              TranslateMessage, TranslateMessage',\
             DispatchMessage, 'DispatchMessageA',\
            DefWindowProc, 'DefWindowProcA',\
                PostQuitMessage, 'PostQuitMessage',\
             LoadIcon, 'LoadIconA',\
          LoadCursor, 'LoadCursorA',\
              MessageBox, 'MessageBoxA',\
              SendMessage, 'SendMessageA'
                       
    import  GDI,\
              CreateFont, 'CreateFontA',\
              DeleteObject, 'DeleteObject'

    


Thanks again for any help Smile
Post 29 Jul 2007, 00:54
View user's profile Send private message Reply with quote
Yardman



Joined: 12 Apr 2005
Posts: 244
Location: US
Yardman 29 Jul 2007, 08:16
[ Post removed by author. ]


Last edited by Yardman on 04 Apr 2012, 02:29; edited 1 time in total
Post 29 Jul 2007, 08:16
View user's profile Send private message Reply with quote
Hobo



Joined: 05 Jul 2007
Posts: 11
Hobo 29 Jul 2007, 08:46
Yes, thanks for that, it's exactly what i wanted. Very Happy
Post 29 Jul 2007, 08:46
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.