Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2024-01

What's in Hello World

30 messages · 17 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Matthew Phillips

I compiled the Hello World program from the docs and noticed that it's 435k. Compared to a lot of newer languages, like Golang, that's not bad at all.

I then compiled the equivalent C program with gcc which came out at 33k. So I'm just curious, where does the difference comes from? Could it be that fpc is including some parts that are not being used in this simple of a program or is more going on?

Like I said, purely a curiosity, not intended as a criticism. Cheers.

Reply by email

Florian Klämpfl
to Matthew Phillips
Show quoted text 10 lines
Am 06.01.2024 um 20:05 schrieb Matthew Phillips via fpc-pascal : I compiled the Hello World program from the docs and noticed that it's 435k. Compared to a lot of newer languages, like Golang, that's not bad at all. I then compiled the equivalent C program with gcc which came out at 33k. So I'm just curious, where does the difference comes from? Could it be that fpc is including some parts that are not being used in this simple of a program or is more going on?

https://wiki.freepascal.org/Size_Matters

Show quoted text 6 lines
Like I said, purely a curiosity, not intended as a criticism. Cheers. _______________________________________________ fpc-pascal maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply by email

Peter B
to Matthew Phillips: I compiled the Hello World program from the docs and noticed that it's 435k. Compared to…
Matthew Phillips wrote 13 lines
I compiled the Hello World program from the docs and noticed that it's 435k. Compared to a lot of newer languages, like Golang, that's not bad at all. I then compiled the equivalent C program with gcc which came out at 33k. So I'm just curious, where does the difference comes from? Could it be that fpc is including some parts that are not being used in this simple of a program or is more going on? Like I said, purely a curiosity, not intended as a criticism. Cheers. _______________________________________________ fpc-pascal maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Try building with smartlinking, -XX
I get 35k

Reply by email

Sven Barth
to Florian Klämpfl: https://wiki.freepascal.org/Size_Matters
Florian Klämpfl wrote 16 lines
> Am 06.01.2024 um 20:05 schrieb Matthew Phillips via fpc-pascal > : > > I compiled the Hello World program from the docs and noticed that it's > 435k. Compared to a lot of newer languages, like Golang, that's not bad > at all. > > I then compiled the equivalent C program with gcc which came out at > 33k. So I'm just curious, where does the difference comes from? > Could it be that fpc is including some parts that are not being used in > this simple of a program or is more going on? https://wiki.freepascal.org/Size_Matters

To underline this with some numbers (I assume you mean the demo/text/hello.pp which only contains a mere "Writeln('Hello World')" and no additional units; all tests on x86_64-linux with 3.3.1):

- FPC compiled as is: 388976 B
- FPC compiled with full smartlinking: 55920 B
- FPC compiled with C linkage: 388760 B
- FPC compiled with full smartlinking and C linkage: 56792 B

(gotta admit, the last one surprised me though ^^')

Regards,
Sven

Reply by email

Michael Van Canneyt
to Sven Barth
Sven Barth wrote 25 lines
Am 07.01.2024 um 10:01 schrieb Florian Klämpfl via fpc-pascal: > > >> Am 06.01.2024 um 20:05 schrieb Matthew Phillips via fpc-pascal >> : >> >> I compiled the Hello World program from the docs and noticed that it's >> 435k. Compared to a lot of newer languages, like Golang, that's not bad >> at all. >> >> I then compiled the equivalent C program with gcc which came out at >> 33k. So I'm just curious, where does the difference comes from? >> Could it be that fpc is including some parts that are not being used in >> this simple of a program or is more going on? > > https://wiki.freepascal.org/Size_Matters > To underline this with some numbers (I assume you mean the demo/text/hello.pp which only contains a mere "Writeln('Hello World')" and no additional units; all tests on x86_64-linux with 3.3.1): - FPC compiled as is: 388976 B - FPC compiled with full smartlinking: 55920 B - FPC compiled with C linkage: 388760 B - FPC compiled with full smartlinking and C linkage: 56792 B

Maybe it is a good idea to add these numbers to the above WIKI page, to quantify the discussion and to illustrate what the effect is of various options.

I think we should also explain why linking to C has almost no effect on actual binary size.

Michael.

Reply by email

Ingemar Ragnemalm

Just for comparison, I fired up Think Pascal and made Hello world!

Plain Hello world, closes so quickly that you don't have time to see it: 4625 bytes.

Including ShowText and while not Button do; 4639 bytes.

Yes, less than 5k! Progress?

/Ingemar

Reply by email

Jonas Maebe
to Ingemar Ragnemalm
Ingemar Ragnemalm wrote 8 lines
Just for comparison, I fired up Think Pascal and made Hello world! Plain Hello world, closes so quickly that you don't have time to see it: 4625 bytes. Including ShowText and while not Button do; 4639 bytes. Yes, less than 5k! Progress?

You forgot the 1MB Mac ROM :)

