while a forumreader post "some hello world" coding languages and forget the ASM language, so i add this tasm version :

>.model flat,stdcall
>option casemap:none
>msg db "hello world !",0
>call Messagebox,offset msg,offset msg,0
>call ExitProcess,0
>end start

and he answer with this sample and told me to use this if i want to code real in asm:

void main()
printf("Hello, World!\n;
return 0;

than doing:
section .data
msg dw "Hello, World!",10,13,0
section .text
global _start ; same as main

mov eax,4 ; sys_write call
mov ebx,1 ; stdout
mov ecx,msg ; address of message
mov edx,15 ; msg len

int 0x80 ;kernel-mode jump

mov eax,1 ; sys_exit
mov ebx,0
int 0x80

the sample looks for me like .com and not exe code.
me is not familiar with this coding form.

why is the second form the "real" way to code in asm ?

what do you say, any other way to get it smaller?

thanks :-)

Posted on 2005-06-28 02:40:41 by xanthos
the example he gave looks like the first part is c, and the 2nd part is for *nix in assembly, your version works, so stick with it i'd say
Posted on 2005-06-28 03:34:21 by evlncrn8
Second example is an asm example of helloword for linux using only syscalls.

what do you say, any other way to get it smaller?

If you are referring to the second example. Then it's possible to create a much smaller executable by creating custom ELF header and assembling the code to flat binary.
Posted on 2005-06-28 11:57:02 by arafel
By the way, in win, you can delete the call to ExitProcess and only put a ret. If Im not wrong, that will also work for the *nix enviroment, instead of make a syscall or a api call.

By the way, that typo, about #include (nothing here) is from you?? or from the guy?.. also you can not depend on the sections...

.model flat,stdcall
option casemap:none ;perhaps in this case dosent matter if you put this or not...

; msg db "hello world !",0 ;here the data, the point is be outside of the execution line...
call Messagebox,offset msg,offset msg,0
msg db "hello world !",0
end start

Near to equal to the other sample...
Posted on 2005-06-28 12:33:48 by rea
Thanks a lot for the help !

By the way, that typo, about #include (nothing here) is from you?? or from the guy?.

its from the other guy.

when i read "void" i remeber the word to see in a C source, but i use only asm.
looks for me like a macro.

btw. why remove .data and write at end ?
what means "outside of the execution line" ?

sorry english is not my homepanguage :)

