Ultimate "HELLO WORLD" - FBC 1.01.0 review

General FreeBASIC programming questions.
DOS386
Posts: 798
Joined: Jul 02, 2005 20:55

Ultimate "HELLO WORLD" - FBC 1.01.0 review

Postby DOS386 » Dec 31, 2014 11:41

Code: Select all

'' "HELLO.BAS" - ultimate "HELLO WORLD" program
'' (C) 2015-Jan-01 All fights reserved

'' For DOS (FreeDOS/EDR-DOS/...) and Win32 (ME/NT/10/XP/...)
'' Compile with FreeBASIC Compiler only !!!
'' Tests FBC efficiency - the (smallest possible) bloat of executables

'' Define "__USE_PRINT__" on the commandline ("-d") to use the PRINT
'' command (gives more bloat), otherwise job will be done most
'' efficiently natively through DPMI+BIOS or Win32 API

'' REM DOS BATttery file
'' FBD HELLO.BAS
'' REN HELLO.EXE HDE.EXE
'' FBD -d __USE_PRINT__ HELLO.BAS
'' REN HELLO.EXE HDP.EXE

'' REM Win32 BATttery file
'' FBW HELLO.BAS
'' REN HELLO.EXE HWE.EXE
'' FBW -d __USE_PRINT__ HELLO.BAS
'' REN HELLO.EXE HWP.EXE

'' -----------------------------

type UINT32 as UINTEGER
type UINT8  as UBYTE

'' -----------------------------

#if defined (__FB_DOS__)
  #define __FB_GOTHIM__
  Public Function __crt0_glob_function Alias "__crt0_glob_function" _
  ( ByVal arg As UByte Ptr ) As UByte Ptr Ptr
  Return 0
  End Function
#endif
#if defined (__FB_WIN32__)
  #define __FB_GOTHIM__
  Extern _CRT_glob Alias "_CRT_glob" As Integer
  Dim Shared _CRT_glob As Integer = 0
  Extern _dowildcard Alias "_dowildcard" As Long
  Dim Shared _dowildcard As Long = 0
#endif
#if not defined (__FB_GOTHIM__)
  #error "UNSUPPORTED TARGET"
#endif
#if defined (__FB_DOS__)
  #if defined (__FB_WIN32__)
    #error "YOU CAN'T DANCE AT 2 DIFFERENT PARTIES AT SAME TIME"
  #endif
#endif

'' -----------------------------

#if not defined (__USE_PRINT__)
  #if defined (__FB_WIN32__)
    EXTERN "Windows"
      DECLARE FUNCTION GetStdHandle (BYVAL AS UINT32) AS UINT32
      DECLARE FUNCTION WriteFile (BYVAL AS UINT32, BYVAL AS UINT32, BYVAL _
                       AS UINT32, BYVAL AS UINT32, BYVAL AS UINT32) AS UINT32
    END EXTERN
  #endif
#endif

'' -----------------------------

#if not defined (__USE_PRINT__)

  SUB PUTCH (BYVAL QQ8 AS UINT8)

    ASM

  #if defined (__FB_DOS__)

        push   ebx
        mov    al, [QQ8]      '' Char in AL
        mov    ah, 14         '' $0E - "TTY" BIOS service
        xor    ebx, ebx       '' MOVNTQ EBX, 0
        int    16             '' INT $10 - BIOS screen stuff
        pop    ebx

  #else

        mov    eax, 4294967285
        push   eax                '' "-11" means "stdout"
        call   GetStdHandle
        inc    eax                '' CMPNTQ EAX, $FFFF'FFFF
        jz     short consolesucks '' Console got shot by some gun geek ???
        dec    eax

        mov    dl, [QQ8]
        push   edx        '' Char to write (EAX holds hendaye)
        xor    edx, edx   '' MOVNTQ EDX, 0
        push   edx        '' PUSHD 0 | Reserved UINT32 for output
        mov    ecx, esp   '' Now points to the reserved UINT32
        push   edx        '' Useless ZERO :-(
        push   ecx        '' Output: number of chars written !!! :-D
        inc    edx        '' MOVNTQ EDX, 1 | Size of text
        push   edx        '' Size of text, no "$" no ZERO at the end ;-)
        add    ecx, 4     '' Now points to our "text", upper 24 bits are junk
        push   ecx        '' Addr of our "text"
        push   eax        '' Hendaye
        call   WriteFile
        pop    ecx        '' Discard return value with written amount
        pop    ecx        '' Discard PUSH'ed char too

consolesucks:

  #endif

    END ASM

  END SUB '' PUTCH

#endif

'' -----------------------------

#if defined (__USE_PRINT__)
  #if defined (__FB_DOS__)
    ? "Hello __USE_PRINT__   DOS"
  #else
    ? "Hello __USE_PRINT__ Win32"
  #endif
