flat assembler
Message board for the users of flat assembler.

flat assembler > Windows > Smallest fasm hello world

Author
Thread Post new topic Reply to topic
moveax41h



Joined: 18 Feb 2018
Posts: 47
Out of curiosity, I'd like to construct the smallest possible "hello world" program in fasm.

right now I've been using import msvcrt, printf, system (for pause>nul), and exit.

Is there a way to print to the console without having to import that library on a modern Windows system in user-mode?

What about in kernel-mode? I can use 8086emu to print using interrupts which is awesome and I can write a program that's only like 96 bytes in 16-bit mode. Is there anything like this on a modern Windows system or at least some way to slim down the footprint? Thanks.

_________________
-moveax41h
Post 07 Mar 2018, 09:03
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16128
Location: Hyperborea
moveax41h wrote:
Out of curiosity, I'd like to construct the smallest possible "hello world" program in fasm.
How are you measuring "small". By source size, or by binary size?
moveax41h wrote:
Is there a way to print to the console without having to import that library on a modern Windows system in user-mode?
You can use the Windows "int 0x28" directly. But it is not documented, it changes for each OS version, and depending upon the OS version you will still be forced to link to at least one DLL or the loader will error out. Anyhow, this is not really recommended, it has too many issues IMO.
Post 07 Mar 2018, 09:18
View user's profile Send private message Visit poster's website Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 451
Location: Belarus
moveax41h wrote:
I can write a program that's only like 96 bytes in 16-bit mode.

Why so large? A typical MS-DOS “Hello, world” program is around 30 bytes.

As for your question, what is your purpose? Just making the tiniest possible “Hello, world” has already been done. But it is of little to no use when it comes to extending it to something more useful.
Post 07 Mar 2018, 10:53
View user's profile Send private message Visit poster's website Reply with quote
alexfru



Joined: 23 Mar 2014
Posts: 66
moveax41h wrote:
right now I've been using import msvcrt, printf, system (for pause>nul), and exit.

Is there a way to print to the console without having to import that library on a modern Windows system in user-mode?

You can import GetStdHandle, WriteFile, ExitProcess, etc from kernel32.dll instead and use those (that's what msvcrt.dll's routines end up doing). But it won't save size.

moveax41h wrote:
What about in kernel-mode?

Indeed, what about it? Please elaborate.
Post 07 Mar 2018, 16:34
View user's profile Send private message Reply with quote
moveax41h



Joined: 18 Feb 2018
Posts: 47
This was more of a conceptual/education question than a need for an immediate real-world application. It didn't "click" until recently that even in asm you needed to call APIs on Windows. Of course I knew this in C but I was under the impression before (prob from 16-bit) that you could do something different in asm like revolution said. Perhaps a direct syscall as well..
Post 08 Mar 2018, 04:27
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16128
Location: Hyperborea
"syscall" and "int 0x28" are the same thing in Windows, it's just a different way to access the same kernel functions. But as stated above, the values and functions are not documented so you would have to reverse engineer things to make it work. Not an impossible task, but also not very useful.
Post 08 Mar 2018, 04:48
View user's profile Send private message Visit poster's website Reply with quote
alexfru



Joined: 23 Mar 2014
Posts: 66
The Windows system call interface is undocumented and it changes from one version of Windows to another. Your best bet is importing from system DLLs, which are in many cases just thin wrappers around int/syscall/sysenter. You can hack around this, but your app won't be portable. And it may get additional downvotes from scareware, which modern antiviruses appear to be.
Post 08 Mar 2018, 07:03
View user's profile Send private message Reply with quote
moveax41h



Joined: 18 Feb 2018
Posts: 47
revolution wrote:
"syscall" and "int 0x28" are the same thing in Windows, it's just a different way to access the same kernel functions. But as stated above, the values and functions are not documented so you would have to reverse engineer things to make it work. Not an impossible task, but also not very useful.

That's fine, I do RE for a living. Actually, I am just beginning to do "forward" asm but for example, I've had to use WinDbg to RE the system service dispatch table before. I get what you're saying for practical, real-world applications that's a bad idea but I'm a weirdo like that. Very Happy

_________________
-moveax41h
Post 08 Mar 2018, 20:48
View user's profile Send private message Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1606
Location: Ukraine
Wink


Description:
Download
Filename: hello.asm
Filesize: 23 Bytes
Downloaded: 140 Time(s)


_________________
UNICODE forever!
Post 09 Mar 2018, 06:55
View user's profile Send private message Visit poster's website Reply with quote
Mikl___



Joined: 30 Dec 2014
Posts: 93
Post 10 Mar 2018, 00:26
View user's profile Send private message Visit poster's website 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-2018, Tomasz Grysztar.

Powered by rwasa.