flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
rugxulo 07 Jul 2016, 23:57
I'm not sure why you demand it has to be an .EXE. The whole point of .EXE is to support relocations, multiple segments, i.e. greater than 64 kb .COMs.
You've probably got your output as small as it can go, but even on FAT12 floppy disks, the cluster size is 512 bytes, so it's still going to waste that much, at minimum. So it may not really be worth saving a few bytes when half a kb is already being used. |
|||
![]() |
|
DOS386 08 Jul 2016, 08:31
> No arguments
> I wrote it in hex code Please release source code. _________________ Bug Nr.: 12345 Title: Hello World program compiles to 100 KB !!! Status: Closed: NOT a Bug |
|||
![]() |
|
patulinu 08 Jul 2016, 11:36
DOS386 wrote: Please release source code. |
|||
![]() |
|
patulinu 08 Jul 2016, 15:01
Here is what I could understand from the hexa version of the 37-byte "hello" program.
I Compiled it with the latest release of FASM (1.71.54). The resulting raw file is exactly the same as the original (every byte). Obviously, it runs perfectly, as the original one. ![]() No need to rename the resulting BIN file to EXE anymore (now using the "format" directive so that it generates file with EXE extension). 9/July: fixed comment about word 0fdb4h: it's the SS, not Checksum, as pointed out by l4m2. Code: format binary as 'exe' ; no need to rename ".bin" to ".exe" after compiled. org 0 ; this stuff should start at offset 0 (zero). ExeSignature db 4dh, 5ah ; exe stub: file signature 'MZ' at offset 0. LastPageSize dw 25h ; exe stub: number of bytes in the last page (in our case, the file size). PageCount dw 1 ; exe stub: number of whole/partial pages. Entry_Point: ; at offset 106h mov dx, sp ; [#1] same as "mov dx, msg", since sp=118h, as set in the header (see #2). HeaderSize dw 0 ; exe stub: header size (in paragraphs). ; NOTE: this runs as "add [bx+si],al" but it doesn't hurt. mov ah, 9 ; dos service to display a $-terminated text. int 21h ; displays the msg. the addr of the msg was set at the code entry point (see #1). SS_InitValue dw 0fdb4h ; exe stub: Initial SS relative to start of executable. ; NOTE: this runs as "mov ah,fd" but it doesn't hurt. SP_InitValue dw 118h ; [#2] exe stub: initial value for the SP register (see #1). ; NOTE: this runs as "sbb [bx+di],al" but it doesn't hurt. int 20h ; COM-style wayout. IP_InitValue dw 106h ; exe stub: initial value for the IP register (program entry point). CS_InitValue dw 0fff0h ; exe stub: relocatable segment address for CS. msg db 'Hello World!$' Running the BAT, which waits for a keypress: ![]()
Last edited by patulinu on 09 Jul 2016, 12:14; edited 1 time in total |
|||||||||||
![]() |
|
l4m2 09 Jul 2016, 03:21
patulinu wrote: [color=darkblue]Here is what I could understand from the hexa version of the 37-byte "hello" program. fdb4 should be ss init value |
|||
![]() |
|
patulinu 09 Jul 2016, 12:16
l4m2 wrote: fdb4 should be ss init value Yes, thank you. Fixed. |
|||
![]() |
|
l4m2 09 Jul 2016, 16:20
This code works both as .exe and .com:
Code: format binary as 'exe' ; no need to rename ".bin" to ".exe" after compiled. org 100h ; this stuff should start at offset 100h. ExeSignature db 4dh, 5ah ; 00: 4D 5A exe stub: file signature 'MZ' Entry_Point: mov dx, msg ; 02: BA 18 ; 04: 01 exe stub: number of whole/partial pages. db 0, 0ffh ; 05: 00 ; 06: FF mov ax, 0 ; 07: B8 ; 08: 00 00 header size mov ah, 9 ; 0A: B4 09 int 21h ; 0C: CD 21 SS_InitValue: mov ah, 0fdh ; 0E: B4 FD SP_InitValue: int 20h ; 10: CD 20 nop ; 12: 90 90 nop IP_InitValue: dw Entry_Point ; 14: 02 01 exe stub: initial value for the IP register (program entry point). CS_InitValue: dw 0fff0h ; 16: F0 FF exe stub: relocatable segment address for CS. msg db 'Hello World!$' besides, there is space in the code (the two nops won't execute). |
|||
![]() |
|
patulinu 09 Jul 2016, 16:43
l4m2 wrote: This code works both as .exe and .com: I didn't try to make your code smaller. Just created the source code that generates your original binaries. It seems the only way to make it smaller is by changing the message itself. Maybe to just: "Hi!". ![]() |
|||
![]() |
|
l4m2 13 Jul 2016, 03:29
This code runs perfectly on dosbox debug but not directly run:
Code: format binary as 'exe' org $0100 db 'MZ' mov dx, msg-2 dw $FF00 push dx dw $0000 pop bx sub [bx],word $FFF0-'He' mov ah, $09 int $21 ;ret db $C3 dd $FFF0'0102 msg: db 'llo World!$' |
|||
![]() |
|
patulinu 13 Jul 2016, 13:03
l4m2 wrote: This code runs perfectly on dosbox debug but not directly run: If it doesn't run, it doesn't count. ![]() |
|||
![]() |
|
l4m2 13 Jul 2016, 13:11
Quote:
So is there a way to make it runable? |
|||
![]() |
|
patulinu 13 Jul 2016, 16:25
l4m2 wrote:
I believe your first version is the smallest possible for a EXE/DOS/16-bit program, because all those header values left alone are really required by the OS so that the program can be load and run. You may even rearrange things as you did in the latest versions, but all you will be able to accomplish is save 1 or 2 bytes in a raw (but not enough to move the "hello" message to a lower addr and get rid of the tail). Due to the need of keeping those minimum header fields, the only safe way to make your program smaller is by turning the whole "hello" message into a simple "Hi." message. I can't see any other option for a true EXE program, but I'm still a enthusiast. |
|||
![]() |
|
l4m2 14 Jul 2016, 04:44
Code: format binary as 'exe' org $0100 db 'MZ' ;00 'MZ' mov bx, msg-2 ;02 ;04 word 1 dw $ED00 ;05 mov ax, $0000 ;07 ;08 word 0 mov [bx],word 'He' ;0A mov dx, bx ;0E SS mov ah, $09 ;10 SP int $21 ;12 ;ret dw $C392 ;14 IP dw -$C39 ;16 CS msg: db 'llo World!$' |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.