That's also the main difference between C and FPC: C programs by default are dynamically linked, so all of the standard RTL functionality that gets linked into an FPC program is not there in a C program most of the time.

It's also why golang programs are larger: those are statically linked as well.

Jonas

Reply by email

Sven Barth
to Michael Van Canneyt: Maybe it is a good idea to add these numbers to the above WIKI page, to quantify the…
Michael Van Canneyt wrote 35 lines
On Sun, 7 Jan 2024, Sven Barth via fpc-pascal wrote: > Am 07.01.2024 um 10:01 schrieb Florian Klämpfl via fpc-pascal: >> >> >>> Am 06.01.2024 um 20:05 schrieb Matthew Phillips via fpc-pascal >>> : >>> >>> I compiled the Hello World program from the docs and noticed that it's >>> 435k. Compared to a lot of newer languages, like Golang, that's not >>> bad >>> at all. >>> >>> I then compiled the equivalent C program with gcc which came out at >>> 33k. So I'm just curious, where does the difference comes from? >>> Could it be that fpc is including some parts that are not being >>> used in >>> this simple of a program or is more going on? >> >> https://wiki.freepascal.org/Size_Matters >> > To underline this with some numbers (I assume you mean the > demo/text/hello.pp which only contains a mere "Writeln('Hello > World')" and no additional units; all tests on x86_64-linux with 3.3.1): > > - FPC compiled as is: 388976 B > - FPC compiled with full smartlinking: 55920 B > - FPC compiled with C linkage: 388760 B > - FPC compiled with full smartlinking and C linkage: 56792 B Maybe it is a good idea to add these numbers to the above WIKI page, to quantify the discussion and to illustrate what the effect is of various options.

Probably... 🤷‍♀️

And just for the fun of it, the size if the RTL is compiled into a dynamic package and that is used:

- no smartlinking: 15784 B
- with smartlinking: 15608 B

With the librtl.so having a size of 649912 B which will ammortize itself if multiple applications use dynamic packages.

I think we should also explain why linking to C has almost no effect on actual binary size.

That's mainly because the functions that differ between FPC_USE_LIBC and not are rather slim syscalls anyway, so the main bunch of Pascal code is still the same in both cases.

Regards,
Sven

Reply by email

Florian Klämpfl
to Ingemar Ragnemalm: Just for comparison, I fired up Think Pascal and made Hello world! Plain Hello world,…
Show quoted text 10 lines
Am 07.01.2024 um 13:21 schrieb Ingemar Ragnemalm via fpc-pascal : Just for comparison, I fired up Think Pascal and made Hello world! Plain Hello world, closes so quickly that you don't have time to see it: 4625 bytes. Including ShowText and while not Button do; 4639 bytes. Yes, less than 5k! Progress?

https://github.com/chainq/amiga-tiny-hello-p

244 bytes with FPC.

Reply by email