#else
  PUTCH (72)
  PUTCH (101)
  PUTCH (108)
  PUTCH (108)
  PUTCH (111)
  PUTCH (32)      '' Space
  #if defined (__FB_DOS__)
    PUTCH (68)    '' "D"
  #else
    PUTCH (87)    '' "W"
  #endif
  PUTCH (13)      '' CR
  PUTCH (10)      '' LF
#endif

'' -----------------------------

END

Code: Select all

HELLO.BAS      3'987
PS.BAS           735

HDE - Hello DOS most efficient

HDE0185.EXE   74'240
HDE0220.EXE   74'240
HDE0901.EXE  139'776
HDE1010.EXE   74'240 <- same size

HDP - Hello DOS using PRINT

HDP0185.EXE   83'456
HDP0220.EXE   83'456
HDP0901.EXE  152'576
HDP1010.EXE   82'944 <- smaller !!!

HWE - Hello Win32 most efficient

HWE0185.EXE    6'144
HWE0220.EXE    7'680
HWE0901.EXE   12'800
HWE1010.EXE   13'824 <- very bloated
HWE1010Q.EXE  14'369 (binutils from 0.22) <- silly bloat

HWP - Hello Win32 using PRINT

HWP0185.EXE   15'872
HWP0220.EXE   16'896
HWP0901.EXE   22'528
HWP1010.EXE   25'088 <- very bloated
HWP1010Q.EXE  26'145 (binutils from 0.22) <- silly bloat

PSD - PUTSMIL DOS

PSD0185.EXE  186'368
PSD0220.EXE  186'368
PSD0901.EXE  252'928
PSD1010.EXE  186'368 <- same size

PSW - PUTSMIL Win32

PSW0185.EXE  108'032
PSW0220.EXE  103'936
PSW0901.EXE  113'152
PSW1010.EXE  122'880 <- marginally bigger
PSW1010Q.EXE 124'449 (binutils from 0.22) <- silly bloat

FYI: good old binutils from 0.22 with FBC 1.01.0 do add
following 33 Octet's of garbage to end of Win32 binary:
"!   .text.startup .text.unlikely "


viewtopic.php?t=23160 "Version 1.01.0 released"
viewtopic.php?t=22664 "EXE sizes"
viewtopic.php?t=11757 "The war on DGJPP bloat again | Helo word sizes | how to save"

Some tests about the recent 1.01.1 release:

- no spectacular changes observed in the DOS version (1.00.0 worked for me too), no DOS output bloat increase since 0.18.5 (see above)

- Win32 version runs on ME again (1.00.0 didn't), also graphics does (but banding effects), some increase of bloat (see above)

"changelog.txt" wrote:

- Win32 gfxlib2 did not process thread messages, causing problems with response to system hotkeys and potentially more


remaining problems:

- Graphics DOS: can't create a screen that doesn't match the graphics card (for example 300x700) - more a missing feature than bug

- Graphics Win32: behaves badly under HX (keyboard dead) - I had expected this to get resolved by fix above, but no

- Graphics Win32: banding effects under ME only (not XP and HX) (maybe UNLOCK would help)

- Linker Win32 creates silly and bloated (see above) (still working) executables, if "ld.exe" replaced from version 0.22, using "as.exe" from 0.22 and "ld.exe" from 0.90.1 is OK

Not yet tested on CPU older than P3.

Conclusion: 1.01.0 seems to be a good release ... thanks to all developers.
DOS386
Posts: 798
Joined: Jul 02, 2005 20:55

Re: Ultimate "HELLO WORLD" - FBC 1.01.0 review

Postby DOS386 » Jan 01, 2015 17:36

Code: Select all

- fbc no longer includes full ldscripts, a supplemental snippet (fbextra.x) is passed to the linker instead (except for the DOS/DJGPP version which still relies on a modified ldscript)


The linking trouble (warns + strange binary) is most likely due to this ^^^ change in 0.24. Taking AS.EXE + LD.EXE + 2 DLL's (only a bit bloated ...) from 0.24 (rather than 0.22) fixes it.
DOS386
Posts: 798
Joined: Jul 02, 2005 20:55

Re: Ultimate "HELLO WORLD" - FBC 1.01.0 review

Postby DOS386 » Jan 12, 2015 10:39

I wrote:

> Not yet tested on CPU older than P3.

Done! Result: DOS "Hello world" runs on P1, while Win32 "Hello world" crashes at some CMOVNTQ-like instruction. Obviously the "-arch" option of FBC (called "March" in some other compilers) allowing to target 386, 486, 586 is of very limited use if all libraries are precompiled with "March=686/P3_with_CMOVNTQ" (nowadays even stuff compiled with "March=786/P4_with_SSE" without documented requirements is getting common).

Return to “General”

Who is online

Users browsing this forum: No registered users and 14 guests