flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
DOS386 22 Feb 2007, 04:53
I created some example executables (based also on work of "babyboy10777"
![]() see also ( BB's PE ) : http://board.flatassembler.net/topic.php?t=5616 and ( my LE ) : http://board.flatassembler.net/topic.php?t=7122 and ( late 2009-06 derivative work by Borsuc based on my PE ) http://board.flatassembler.net/topic.php?t=10288 MZ: Code: ; ; FASM example of writing simple EXE program ; using "format MZ" ; format MZ stack $3000 ; Very generous heap 0 ; No memory here push cs pop ds mov ah,9 mov dx,txhello int $21 ; Print to screen mov ax,$4C00 int $21 ; Exit from EXE txhello: db 'Hello world !',$0D,$0A,$24 rb $5000 ; Additional memory here, can be also 0 ; or omitted for this "Hello" program ;END. Code: ;***************************************************************** ; ; FASM example of writing a simple DOS EXE ; program using "format binary" ; ; Limitations: ; Single-segment, no relocs, < 64 KiB EXE size, no "heap" ; ; Documentation below from www.delorie.com, some additions ; ;***************************************************************** ; ;00-01 0x4d, 0x5a. This is the "magic number" of an EXE file. ;The first byte of the file is 0x4d and the second is 0x5a. ;[HINT: it is "MZ"] ; ;02-03 The number of bytes in the last block of the program ;[SILLY: refers to the "complete" >> file << size (header + ;program, but excl. possible overlay), not the program code] ;that are actually used. If this value is zero, that means the ;entire last block is used (i.e. the effective value is 512). ; ;04-05 Number of blocks in the file that are part of ;the EXE file. If [02-03] is non-zero, only that much ;of the last block is used. [HINT: "block"=512 bytes] ; ;06-07 Number of relocation entries stored after the header. ;May be zero. [HINT: should be, relocs are a bad hack] ; ;08-09 Number of paragraphs in the header. The program's data ;begins just after the header, and this field can be used to ;calculate the appropriate file offset. The header includes ;the relocation entries. [SILLY: Note that some OSs and/or ;programs may fail if the header is not a multiple of 512 ;bytes.] [HINT: minimum header size is $20, resulting in 2 here] ; ;0A-0B Number of paragraphs of additional memory that the ;program will need. [SILLY: This is the equivalent of the BSS ;size in a Unix program.] The program can't be loaded if there ;isn't at least this much memory available to it. ; ;0C-0D Maximum number of paragraphs of additional memory. ;Normally, the OS reserves all the remaining conventional ;memory for your program [SILLY: suppress this with ;"heap 0"], but you can limit it with this field. ; ;0E-0F Relative value of the stack segment. This value is ;added to the segment the program was loaded at, ;and the result is used to initialize the SS register. ;[HINT: it is the size of the executable + reserved area, ;in 16-byte units] ; ;10-11 Initial value of the SP register. ;[HINT: stack size, equal to / comes from "stack" directive] ; ;12-13 Word checksum. If set properly, the 16-bit sum of ;all words in the file should be zero. Usually, ;this isn't filled in. [SILLY: this is useless & always ZERO] ; ;14-15 Initial value of the IP register. [HINT: it is ZERO] ; ;16-17 Initial value of the CS register, relative to the segment ;the program was loaded at. [HINT: it is ZERO] ; ;18-19 Offset of the first relocation item in the file. ;[HINT: it is mostly $1C, even if no relocs present at all Both sources compile into exactly same executables ![]() MZ stub for PE: Code: ; ; FASM Stub for PE executables ; format binary as "EXE" ; FASM 1.67.22 required PE: Code: ; ; http://board.flatassembler.net/topic.php?t=5616 ; Manual PE .EXE template ; Win32/HX-DOS GUI "Hello world", std imports ; ccbase = $400000 ; 4 Mi ccstartrva = $1000 ; 4 Ki format binary as "EXE" ; FASM 1.67.22 required 3 additional codes (besides those above) are inside package available for download ![]() ![]() Improvements against "babyboy10777"'s version: - Removed mysterious $0E00 constant (was $1000-$0200, diff of mem/file alignement) - Eliminated the silly need to add $400E00 to EVERY label - Provided working DOS stub giving useful hint to the user - Better commenting - Fixed alignement bug occurring if already aligned (one of my codes exposes it) The PE executables are verified to work in XP, 98, and DOS. Please test and post comments (bugs, possible optimizations, ...) ![]() EDIT : added link
_________________ Bug Nr.: 12345 Title: Hello World program compiles to 100 KB !!! Status: Closed: NOT a Bug Last edited by DOS386 on 16 Jun 2009, 11:10; edited 4 times in total |
|||||||||||
![]() |
|
rugxulo 22 Feb 2007, 17:58
Suggestions:
EDIT: Not everybody has both tar and zip, believe it or not (although they should ... or at least DJTAR, heh). Last edited by rugxulo on 22 Feb 2007, 18:52; edited 1 time in total |
|||
![]() |
|
bubach 22 Feb 2007, 18:08
It's 5kb, who cares about compressing more? ZIP can be opened on most platforms without downloading anything.
|
|||
![]() |
|
rugxulo 22 Feb 2007, 18:51
bubach, it's 5k because he put a .tar in the .ZIP itself, which currently needs both an unzipper (inflater) and an untar program to extract individual files from the embedded .tar file. In other words, why archive with .tar and compess with .ZIP when .ZIP does both archiving and compressing? (Like I said, not everyone already has or uses both tar and zip).
|
|||
![]() |
|
rugxulo 23 Feb 2007, 21:17
Suggestion about the code? Well, the only one I have is: change the DOS stub to say "Get HXRT at http://www.japheth.de if Win32 ain't available!". (At least they'd know where to get it from.)
Sorry, I don't mess with PEs much, so I can't really help much regarding that. ![]() BTW, here's what I was suggesting (in case it wasn't obvious, although you can do it your way if you really wanted, but why?): Code: [ WinXP ] Fri 02/23/2007>av /l! fasmmzpe.zip FASMMZPE.ZIP mzpe.zip 5,929 (29,732) Feb,22,2007 12:23:36p [Deflat] [ WinXP ] Fri 02/23/2007>v /z;lv fasmmzpe.zip fasmmzpe zip 6,043 Feb,22,2007 12:23:36pm A... [ WinXP ] Fri 02/23/2007>scrndump |
|||
![]() |
|
TheRaven 24 Apr 2008, 02:56
Zip-Genius.
Freeware utility suite, Italian design by nature, awesome by all virtue. Handles: .tar, .rar, .zip, .gz styles, 7zip, and too many others from one interface. AWESOME! I wouldn't be caught dead without it. _________________ Nothing so sought and avoided more than the truth. I'm not insane, I know the voices in my head aren't real! |
|||
![]() |
|
daniel.lewis 30 Apr 2008, 07:01
7-zip is good enough for me.
PS: I'll have to take a look at your program when I get home, or if things get busy, this weekend. Thanks for sharing. |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.