Unknown author
to Florian Klämpfl
Florian Klämpfl wrote 23 lines
> Am 07.01.2024 um 13:21 schrieb Ingemar Ragnemalm via fpc-pascal > : > > Just for comparison, I fired up Think Pascal and made Hello world! > > Plain Hello world, closes so quickly that you don't have time to see > it: 4625 bytes. > > Including ShowText and while not Button do; 4639 bytes. > > Yes, less than 5k! Progress? > https://github.com/chainq/amiga-tiny-hello-p 244 bytes with FPC. Not that it's 100 percent relevant, but I always use powerbasic (https://www.powerbasic.com) when it's a matter of size, since powerbasic and it's console compiler produces a hello world program of just 7,168 bytes which is still a windows executable, and works on just about any version of windows.

I've never found any windows compiler that produces smaller executables by default.

Even their powerbasic windows compilers do an admirable job of keeping the executable sizes down to amazing numbers.

I have an epub reader I've been working off and on for the last couple years, and even with a complete gui and significant functionality, my epub reader clocks in at a whooping 75,776 bytes.

I've never gotten such results from any other windows compiler, and indeed, a great deal of linux compilers can't match that.

Of course, I *always* use FPC when a I need the program on multiple platforms, though I do tend to use java when I need a gui on multiple platforms, as I can just throw up the grid format, then not have to worry about how the gui looks, which is great for me, because it's either that, or have a sighted individual pour over the gui with me until I get it right.  It's just easier to use grid mode on java. :)

For what it's worth though, generally, I find FPC to be considerably better than anything cross platform except of course for GCC.

Reply by email

James Richters
to Peter B: Try building with smartlinking, -XX I get 35k
Try building with smartlinking, -XX

I never knew there was an option for smartlinking. I'm using the FPC text IDE, I see various options like
Generate Smaller Code, and level 1, 2, and 3 optimizations, but I don't see anything specifically called smartlinking.
Is it the same as Generate Smaller Code? or if not, is there another way to turn it on in the textmode IDE?

James

Reply by email

Michael Van Canneyt
to Sven Barth: Probably... 🤷‍♀️ And just for the fun of it, the size if the RTL is compiled…
Sven Barth wrote 20 lines
>> >> - FPC compiled as is: 388976 B >> - FPC compiled with full smartlinking: 55920 B >> - FPC compiled with C linkage: 388760 B >> - FPC compiled with full smartlinking and C linkage: 56792 B > > Maybe it is a good idea to add these numbers to the above WIKI page, > to quantify > the discussion and to illustrate what the effect is of various options. Probably... 🤷‍♀️ And just for the fun of it, the size if the RTL is compiled into a dynamic package and that is used: - no smartlinking: 15784 B - with smartlinking: 15608 B With the librtl.so having a size of 649912 B which will ammortize itself if multiple applications use dynamic packages.

Nice result. Smaller than a C program :-)

Show quoted text 7 lines
> I think we should also explain why linking to C has almost no effect > on actual binary size. That's mainly because the functions that differ between FPC_USE_LIBC and not are rather slim syscalls anyway, so the main bunch of Pascal code is still the same in both cases.

I know this, but most likely users will not realize this... :-)

Michael.

Reply by email

Unknown author
to Michael Van Canneyt

For what it's worth, the hello world program in powerbasic (https://www.powerbasic.com) comes to a whooping 7,168 bytes. That's the console version, not the gui version, that's a bit bigger, but by not much more.  I have an epub reader I've been working on for a few years, on and off, and that program which has a complete gui, web browser calls, and the like, weighs in at just over 75K.  I always use powerbasic if I'm writing a windows only program, since it's ability to produce such small executables is well known.  Heck, it even has a #bloat command in the compiler to artificially inflate the size of the exe files it builds, because so many didn't believe that it was producing an actual windows binary.

