hello world = 23 bytes 
Author Message
 hello world = 23 bytes

Using TASM I have made a .com file that prints the string
hello world
to the screen and the .com file is only 23 bytes.
I was just curious to see if anyone has done this smaller than 23 bytes.
Thanks

Boogie



Wed, 26 Sep 2001 03:00:00 GMT  
 hello world = 23 bytes
Yeah, I wrote a 19 byte version.

I will release it here in a few days time.

regards
    TAD

Quote:

>Using TASM I have made a .com file that prints the string
>hello world
>to the screen and the .com file is only 23 bytes.
>I was just curious to see if anyone has done this smaller than 23 bytes.
>Thanks

>Boogie



Wed, 26 Sep 2001 03:00:00 GMT  
 hello world = 23 bytes
Could you just post the source code?

THX,
-Benjamin.


Quote:
>Using TASM I have made a .com file that prints the string
>hello world
>to the screen and the .com file is only 23 bytes.
>I was just curious to see if anyone has done this smaller than 23 bytes.
>Thanks

>Boogie



Wed, 26 Sep 2001 03:00:00 GMT  
 hello world = 23 bytes

Quote:

>Using TASM I have made a .com file that prints the string
>hello world
>to the screen and the .com file is only 23 bytes.
>I was just curious to see if anyone has done this smaller than 23 bytes.

Here is one - in 17 bytes.

    assume ds:_TEXT, cs:_TEXT, es:_TEXT
_TEXT segment

    org    100h
start:
    mov    bp,82h     ;bp -> to DOS command line start (skip initial space)
    mov    cl,11        ; = length of 'hello world'
    mov    bl,cl         ; nice blue color code
    mov    ah,13h     ; subfunction for copy to VGA text page
    xor      dx,dx       ; at screen position 0,0
; al = 0, at least if started under DOS 6.22, so bl is the color
    int       10h          ;copy the string (es = ds)
    mov     ah,4ch    ;exit to DOS
    int        21h         ;because the job is DONE!

_TEXT    ends
    end    start

Assemble and link this code. You get a 17 byte long xxx.com file. Now start
it by
xxx hello world
and you get the 'hello world' written at the first line. It does however a
lot more. I've made it type 'hello Vlado', 'I love you  ' etc. and it works
fine.

I guess this is not what you expected. Neither I'm proud of it. IMO, if
somebody wishes to compete, he must first post his code along with the exact
specification of the conditions which it must meet.

Regards, Vlado



Wed, 26 Sep 2001 03:00:00 GMT  
 hello world = 23 bytes

Quote:

> Using TASM I have made a .com file that prints the string
> hello world
> to the screen and the .com file is only 23 bytes.
> I was just curious to see if anyone has done this smaller than 23 bytes.

  mov dx,offset Hello$          ; 3
  mov ah,9                      ; 2
  int 21h                       ; 2
  ret                           ; 1
Hello$  db "hello world$"     ; 12

Total should be 20 bytes. How did you get to 23?

Terje

--

Using self-discipline, see http://www.eiffel.com/discipline
"almost all programming can be viewed as an exercise in caching"



Wed, 26 Sep 2001 03:00:00 GMT  
 hello world = 23 bytes
|
|>Using TASM I have made a .com file that prints the string
|>hello world
|>to the screen and the .com file is only 23 bytes.
|>I was just curious to see if anyone has done this smaller than 23 bytes.
|
|
|Here is one - in 17 bytes.

[SNIP]

Here's one - in 8 bytes

        .model  tiny
        .code
        org     0100h
Start:
        xchg    bp,ax    ;BP=09xxh and now AH=09h
        mov     dx,offset s$
        int     21h
        retn
s$      db      '$'
        end     Start

Add a string and the code will get bigger



Wed, 26 Sep 2001 03:00:00 GMT  
 hello world = 23 bytes

Quote:
>  mov dx,offset Hello$              ; 3
>  mov ah,9                  ; 2
>  int 21h                   ; 2
>  ret                               ; 1
>Hello$      db "hello world$"     ; 12

>Total should be 20 bytes. How did you get to 23?

>Terje

