Smallest Executable to write "Hello World" to the screen

Started by Prince Wotoshi, November 01, 2008, 08:09:19 PM

Previous topic - Next topic

Prince Wotoshi

With a couple of guys we have a challenge who can write the smallest executable being able to print "Hello World".
Since the .com files would be the smallest possible, this is the current target.

Using a little trick (command line argument) I'm up to 7 bytes:


mov ah,09h
mov dx,82h
int 21h

which can be run: test.com Hello World$
and it would print Hello World to the screen.

The only way I could come up with to make it another byte shorter is:


mov ah,09h
mov dl,82h
int 21h

This should work the same, but gives an error instead:
Quote
Administrator: cmd.exe - test3.com hello$
The NTVDM CPU has encountered an illegal instruction.
CS:11ed IP:0024 OP:ff ff ff ff ff Choose 'Close' to terminate the application.

I know I'm assuming an empty DH here, but when I run both versions through debug.exe the registers are identical (except for the IP which is off by one byte of course).
Shouldn't this just work or am I missing something here?

Any other ideas to make it even shorter?

Thanks!

sinsi


.model tiny
.286
.code
org 100h
go: mov al,dh
    call phex8
    ret
phex8:  ror al,4
        call phex4
        ror al,4
phex4:  push ax
        and al,15
        cmp al,10
        sbb al,105
        das
        mov dl,al
        mov ah,2
        int 21h
        pop ax
        ret

end go

This code gives me "05" as the result, so I guess DH isn't 0 after all...
You should really have a "ret" at the end of your code too.
Light travels faster than sound, that's why some people seem bright until you hear them.

Prince Wotoshi

strange, it gives 11 for me when I run your code, but when I run it through debug.exe:


AX=0000  BX=0000  CX=001F  DX=0000  SP=FFFE  BP=0000  SI=0000  DI=0000
DS=17AB  ES=17AB  SS=17AB  CS=17AB  IP=0102   NV UP EI PL NZ NA PO NC
17AB:0102 E80100        CALL    0106

Both AX and DX are 0 after the first line of code....
So debug.exe doesn't work like it should then?

I know about the ret that should be there, but it doesn't help in size :D

Thanks for your reply!

sinsi

The only registers initialised by DOS for a .com program are AL,AH,DS,ES,SS and SP, all others are 'undefined' - they could be anything, usually what DOS left in there.
Debug initialises BX:CX to the program's size, maybe it zeroes out other registers? For me, debugging any program shows DX=0.
Light travels faster than sound, that's why some people seem bright until you hear them.

MichaelW

eschew obfuscation

Prince Wotoshi

Ahhh, so that explains why it looks ok.
Well, then 7 bytes really is the smallest we can go, I think.

Thanks for your answers!

FORTRANS

Hi,

   Yes I just got bitten by the difference between DEBUG and
normal loading of a program.  Look at the GENERAL.TXT file
in the Hugi Compo rules for a good description of the start up
register contents.

http://www.hugi.scene.org/compo/

   The DI register was zeroed by DEBUG, which "fixed" an error
in my code.

Cheers,

Steve N.

jj2007

Quote from: Prince Wotoshi on November 01, 2008, 08:09:19 PM
Using a little trick (command line argument) I'm up to 7 bytes:


mov ah,09h
mov dx,82h
int 21h

which can be run: test.com Hello World$
and it would print Hello World to the screen.

Without the ret, I get a lot of garbage until it prints Hello. Are the rules of your game unspecific enough to tolerate the garbage?

Prince Wotoshi

Are you sure you have the $ at the end of the argument?
It works perfectly for me on vista. This the file (program) if you look at it from a hex editor:


B409 BA8200 CD21


And no it's not allowed to see garbage ;), but for me it doesnt......

zemtex

Hey Prince Wotoshi. I see that you have a captains of crush gripper in your avatar. It was funny to see that there are grip trainers in this forum. I have closed the CoC 3.5 myself from a choked position and I have repped the CoC 3 from a non-choked position for about 6 reps.
I have been puzzling with lego bricks all my life. I know how to do this. When Peter, at age 6 is competing with me, I find it extremely neccessary to show him that I can puzzle bricks better than him, because he is so damn talented that all that is called rational has gone haywire.