I use FPC when working on cross platform programs, since it can compile for many platforms, unless I need a gui.  In that case, I use java, since I can put it in grid mode, and then I don't have to worry about how the gui is laid out.  Something that typically takes sighted assistance, and a great deal of time otherwise.

Of course, GCC produces small binaries too, and I'll use that too when the need arrises.

It all depends on what I am working on, and where it is going to run.

Michael Van Canneyt wrote 42 lines
On Sun, 7 Jan 2024, Sven Barth via fpc-pascal wrote: >>> >>> - FPC compiled as is: 388976 B >>> - FPC compiled with full smartlinking: 55920 B >>> - FPC compiled with C linkage: 388760 B >>> - FPC compiled with full smartlinking and C linkage: 56792 B >> >> Maybe it is a good idea to add these numbers to the above WIKI page, >> to quantify >> the discussion and to illustrate what the effect is of various options. > > Probably... 🤷‍♀️ > > And just for the fun of it, the size if the RTL is compiled into a > dynamic package and that is used: > > - no smartlinking: 15784 B > - with smartlinking: 15608 B > > With the librtl.so having a size of 649912 B which will ammortize > itself if multiple applications use dynamic packages. Nice result. Smaller than a C program :-) > >> I think we should also explain why linking to C has almost no effect >> on actual binary size. > > That's mainly because the functions that differ between FPC_USE_LIBC > and not are rather slim syscalls anyway, so the main bunch of Pascal > code is still the same in both cases. I know this, but most likely users will not realize this... :-) Michael. _______________________________________________ fpc-pascal maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply by email