Just as I would have done. Of course, you all realize that the true
programmers' statement is 'Hello world!' and so it *should* be 21 bytes, but
that was just a technicality. I think the 23 bytes was probably due to using
int 21h (b4 4c cd 21??)... he's probably not familiar with the internals of
DOS. ;)

As for that command line person, that's cheating. The program is supposed to do
the work, not you. As for the person who will "post the code later," I think
you're lying. =)  Just post the code, or else you have no credibility
whatsoever.

  - vulture a.k.a. Sean Stanek



Wed, 26 Sep 2001 03:00:00 GMT  
 hello world = 23 bytes


Quote:

>> Using TASM I have made a .com file that prints the string
>> hello world
>> to the screen and the .com file is only 23 bytes.
>> I was just curious to see if anyone has done this smaller than 23 bytes.

>  mov dx,offset Hello$         ; 3
>  mov ah,9                     ; 2
>  int 21h                      ; 2
>  ret                          ; 1
>Hello$ db "hello world$"       ; 12

>Total should be 20 bytes. How did you get to 23?

Because "hello world" is syntactically wrong. It should read "Hello,
world!" where the capitalization of the "h" can be accomplished at
virtually no cost. Things get more complicated as it comes to the
necessary exclamation mark (without the exclamation mark, "Hello world"
is not a valid english sentence, neither is it without the comma. We
still haven't taken into consideration the need for <cr><lf> which will
be necessary to make the application more user- friendly. We are at 24
bytes now and still there is no means to catch a DOS critical error in
case the user has redirected the output to a file e.g. "hello >
a:hello.txt" and something goes wrong.

Squeezing all this into a mere 23 bytes most definitely requires some
very advanced programming skills.

Regards,

Michael Tippach



Wed, 26 Sep 2001 03:00:00 GMT  
 hello world = 23 bytes
All this fuss over printing "hello world"...

here is my code, as for the rules and the "!" character and 0D 0A
these were NOT mentioned in the original message (see below).

    .model tiny
    .code
    org 256
start:
        mov dx,offset greetz
        xchg ax,bp        ; assume BP=09xx at startup
        int 21h
        ret
greetz: db 'Hello World$'

    end start

if you think are are good at size optimization then why not
wait for the next Hugi size-compo which should hopefully
start in the next week or so... as soon as adok/hugi settle
on the rules and task at hand.

check out this Hugi page, for more info..

http://www.geocities.com/SiliconValley/Bay/6062/compo.htm

regards
    TAD    #:o)

Quote:



>>> Using TASM I have made a .com file that prints the string
>>> hello world
>>> to the screen and the .com file is only 23 bytes.
>>> I was just curious to see if anyone has done this smaller than 23 bytes.



Thu, 27 Sep 2001 03:00:00 GMT  
 hello world = 23 bytes
I looked at all these boring posts, and decided to post my own...

28 bytes long...I'm sure you can improve...

not an int in sight...much more fun, and no command line mucking...

DANGER! NASM/tlink syntax...also assumes screen mode 3.

segment code
resb 100h
..start:
                push word 0b850h                ;middle of screen
                pop es
                mov si,hi-1                        ;some strange bug within
NASM doesn't adress properly..
                mov cl,13                        ;13 letters...
                inc ah                            ;comes up black if no
colour is specified...
nerf:           lodsb                            ;load char
                stosw                            ;store + colour
                loop nerf                        ;loop...
                ret                                ;ret to PSP:0000 (there's
an int 20 there...sneaky)

hi      db      'Hello world!'

----------
Ian Scott...

www.geocities.com/SiliconValley/Hills/5938/
Nerf be with you!



Thu, 27 Sep 2001 03:00:00 GMT  
 hello world = 23 bytes

Quote:

> [snipped]
>As for that command line person, that's cheating.

Is it really?. Let's look closer at that. Lacking a code of your own I'll
use the Terje's smart program for comparison. At execution time both his and
mine programs behave much the same way - they set a pointer to some place in
their segment and pass it to some external module for actual displaying. In
Terje's program this place is filled in at task contruction time and in
mine - at pre-run time. Therefore, if we confine ourselves to a single run,
both programs are equivalent, since you type in 'Hello world' only once in
both cases.

For multiple runs I might use CED or its equivalents.  As you see, this is a
slippery ground. Think over it before rushing on me again and please, be
more FAIR!

Remaining otherwise respectful, Vlado



Thu, 27 Sep 2001 03:00:00 GMT  
 hello world = 23 bytes
You need 12 bytes for "Hello world$" and the rest are approximations

 mov ah, 9 = 2 bytes
 mov dx, offset msg = 3 bytes
 int 21h = 2 bytes
 ret = 1 byte
msg db 'Hello world' = 12 bytes

; let's assume we can use ret instead of int 20h
; which is true for .com file

I got 20 bytes. Hoorray!!

I guess you can play around and even try to compress it :)