Posted on 2005-06-28 14:15:43 by xanthos
Terminating only with ret instruction will cause resource leakage. Hence sys_exit syscall`s main purpose is to free allocated resources before terminating the process.
Posted on 2005-06-28 15:19:47 by arafel
What type of resource leakage?, you mean the thing about resources to load??? or you mean resources like memory assigned to the exe????.. and you are talking only about *nix??? or is applicable to Win32 too?

Also I not see direct allocation of memory in this short example... but that is a thing more related to the design of the OS... than to us.

.... hehe

By th way, reading again the source provided... and the thing about void.. then is a return 0; interesting :P....
Posted on 2005-06-28 15:41:12 by rea
The thing about the shortest hello world, I think is in the way, the less lines posible to have an application that print hello world in the screen... (not refered the size of the application), but the size of the source. At less is like I view it.

Then for delete a extra line ".data" is posible to move the data inside the code segment in the mean time that you ensure that this data will not be executed(and writed if something about the protection of code segment)... that mean that it need be outside of any function because any function that have a entry point (or a start address) will be potentially executed by the CPU, taht is what I call a execution line, the path of execution followed by the CPU.

Also the source in C is a mess... any compiler will be unable to compile it... :), even the one taht I have in my brain that is not as strict as the imlemented in software, but can by interpretated ;) :roll:.
Posted on 2005-06-28 15:51:15 by rea

I was talking about Linux sys_exit. Dunno about windows ExitProcess (it probably does the same thing though) but sys_exit closes all the files and frees their handles, frees memory, sets correct state for current process, notifies any child processes about termination, etc. Basically does everything in order to successfully terminate a process.
Posted on 2005-06-28 16:14:22 by arafel
ExitProcess does the same (according to your post) and additionally it closes the attached DLLs. not calling it = resource leakage (mainly: memory, handles and a message pool ).
Posted on 2005-06-29 14:48:20 by ti_mo_n
Under win32, doing a "ret" will end up in terminating your main thread, and your program will exit cleanly and deallocate all resources... Might as well do an ExitProcess though, to be clean and Mr. Proper.
Posted on 2005-06-29 20:29:57 by f0dder
and your program will exit cleanly and deallocate all resources...(...)

From other threads too? :|
Posted on 2005-06-29 22:33:00 by ti_mo_n

From other threads too?

The main thread will be terminated... other threads will probably still be running (the 'ret' location is "push eax / call ExitThread" on my system, and probably on other windows versions as well).

I certainly wouldn't use the "ret" method of terminating an app for anything "real", simply because it's not documented that this will work... and multi-threading is another issue.
Posted on 2005-06-30 12:44:33 by f0dder
If I remember correctly, a ret terminate the current thread (and thing related to the thread... like mem.. handles???), but dont know how will be handled the other threads, they need to have been exited before.

But in this case of a "Hello World" there is no necesity because all the resources allocated to your application, are allocated directly by the OS, then I consider that is good programming if the app that allocate it, also delete it, then if the OS will not take care of delete what has been allocated (be the OS), you know... that will be a bad programming way... that is for what I say "Also I not see direct allocation of memory in this short example... but that is a thing more related to the design of the OS... than to us."

In the case that you start requesting resources, then it will be a must that you free them calling the proper functions, and if more you need to exit in x/any moment, without let exit others threads with is respective free of memory, handles, and the respecive ret, then ExitProcess should be used, for example the thing about more than one thread running... tought I guess a reread of thread/process in the Win reference will help a little in this case.

Also Im sure if you allocate extra resources (apart from the allocated by the OS) and you handle them well (without need to exit a priory), I guess that your application also can use ret (hope I make clear myself).

In resume, I will say that ExitProcess is a function used for exit a priory and clear uncleared extra things... there is no necesity for exit a priory or clear uncleared extra things if there is no error in the run line of the program and correct allocation, handling and deallocation of resources.
Then a single ret will work for the most comlex application if before this all the extra resources have beed deallocated. At less that is what I think/see.
Posted on 2005-06-30 14:18:23 by rea

Then a single ret will work for the most comlex application if before this all the extra resources have beed deallocated.

I haven't seen the "ret will terminate primary thread" documented anywhere officially, so you shouldn't depend on it.

Furthermore, consider that DLLs might create additional worker threads.
Posted on 2005-06-30 15:34:44 by f0dder
The last a good point (I guess).

For the other I where to the Reference that I have, tough don't know how old, is about 32-bit Windows.

Terminating a Thread
A thread executes until one of the following events occurs:

? The thread calls the ExitThread function.
? Any thread of the process calls the ExitProcess function.
? The thread function returns.
? Any thread calls the TerminateThread function with a handle to the thread.
? Any thread calls the TerminateProcess function with a handle to the process.

Terminating a Process

A process executes until one of the following events occurs:

? Any thread of the process calls the ExitProcess function. This terminates all threads of the process.
? The primary thread of the process returns. The primary thread can avoid terminating other threads by explicitly calling ExitThread before it returns. One of the remaining threads can still call ExitProcess to ensure that all threads are terminated.
? The last thread of the process terminates.
? Any thread calls the TerminateProcess function with a handle to the process. This terminates all threads of the process, without allowing them to clean up or save data.

? For console processes, the default handler function calls ExitProcess when the console receives a CTRL+C or CTRL+BREAK signal. All console processes attached to the console receive these signals. Detached processes and GUI processes are not affected by CTRL+C or CTRL+BREAK signals. For more information, see SetConsoleCtrlHandler.
? The user shuts down the system or logs off. Use the SetProcessShutdownParameters function to specify shutdown parameters, such as when a process should terminate relative to the other processes in the system. The GetProcessShutdownParameters function retrieves the current shutdown priority of the process and other shutdown flags.

Tough perhaps I need to make more clear for what I have writed that line about the single ret and that will work for the more complex app if all the resources are handle correctly and no errors occur (that need exit a priory).

But yes, note that not a ret in any place, but a ret from the main thread ;), that is why other thread can exit the main thread :) they are independent lines, but the main thread is the main thread...

By the way, nice thing the one about "spell check", that will help in some cases... tough writed?? is like is say write in past?.. and perhaps tought (like I write it normally) isnt tough or the direct translation is not what I mean.. :roll:.
Posted on 2005-06-30 16:25:18 by rea
There are probably so many people who just return from the main thread, that I doubt MS would change it.
Just don't forget that some libraries create their own threads on startup. WINMM.DLL does, and probably OLE32.DLL too. So if you use these, you have to end with ExitProcess. I tend to use it just in case...
Posted on 2005-07-02 04:19:25 by Sephiroth3

#include <iostream>
int main ()
cout << "Hello World";
return (0);
Posted on 2005-07-04 02:34:14 by resistance_is_futile
resitance, that "return" is not to the system, but to the libc runtimes, which end up doing ExitProcess()
Posted on 2005-07-04 12:09:33 by f0dder