Marco van de Voort
to Sven Barth: To underline this with some numbers (I assume you mean the demo/text/hello.pp which only…

Op 7-1-2024 om 11:23 schreef Sven Barth via fpc-pascal:

Show quoted text 11 lines
To underline this with some numbers (I assume you mean the demo/text/hello.pp which only contains a mere "Writeln('Hello World')" and no additional units; all tests on x86_64-linux with 3.3.1): - FPC compiled as is: 388976 B - FPC compiled with full smartlinking: 55920 B - FPC compiled with C linkage: 388760 B - FPC compiled with full smartlinking and C linkage: 56792 B (gotta admit, the last one surprised me though ^^')

I noticed that when I implemented -dFPC_USE_LIBC. The dynamic library overhead is bigger than the 15-20kb worth of routines saved in fairly simple programs. In the past is was even more pronounced because readdir was kernel.

Reply by email

Rainer Stratmann
to Florian Klämpfl: https://github.com/chainq/amiga-tiny-hello-p 244 bytes with FPC.

Am Sonntag, 7. Januar 2024, 14:09:24 CET schrieb Florian Klämpfl via fpc- pascal:

Show quoted text 15 lines
> Am 07.01.2024 um 13:21 schrieb Ingemar Ragnemalm via fpc-pascal > : > > Just for comparison, I fired up Think Pascal and made Hello world! > > Plain Hello world, closes so quickly that you don't have time to see it: > 4625 bytes. > > Including ShowText and while not Button do; 4639 bytes. > > Yes, less than 5k! Progress? https://github.com/chainq/amiga-tiny-hello-p 244 bytes with FPC.

Is the size of AVR programs reasonable small?
Is the AVR code stable?
I would like to switch to freepascal.

Reply by email

Karoly Balogh
to Ingemar Ragnemalm: Just for comparison, I fired up Think Pascal and made Hello world! Plain Hello world,…

Hi,

Ingemar Ragnemalm wrote 7 lines
Just for comparison, I fired up Think Pascal and made Hello world! Plain Hello world, closes so quickly that you don't have time to see it: 4625 bytes. Including ShowText and while not Button do; 4639 bytes. Yes, less than 5k! Progress?

This isn't a fair comparison. Think Pascal is a single platform compiler, which means it can avoid a bunch of abstraction layers, and also it doesn't support many advanced modern Pascal constructs. Main examples are AnsiStrings, and exception handling, but also the memory allocator is more advanced, and thus bigger than the early Pascal compilers. Everything has a trade off.

Also while this means the initial "bloat" is bigger, there's a lot less added, as one progresses. I have a fully localized, multithreaded GUI Amiga application written in Free Pascal, that is around 64KiB. I'm sure it could be a lot smaller too, but it isn't unreasonable. (Here: http://viaduct.amigaspirit.hu )

If anyone is curious what gets into a "Hello, World!" binary, feel free to look into a linker map, by using command line argument -Xm. (Note on Linux & systems using GNU LD, the linker map file starts with the _discarded_ sections, the ones which did not get into the binary, so look at the bottom of the file.)

Charlie

Reply by email

Karoly Balogh
to Michael Van Canneyt: Maybe it is a good idea to add these numbers to the above WIKI page, to quantify the…

Hi,

Michael Van Canneyt wrote 15 lines
> To underline this with some numbers (I assume you mean the > demo/text/hello.pp which only contains a mere "Writeln('Hello World')" > and no additional units; all tests on x86_64-linux with 3.3.1): > > - FPC compiled as is: 388976 B > - FPC compiled with full smartlinking: 55920 B > - FPC compiled with C linkage: 388760 B > - FPC compiled with full smartlinking and C linkage: 56792 B Maybe it is a good idea to add these numbers to the above WIKI page, to quantify the discussion and to illustrate what the effect is of various options. I think we should also explain why linking to C has almost no effect on actual binary size.

Note that the numbers above don't include stripping, so it's full with symbols. I get the same numbers with unstriped binares. If I add striping (-Xs), the Hello, World! FPC with smartlinking binary is 35056 bytes. (Current FPC Git main, on Debian 12, x86_64) Other binary sizes change by roughly the same percentage.

Also note that on most platforms, smartlinking is a lot faster and less invasive than it used to be, and it doesn't need additional .a files, thanks to section smartlinking and the section garbage collection feature of modern linkers. Not sure if some documentation needs to be updated for that, but while we're at it... :)

Charlie

Reply by email

Karoly Balogh
to Florian Klämpfl: https://github.com/chainq/amiga-tiny-hello-p 244 bytes with FPC.

Hi,

Florian Klämpfl wrote 14 lines
> Am 07.01.2024 um 13:21 schrieb Ingemar Ragnemalm via fpc-pascal : > > Just for comparison, I fired up Think Pascal and made Hello world! > > Plain Hello world, closes so quickly that you don't have time to see > it: 4625 bytes. > > Including ShowText and while not Button do; 4639 bytes. > > Yes, less than 5k! Progress? https://github.com/chainq/amiga-tiny-hello-p 244 bytes with FPC.

BTW, and while I still stand by the Disclaimer I wrote at the bottom of that page, this kind of technique can have a real world impact and use. For example, we made a couple of Windows 4k intros (real time animations with graphics and music, in less than 4096 bytes!) with Free Pascal using the same kind of startup-bypass technque - and admittedly, a compressing linker, called Crinkler. :)

Ampelwürfel:
https://www.pouet.net/prod.php?which=90091
... additional backstory/tech explanation:
- https://www.pouet.net/prod.php?which=90091#c932283 Binary download:
- https://files.scene.org/view/parties/2021/deadline21/pc_intro/rbs-aw.zip Direct YouTube link:
- https://youtu.be/Tz_dpKQrQE0

Icecold:
https://www.pouet.net/prod.php?which=94741
Binary download:
- https://files.scene.org/view/parties/2023/evoke23/in4k/rbs-icecold.zip Direct YouTube link:
- https://youtu.be/z5aR2EfqRgI

Sadly the source for these is not available, AFAIR, but it's basically the same approach as the Amiga Tiny Hello world.

Crinkler, the compressing linker we used:
https://github.com/runestubbe/Crinkler

Charlie

Reply by email

