• Create Account

## Hello World in 28 bytes

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

18 replies to this topic

### #1Onemind  Members

265
Like
0Likes
Like

Posted 19 November 2004 - 08:26 AM

I'm taking an Assembly language (x86) class this semester, and the professor said he wrote a Hello World program in 28 bytes. I'm wondering exactly how he got the exe so small. My programs are never smaller than 5kb!

### #2mx  Members

122
Like
0Likes
Like

Posted 19 November 2004 - 08:29 AM

have you tried it writing in DOS assembler and as a .com ? this should do the trick... there are many tutorials on Hello World in 386 asm on the internet. try google.

regards,
m.

1656
Like
0Likes
Like

Posted 19 November 2004 - 08:29 AM

Keep in mind once you compile and link your asm's the program gets byte-padded so it's appropriate to the OS. When he said he did it in so few bytes, I'm willing to bet that he meant his source code was only that big. Remember, before the byte-padding comes, each instruction maps to a machine instruction.*

* - don't burn me about different instruction sets. =) I know that some RISC psuedo ops and CISC instructions span out to two or more instructions when they get translated.

### #4doynax  Members

850
Like
0Likes
Like

Posted 19 November 2004 - 08:53 AM

It's really not that hard. COM programs don't require any header or padding.
Here's my version (21 bytes). Just paste this into a DOS prompt.
debuga 100mov ah,09mov dx,109int 21hint 20hdb "Hello World$"rcx15n hello.comwq ### #5kSquared Members 1356 Like 0Likes Like Posted 19 November 2004 - 09:24 AM Depends on how we're defining a 'program'. And did your professor say the program was actually in assembler? For instance, this batch file is even shorter than the (correct) 21-byte program above: <<< @ECHO Hello, world! >>> The above is only 19 bytes. You can even tell your professor you've "optimized" his version. [grin] - k2 "Choose a job you love, and you'll never have to work a day in your life." — Confucius"Logic will get you from A to B. Imagination will get you everywhere." — Albert Einstein"Money is the most egalitarian force in society. It confers power on whoever holds it." — Roger Starr{General Programming Forum FAQ} | {Blog/Journal} | {e-mail me} | {excellent webhosting} ### #6Onemind Members 265 Like 0Likes Like Posted 24 November 2004 - 11:54 AM Thanks guys. ### #7Mayrel Members 348 Like 0Likes Like Posted 24 November 2004 - 12:04 PM In m4: Hello, world. Only 14 or 15 bytes (depending upon how long a line break is). ### #8Rhaal Members 754 Like 0Likes Like Posted 24 November 2004 - 12:52 PM Quote:  Original post by doynaxIt's really not that hard. COM programs don't require any header or padding.Here's my version (21 bytes). Just paste this into a DOS prompt.debuga 100mov ah,09mov dx,109int 21hint 20hdb "Hello World$"rcx15n hello.comwq

I don't know ASM, but that was FUN! I wasn't aware that you just type it into the prompt!

### #9Thrump  Members

169
Like
0Likes
Like

Posted 24 November 2004 - 01:01 PM

Would the instruction size of the computer make this easier? Ie, could you do it on an 8-bit machine?

edit: never mind, the example above does it in 21 bytes.

### #10MindWipe  Members

940
Like
0Likes
Like

Posted 24 November 2004 - 01:17 PM

Quote:
Original post by Rhaal
Quote:
 Original post by doynaxIt's really not that hard. COM programs don't require any header or padding.Here's my version (21 bytes). Just paste this into a DOS prompt.debuga 100mov ah,09mov dx,109int 21hint 20hdb "Hello World$"rcx15n hello.comwq I don't know ASM, but that was FUN! I wasn't aware that you just type it into the prompt! Agreed (Although I know asm a bit) that was new to me! Cool stuff!!! /MindWipe ### #11darookie Members 1441 Like 0Likes Like Posted 24 November 2004 - 01:57 PM Nice! I didn't now that 'int 20h' is sufficient to exit. My version would like like this: debuga 100mov ah, 09mov dx, 10bint 21hmov ah, 4cint 21hdb "Hello World!$"rcx18n hello.comwqhello.com

Resulting in 24 bytes. I don't get how the prof could get 28 bytes...

### #12xyuri  Members

166
Like
0Likes
Like

Posted 24 November 2004 - 02:09 PM

This is depressing ....

I used to think VB was a cool language ....
Then I though I should learn something C based, so I started C# ...
But the .NET framework was too slow, so now C++ .....
But now I have just found out how easy it is to code stuff like this right into the command prompt ! bah, it just keeps betting better :)

### #13izzo  Members

437
Like
0Likes
Like

Posted 24 November 2004 - 05:31 PM

20 bytes if you use ret instead of int 20h to exit ;-)

cheers
sam

### #14Zahlman  Members

1682
Like
0Likes
Like

Posted 24 November 2004 - 08:11 PM

### #15Red Falcon  Members

142
Like
0Likes
Like

Posted 24 November 2004 - 08:51 PM

Quote:
 Original post by xyuriBut now I have just found out how easy it is to code stuff like this right into the command prompt ! bah, it just keeps betting better :)

Note that Assembly sure isnt the fastest code in the world, and that some (or rather most) programmers litterally run if you ask them to code assembly. assembly is only good for routines that are called 100ths of time a second (not so much, but u get the point) you can make games with assembly however (Rollercoaster tycoon was writen in it) but i guess u rather learn C (or c++) to keep you from getting mad from assebly :)

### #16Red Falcon  Members

142
Like
0Likes
Like

Posted 24 November 2004 - 08:51 PM

Quote:
 Original post by xyuriBut now I have just found out how easy it is to code stuff like this right into the command prompt ! bah, it just keeps betting better :)

Note that Assembly sure isnt the fastest code in the world, and that some (or rather most) programmers litterally run if you ask them to code assembly. assembly is only good for routines that are called 100ths of time a second (not so much, but u get the point) you can make games with assembly however (Rollercoaster tycoon was writen in it) but i guess u rather learn C (or c++) to keep you from getting mad from assembly :)

also a prob: assembly is processor dependent... what u write fot a pentioum, isnt guaranteed to wotk on, lets say, athlon

### #17BdR  Members

177
Like
0Likes
Like

Posted 24 November 2004 - 09:21 PM

The ACM "Hello World" project, hello world in any programming language :D

### #18JTippetts  Moderators

12314
Like
0Likes
Like

Posted 25 November 2004 - 04:39 AM

Just for the record for budding asm programmers: the asm code snippets above aren't really being entered directly at the command prompt. If you'll notice, the first line given is 'debug', which fires up the debugger. Subsequent asm code and other instructions are then passed to debug, which has a small capability for editing and writing assembly language programs. In these examples, debug is writing the program to the file hello.com, which is then being executed after the 'q' command exits debug. It's not the best way for creating extensive assembly, but it is sufficient for testing out small things such as this. For large asm apps you'll want an actual assembler which takes text files as input much like any other kind of compiler or language translator. These more powerful asm tools (such as MASM) include more powerful macros and methods for structuring applications and dealing with data.

Assembly! Yays!! [smile]

### #19Rob Loach  Members

1504
Like
0Likes
Like

Posted 25 November 2004 - 06:20 AM

Quote:
 Original post by ZahlmanThe way you write a 'Hello World' program speaks volumes about your level of experience. [smile]
Brilliant!

Rob Loach [Website] [Projects] [Contact]

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.