On 1/7/24 14:21, Ingemar Ragnemalm via fpc-pascal wrote:

Just for comparison, I fired up Think Pascal and made Hello world!

Plain Hello world, closes so quickly that you don't have time to see it: 4625 bytes.

Including ShowText and while not Button do; 4639 bytes.

Yes, less than 5k! Progress?

Nah! It's bloat, bloat, bloat, horrible bloat!!! I'm not impressed. :)

Nothing beats assembler for DOS:

; nasm asmhello.asm -o asmhello.com
        bits 16
        cpu 8086
        org 100h
        mov dx, msg
        mov ah, 9
        int 21h
        ret
msg:    db 'Hello, world!', 13, 10, '$'

The produced executable is only 24 bytes (8 bytes of code and 16 bytes of data):

BA 08 01 B4 09 CD 21 C3 48 65 6C 6C 6F 2C 20 77 6F 72 6C 64 21 0D 0A 24

You can write this down on a sheet of paper, or memorize it and recite it from memory. Try doing that with 4639 bytes :)

Note that noobs will use the following way to terminate the program:

mov ax, 4c00h

int 21h

But that increases the binary size to 28 bytes. We can put a 'ret' instruction instead, and that works, because DOS puts a 0000h word on top of the stack, and that points to CS:0000h, which is the beginning of the PSP. And that starts with an int 20h, which is the oldschool (MS-DOS version 1) way of terminating a process, which requires CS to point to the PSP, which it does, because we're a .com file.

Nikolay

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to