Peter B
to James Richters: I never knew there was an option for smartlinking. I'm using the FPC text IDE, I see…
James Richters wrote 5 lines
> Try building with smartlinking, -XX I never knew there was an option for smartlinking. I'm using the FPC text IDE, I see various options like Generate Smaller Code, and level 1, 2, and 3 optimizations, but I don't see anything specifically called smartlinking.

If you run fpc from the console, with no parameters or options, you should see a
full set of options listed.

Is it the same as Generate Smaller Code?

No. That is a compile option -Os
-XX is a link time option.

or if not, is there another way to turn it on in the textmode IDE?

No idea. Its easy enough if you compile from the command line. fpc -Os -XX hello.pas

If stripping is not on by default, also use -Xs

Reply by email

Karoly Balogh
to James Richters: I never knew there was an option for smartlinking. I'm using the FPC text IDE, I see…

Hi,

James Richters wrote 7 lines
>Try building with smartlinking, -XX I never knew there was an option for smartlinking. I'm using the FPC text IDE, I see various options like Generate Smaller Code, and level 1, 2, and 3 optimizations, but I don't see anything specifically called smartlinking. Is it the same as Generate Smaller Code?

No, it's not. But the Linker specific options are under Options -> Linker... There's a smartlinking related option there, but I'm not sure if it is what you need. :)

or if not, is there another way to turn it on in the textmode IDE?

There's a field called "Additional Compiler Args" in the Compiler Switches window, in the Options -> Compiler... menu. You can add arguments there like you'd invoke the regular command line compiler.

Charlie

Reply by email

Marco van de Voort
to Karoly Balogh

Op 8-1-2024 om 14:03 schreef Karoly Balogh via fpc-pascal:

No, it's not. But the Linker specific options are under Options -> Linker... There's a smartlinking related option there, but I'm not sure if it is what you need. :)

That one is -XX, and the "create smartlinkable units" in the tab before is -CX (generate smartlinkable units or something similar) .

If you change these, force a build afterwards.

Reply by email

code dz
to Michael Van Canneyt: Nice result. Smaller than a C program :-) I know this, but most likely users will not…

I remember i made a simple win32 window app with custom tiny RTL , and final exe size was 4.5kb .

On Sun, Jan 7, 2024, 20:33 Michael Van Canneyt via fpc-pascal <

Show quoted text 43 lines
wrote: On Sun, 7 Jan 2024, Sven Barth via fpc-pascal wrote: >>> >>> - FPC compiled as is: 388976 B >>> - FPC compiled with full smartlinking: 55920 B >>> - FPC compiled with C linkage: 388760 B >>> - FPC compiled with full smartlinking and C linkage: 56792 B >> >> Maybe it is a good idea to add these numbers to the above WIKI page, >> to quantify >> the discussion and to illustrate what the effect is of various options. > > Probably... 🤷‍♀️ > > And just for the fun of it, the size if the RTL is compiled into a > dynamic package and that is used: > > - no smartlinking: 15784 B > - with smartlinking: 15608 B > > With the librtl.so having a size of 649912 B which will ammortize itself > if multiple applications use dynamic packages. Nice result. Smaller than a C program :-) > >> I think we should also explain why linking to C has almost no effect >> on actual binary size. > > That's mainly because the functions that differ between FPC_USE_LIBC and > not are rather slim syscalls anyway, so the main bunch of Pascal code is > still the same in both cases. I know this, but most likely users will not realize this... :-) Michael._______________________________________________ fpc-pascal maillist - https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply by email

Karoly Balogh
to Marco van de Voort: Op 8-1-2024 om 14:03 schreef Karoly Balogh via fpc-pascal: That one is -XX, and the…

Hi,

Marco van de Voort wrote 10 lines
Op 8-1-2024 om 14:03 schreef Karoly Balogh via fpc-pascal: > No, it's not. But the Linker specific options are under Options -> > Linker... There's a smartlinking related option there, but I'm not sure if > it is what you need. :) That one is -XX, and the "create smartlinkable units" in the tab before is -CX (generate smartlinkable units or something similar) . If you change these, force a build afterwards.

