Hello World! on modern processors.

From: Richard Erlacher <edick_at_idcomm.com>
Date: Wed Aug 22 00:03:35 2001

a long call or a jump takes 3 bytes, but we won't count that for now ...
        .chip 6502
prport .def $FF00 ; send a character to this port and it transmits the
7 ascii bits. Use the MSB as strobe if your port doesn't generate a strobe for
you

        .loc $0210
s: .ascii HELLO WORLD [11]
        .byte $0D [1]
        .loc $0200
        ldx #11 ; length of this string (decimal) [2 bytes]
plp: lda s,x ; get the payload, byte by byte [1]
        or #128 ; set the strobe [1]
        sta prport ; and ship it [3 bytes]
        and #127 ; now clear the strobe [1]
        sta prport ; and write it again [3]
        dex ; [1]
        bne plp ; [2]
        ret ; or whatever [1]

That's got to be about 27 bytes ... AND it uses no services or external storage
of any sort. Now, you could save a byte by mapping I/O into zero page ... and 4
if you don't have to generate a strobe, i.e. your port does that for you in
hardware, as many do. This is just a first guess ... it might be possible to
make it shorter.

Dick

----- Original Message -----
From: "Sean 'Captain Napalm' Conner" <spc_at_conman.org>
To: <classiccmp_at_classiccmp.org>
Sent: Tuesday, August 21, 2001 9:53 PM
Subject: Re: Hello World! on modern processors.


> It was thus said that the Great Jay West once stated:
> >
> > Yes, but per my earlier example.... are we shooting for less instructions in
> > the program or less intructions executed in total for the program? (ie, your
> > 23 byte example is calling dos system services, so.... lots of additional
> > instructions there).
>
> Well, this all started when Iggy said there wasn't a PRINT language
> element in Assembly, so I suppose it's the easiest way to get something
> printed, which means using built in system support.
>
> Now, if you are doing this on an IBM PC the quickest way (assuming a CGA
> card at minimum 8-) is possibly:
>
> org 0100h
> push cs
> pop ds
> mov ax,0b800h
> mov es,ax
> mov si,offset message
> xor di,di
> mov cx,12
> rep movsw
> ret
> message db 'H',7,'e',7,'l',7,'l',7,'o',7,' ',7
> db 'w',7,'o',7,'r',7,'l',7,'d',7,'!',7
> end
>
> -spc (42 bytes, more if you want to be pedantic and check for MDA ... )
>
>
Received on Wed Aug 22 2001 - 00:03:35 BST

This archive was generated by hypermail 2.3.0 : Fri Oct 10 2014 - 23:33:34 BST