[kwoy/bh]



Sat, 29 Sep 2001 03:00:00 GMT  
 hello world = 23 bytes


Quote:
> Using TASM I have made a .com file that prints the string
> hello world
> to the screen and the .com file is only 23 bytes.
> I was just curious to see if anyone has done this smaller than 23 bytes.
> Thanks

> Boogie

try writing a program that prints the current time/date as:

dd/mm/yyyy<space>hh:mm:ss<cr><lf>

--
Regards,
TK - TBD



Sat, 29 Sep 2001 03:00:00 GMT  
 hello world = 23 bytes

Quote:



> > Using TASM I have made a .com file that prints the string
> > hello world
> > to the screen and the .com file is only 23 bytes.
> > I was just curious to see if anyone has done this smaller than 23 bytes.
> > Thanks

> > Boogie

> try writing a program that prints the current time/date as:

> dd/mm/yyyy<space>hh:mm:ss<cr><lf>

The smallest general way to do this is probably to use the CMOS clock,
since this is maintained in BCD, i.e. very little conversion needed.

BTW, I would change the format to the equivalent ISO standard:

  yyyy-mm-dd hh:mm:ss

The code could look somewhat like this: (Written from scratch without
any docs, so there's bound to be some errors.)

        .data
table:
        dw      CENTURY
        dw      YEAR
        db      '-'
        dw      MONTH
        db      '-'
        dw      DAY
        db      ' '
        dw      HOUR
        db      ':'
        dw      MINUTE
        db      ':'
        dw      SECOND
table_end:
        db      13,10,'$'

; 23 bytes of data

        .code
        org 100h
start:
        cld
        mov di,offset table
        mov dx,di
        call read_cmos_and_print
next:
        call read_cmos_and_print
        inc di
        cmp di,offset table_end
         jb next
        mov ah,9                ; Print the generated string
        int 21h
        ret                     ; Program finished!

; 23 bytes of code in main program

read_cmos_and_print proc
        mov ax,[di]             ; Load CMOS offset
        out 70h, al
        in al,71h               ; Read the data
; I'm not sure if I need to check a status register first?

        mov ah,al
        shr ah,4
        and al,15
        add ax,'00'
        stosw                   ; Store back two ascii digits
        ret

; 18 bytes in subroutine
        end     start

So, assuming my hand-assembled byte count is correct, this first attempt
would need 64 bytes, it is almost certainly possible to make it a lot
shorter. :-)

--

Using self-discipline, see http://www.eiffel.com/discipline
"almost all programming can be viewed as an exercise in caching"



Sat, 29 Sep 2001 03:00:00 GMT  
 hello world = 23 bytes
[snippety snip snip]
:
: hello   db  "Hello World", 10, 13, "$"

you missed the comma, won't that make it 23 aswell?

Ed



Sun, 30 Sep 2001 03:00:00 GMT  
 
 [ 25 post ]  Go to page: [1] [2]

 Relevant Pages 

1. hello world = 23 bytes

2. Boogie's Re: hello world = 23 bytes

3. Boogie's Re: hello world = 23 bytes

4. 158 byte linux hello world [nasm]

5. coding "hello /options" (hello-world)

6. SRFI 23: SRFI 23: Error reporting mechanism

7. - Major automotive website (Posted 23/10/2000 13:34:23.470)

8. Hello, world!

9. hello (world)

10. Hello World !

11. Hello World!

12. Hello World!

 

 
Powered by phpBB® Forum Software