flat assembler
Message board for the users of flat assembler.

Index > Windows > Alternative way (threads)

Author
Thread Post new topic Reply to topic
eskizo



Joined: 22 Nov 2005
Posts: 59
eskizo 20 Jun 2009, 16:38
Hi! I am new to assembly. I would like to view some alternative ways (optimized) to do the same as the following code:

Code:
format PE GUI 4.0
entry start

include '%fasminc%\win32a.inc'

section '.code' code readable executable

    title1 db 'Thread1', 0
    title2 db 'Thread2', 0
    caption db 'Hello world!', 0

th1:  push MB_OK
  push title1
 push caption
        push HWND_DESKTOP
   call [MessageBox]

       push 1000
   call [Sleep]

    jmp th1
     ret

th2:     push MB_OK
  push title2
 push caption
        push HWND_DESKTOP
   call [MessageBox]

       push 2000
   call [Sleep]

    jmp th2
     ret

start:   push 0 
     push 0 
     push 0 
     push th1
    push 0 
     push 0 
     call [CreateThread]

     push 0 
     push 0 
     push 0 
     push th2
    push 0 
     push 0 
     call [CreateThread]

     push -1
     call [Sleep]            ; 49,7 days!

    push 0
      call [ExitProcess]

section '.import' data import readable

      library kernel32, 'kernel32.dll', user32, 'user32.dll' 

     import kernel32, CreateThread, 'CreateThread', \
 Sleep, 'Sleep', ExitProcess, 'ExitProcess'
      import user32, MessageBox, 'MessageBoxA'
    
Post 20 Jun 2009, 16:38
View user's profile Send private message Reply with quote
asmcoder



Joined: 02 Jun 2008
Posts: 784
asmcoder 20 Jun 2009, 17:02
[content deleted]


Last edited by asmcoder on 14 Aug 2009, 14:50; edited 1 time in total
Post 20 Jun 2009, 17:02
View user's profile Send private message Reply with quote
eskizo



Joined: 22 Nov 2005
Posts: 59
eskizo 20 Jun 2009, 19:39
Quote:
return from thread by retn 4 (a var on stack), or by ExitThread.


I'm sorry. I am a very begginer asm coder, could you give me a more detailed explanation? (retn 4 ?). If I use ExitThread to terminate it, do I need to put ret at the end?

Quote:
dont write code/data because they mean noting.


section '.code' code readable executable
section '.code' readable executable

You mean these are equals sections declarations?
Post 20 Jun 2009, 19:39
View user's profile Send private message Reply with quote
asmcoder



Joined: 02 Jun 2008
Posts: 784
asmcoder 20 Jun 2009, 20:07
[content deleted]


Last edited by asmcoder on 14 Aug 2009, 14:50; edited 1 time in total
Post 20 Jun 2009, 20:07
View user's profile Send private message Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2465
Location: Bucharest, Romania
Borsuc 21 Jun 2009, 00:19
FYI, the section name is constant 8 bytes, so making it null won't make it smaller, it will just pad it with 0s. For compatibility you should name it with a dot and then ANSI characters (maximum 7, because the dot takes one).
Post 21 Jun 2009, 00:19
View user's profile Send private message Reply with quote
eskizo



Joined: 22 Nov 2005
Posts: 59
eskizo 22 Jun 2009, 13:06
Thankyou all.
Post 22 Jun 2009, 13:06
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.