You do not need this, if you use a platform that supports section smartlinking. Then smartlinking "just works" from the regular objects and libraries.

But yeah, this depends on the target platform. You do not need this on Linux, which where this discussion started. I'm sure you also do not need this, if you use the internal linker on Windows either.

Charlie

Reply by email

Jean SUZINEAU
to Peter B: If you run fpc from the console, with no parameters or options, you should see a full set…

Le 08/01/2024 à 13:51, Peter B via fpc-pascal a écrit :

Show quoted text 6 lines
>    or if not, is there another way to > turn it on in the textmode IDE? No idea. Its easy enough if you compile from the command line. fpc -Os -XX hello.pas If stripping is not on by default, also use -Xs

I guess that in the textmode IDE you just have to go Options/Compiler and in the bottom in "Additional compiler args"
you just have to add -Os -XX - Xs

-Os :  Optimize for size rather than speed
-Xs  :  Strip all symbols from executable
-XX : Try to smartlink units             (defines FPC_LINK_SMART)

Reply by email

Nikolay Nikolov
to Ingemar Ragnemalm: Just for comparison, I fired up Think Pascal and made Hello world! Plain Hello world,…
Ingemar Ragnemalm wrote 10 lines
Just for comparison, I fired up Think Pascal and made Hello world! Plain Hello world, closes so quickly that you don't have time to see it: 4625 bytes. Including ShowText and while not Button do; 4639 bytes. Yes, less than 5k! Progress?

Nah! It's bloat, bloat, bloat, horrible bloat!!! I'm not impressed. :)

Nothing beats assembler for DOS:

; nasm asmhello.asm -o asmhello.com
        bits 16
        cpu 8086
        org 100h
        mov dx, msg
        mov ah, 9
        int 21h
        ret
msg:    db 'Hello, world!', 13, 10, '$'

The produced executable is only 24 bytes (8 bytes of code and 16 bytes of data):

BA 08 01 B4 09 CD 21 C3 48 65 6C 6C 6F 2C 20 77 6F 72 6C 64 21 0D 0A 24

You can write this down on a sheet of paper, or memorize it and recite it from memory. Try doing that with 4639 bytes :)

Note that noobs will use the following way to terminate the program:

mov ax, 4c00h

int 21h

But that increases the binary size to 28 bytes. We can put a 'ret' instruction instead, and that works, because DOS puts a 0000h word on top of the stack, and that points to CS:0000h, which is the beginning of the PSP. And that starts with an int 20h, which is the oldschool (MS-DOS version 1) way of terminating a process, which requires CS to point to the PSP, which it does, because we're a .com file.

Nikolay

Reply by email

Adriaan van Os
to Nikolay Nikolov
Nikolay Nikolov wrote
But that increases the binary size to 28 bytes. We can put a 'ret'

That's still 27 bytes too much. Let's design a CPU that has "Hello World" as a one-byte instruction, implement that CPU in a Field-programmable gate array, write an OS for it and let it say hello. That's HelloWorld ad absurdum.

Or just send some smoke signals
<https://www.interestingfacts.org.uk/wp-content/uploads/2013/06/Smoke-Signals-300x275.jpg>

Regards,

Adriaan van Os

Reply by email

DougC
to Adriaan van Os

Ah, yes! The Hello World Machine.

Doug C.

---- On Thu, 11 Jan 2024 14:34:29 -0500 Adriaan van Os via fpc-pascal wrote ---

Nikolay Nikolov wrote
But that increases the binary size to 28 bytes. We can put a 'ret'

That's still 27 bytes too much. Let's design a CPU that has "Hello World" as a one-byte instruction, implement that CPU in a Field-programmable gate array, write an OS for it and let it say hello. That's HelloWorld ad absurdum.
 

Reply by email