Prince Wotoshi

Yes, I did a lot of grip training in the past :)
repping the #3 is a nice achievement, as well as closing the #3.5 from a choke. Good job!
I did both as well, but was not able to become COC certified. My small hands really gave me the disadvantage on the credit card set.
I got Mash monster certified with my #3 though, and the pic you see in my avatar is the #3.

I'm also red nail certified, but achieving that was a lot easier :)

But like I said, I did a lot in the past. Now I sometimes still do it, but I cannot close the #3 consistently anymore. Only on good days ;)


zemtex

I have nails here myself. I havent trained much with them because I tend to run out of nails pretty quickly, and it takes a while to order new ones. I'm not in america. I bend blue nails very easily, but the red nail is not in reach yet.

I train with alot of equipment related to grip and forearm development. Here is a list of equipment/exercises I use frequently:

1: Captains of Crush grippers (I have dual sets of all of them)
2: Heavy Grips grippers (I have all of them)
3: Ironmind Wrist Roller (This one is really effective, it gives you a forearm pump like nothing else i've tried)
4: Ironmind pinch grip block (This one gets on the pinch grip)
5: Ironmind Rolling Thunder (I like this one)
6: Hammer Bar (I ordered this from an armwrestling store, its an effective tool, you mount weight plates onto it)
7: Hercules Bar (This is also a good forearm developer)
8: I use normal weight plates in my hand and curl them with my wrist, I can almost handle 15 kg plates now)

My bench press is really bad at the moment, but my deadlift is 280 kg and my squat is 210 kg. Overhead press is 100 kg x 3 reps so far.
Bicep curl is 90 kg x 3 reps at most.

My strongest area is definitely deadlift. I am trying to improve my bench, I can barely handle 120 kg in the bench. I have very long arms, it could be because of that i'm not sure.

Anyways, good day!

BTW: I understand the emotional situation one can get into after years of training. You get tired, cant afford enough protein, motivation is lost etc. It takes effort to get back into a good pattern again. I struggle with this myself.
I have been puzzling with lego bricks all my life. I know how to do this. When Peter, at age 6 is competing with me, I find it extremely neccessary to show him that I can puzzle bricks better than him, because he is so damn talented that all that is called rational has gone haywire.

xandaz

you must keep in mind that interrupts are executable code.
this i think may be smaller. works only for text mode.

      mov ax,0b800h
      mov es,eax
      lea esi,HelloString
      mov edi,0
      mov cx,sizeof HelloString
loop:
      lodsb
      mov ah,07h ; not sure if attr should be ah or al long time no DOS
      stosw
      dec cx
      jcxz end_loop
      jmp loop
end_loop:
      int 20h

xandaz

   Not sure how this stiff works anymore . It gives invalid fixup .

.286
.model tiny

.data

HelloString     db      'Hello World'

.code
org     100h
        _start:
               mov     ax,0b800h
               mov     es,ax
               lea       si,HelloString
               mov     di,0
               mov     cx,sizeof HelloString
               cld

string_loop:
               lodsb
               mov     ah,7
               stosw
               dec cx
               jcxz  end_loop
               jmp   string_loop
end_loop:
               int      20h
               
end     _start

redskull

37 bytes, 15 of code?

.286
.model tiny
option casemap:none

.data
out_string  db "H", 07h, "e",07h, "l", 07h,"l", 07h,"o", 07h," ", 07h,"W", 07h,"o", 07h,"r", 07h,"l", 07h,"d", 07h

.code
org 0100h
start:   
   
    mov dx,0b800h
    mov es,dx
    mov cl, SIZEOF out_string
    mov si, OFFSET out_string
move:
    lodsw
    stosw
    loop move
    ret

end start
Strange women, lying in ponds, distributing swords, is no basis for a system of government