Jump to content

  • Log In with Google      Sign In   
  • 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.

  • You cannot reply to this topic
18 replies to this topic

#1 Onemind   Members   -  Reputation: 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!

Sponsor:

#2 mx   Members   -  Reputation: 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.

#3 thade   Members   -  Reputation: 1652

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.

#4 doynax   Members   -  Reputation: 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.

debug
a 100
mov ah,09
mov dx,109
int 21h
int 20h
db "Hello World$"

rcx
15
n hello.com
w
q



#5 kSquared   Members   -  Reputation: 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}

#6 Onemind   Members   -  Reputation: 265

Like
0Likes
Like

Posted 24 November 2004 - 11:54 AM

Thanks guys.

#7 Mayrel   Members   -  Reputation: 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).

#8 Rhaal   Members   -  Reputation: 754

Like
0Likes
Like

Posted 24 November 2004 - 12:52 PM

Quote:
Original post by doynax
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.

debug
a 100
mov ah,09
mov dx,109
int 21h
int 20h
db "Hello World$"

rcx
15
n hello.com
w
q



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

#9 Thrump   Members   -  Reputation: 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.

#10 MindWipe   Members   -  Reputation: 940

Like
0Likes
Like

Posted 24 November 2004 - 01:17 PM

Quote:
Original post by Rhaal
Quote:
Original post by doynax
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.

debug
a 100
mov ah,09
mov dx,109
int 21h
int 20h
db "Hello World$"

rcx
15
n hello.com
w
q



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

#11 darookie   Members   -  Reputation: 1437

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:

debug
a 100
mov ah, 09
mov dx, 10b
int 21h
mov ah, 4c
int 21h
db "Hello World!$"

rcx
18
n hello.com
w
q
hello.com

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



#12 xyuri   Members   -  Reputation: 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 :)

#13 izzo   Members   -  Reputation: 347

Like
0Likes
Like

Posted 24 November 2004 - 05:31 PM

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

cheers
sam


#14 Zahlman   Moderators   -  Reputation: 1682

Like
0Likes
Like

Posted 24 November 2004 - 08:11 PM

The way you write a 'Hello World' program speaks volumes about your level of experience. [smile]

#15 Red Falcon   Members   -  Reputation: 142

Like
0Likes
Like

Posted 24 November 2004 - 08:51 PM

Quote:
Original post by xyuri
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 :)


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 :)

#16 Red Falcon   Members   -  Reputation: 142

Like
0Likes
Like

Posted 24 November 2004 - 08:51 PM

Quote:
Original post by xyuri
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 :)


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


#17 BdR   Members   -  Reputation: 154

Like
0Likes
Like

Posted 24 November 2004 - 09:21 PM

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

#18 JTippetts   Moderators   -  Reputation: 8158

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]


#19 Rob Loach   Moderators   -  Reputation: 1500

Like
0Likes
Like

Posted 25 November 2004 - 06:20 AM

Quote:
Original post by Zahlman
The 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.



PARTNERS