flat assembler
Message board for the users of flat assembler.
Index
> DOS > Art Of Assembly |
Author |
|
emu1 29 Jul 2010, 19:14
Hello, I'm learning assembly from the Art of Assembly online, I've chosen to use the FASM compiler..however from time to time there are some things from Art of Assembly I have trouble translating to fasm syntax. For example I'm trying to code a dos TSR key counter
http://www.arl.wustl.edu/~lockwood/class/cs306/books/artofasm/Chapter_18/CH18-1.html#top The obvious problem is all resident code and variables are supposed to be in one segment and you need to know how large that segment is for the INT 31h paragraph count. I can't find any FASM directives for resident segment definition..would Code: push ds push cs pop ds be sufficient to place the program variables in code segment?(I seem to recall reading in manual that no matter where you declare variables they are placed at end of code by compiler?) The other problem is figuring out how large the resident segment code is..would code subtracting $-$$ and placing value into ax be accurate? |
|||
29 Jul 2010, 19:14 |
|
vid 29 Jul 2010, 20:00
To make multi-segment program in FASM, you need to produce MZ file format (.EXE), not just "org 100h" (which defaults to .COM format). .COM is single-segment, .EXE is multi-segment.
However, for TSR it is enough to use .COM, and place all the stuff which has to resident at the beginning of segment, and then only leave that resident. http://flatassembler.net/docs.php?article=manual#2.4.1 |
|||
29 Jul 2010, 20:00 |
|
edfed 29 Jul 2010, 22:19
the executable format is not dependant of the compiler, it depends of the OS where it will run.
for .COM, it is used to start with ORG 100h for .EXE, it is used to strat with FORMAT MZ, PE GUI, PE CONSOLE, etc for linux, it is an other way for menuet, it starts with a menuet header... and so on. just think about WHERE the program is IN RAM, and where point CS:EIP. .COM starts with CS=??? and (E)IP = 100h some OS brings the possibility to make abstraction of this. .EXE is a mecanism like that. let's enjoy the asm coding now. |
|||
29 Jul 2010, 22:19 |
|
revolution 30 Jul 2010, 01:58
emu1 wrote: If I compile a program with Code: format binary ;<--- this is the default org 100h use16 ;... |
|||
30 Jul 2010, 01:58 |
|
DOS386 30 Jul 2010, 04:28
> I can't find any FASM directives for resident segment definition
There is none. > To make multi-segment program in FASM, you need to produce MZ file format (.EXE) Right. > not just "org 100h" (which defaults to .COM format). NO. FASM defaults "format binary" , "org 100h" doesn't default to anything. > COM is single-segment, .EXE is multi-segment. Not exactly. COM is always single-segment, EXE can be multi-segment but also single-segment. > However, for TSR it is enough to use .COM, and place all the stuff > which has to resident at the beginning of segment, and then > only leave that resident. Right. You can throw away the init code before going resident, or you can keep it (YES, this wastes memory). See here for a simple FASM TSR: http://board.flatassembler.net/topic.php?t=9256 > ORG 100h > USE16 > as 'fasm program.asm program.exe' Don't do this - this brews a missnamed COM > the executable format is not dependant of the compiler, > it depends of the OS where it will run. NO. Brewn format depends from the source code only in FASM. > for .COM, it is used to start with ORG 100h You can write "format binary as "COM" ... but maybe FASM will forgive if you don't ... > for .EXE, it is used to strat with FORMAT MZ, PE GUI, PE CONSOLE, etc Make sure to pick a format suitable for your OS: MZ : DOS, can be 8086-compatible PE : Win32, or DOS, but needs DOS extender and 80386 > .COM starts with CS=??? and (E)IP = 100h COM runs always in real mode, there is no EIP, and you have unbreakable 64 KiB segment limit. > let's enjoy the asm coding now. Right FYI, programming with FASM is easier than with MASM (as you usually can simply throw away all the segment/assume/code-vs-data/... stuff). You can't link 16-bit FASM with HLL code (as FASM doesn't support OMF), and you need segments (or some other hack) only for > 64 KiB of bloat. EDIT : fixed BUG pointed below Last edited by DOS386 on 30 Jul 2010, 04:51; edited 1 time in total |
|||
30 Jul 2010, 04:28 |
|
Tyler 30 Jul 2010, 04:45
> You can't link with HLL code
Wha' da ya mean? My trampoline is assembled by fasm(format elf) and linked by ld into my "kernel"(Not really a kernel, just a bunch of code that happens to be bootable.). Everything else is in C. |
|||
30 Jul 2010, 04:45 |
|
DOS386 30 Jul 2010, 04:51
> You can't link with HLL code
> Wha' da ya mean? 16-bit code. |
|||
30 Jul 2010, 04:51 |
|
vid 30 Jul 2010, 11:22
Quote: If I compile a program with Yes, file will have .exe extension, but it will be in a ".COM format" and when you execute, it will be executed as such when you run it. Quote: because of my org 100h COM format is in fact pure binary format, which is loaded at offset 100h (hence the "org 100h"). Quote: or is it necessary to 'fasm program.asm program.com' to get the single segment .com format? No no, as revolution said, contents of resulting file depend entirely on contents of source, not on command line. Also when DOS executes file, it doesn't care about extension. It looks into the file, if it startz with ascii "MZ" characters, it is executed as EXE format, otherwise it is treated as COM format. |
|||
30 Jul 2010, 11:22 |
|
emu1 30 Jul 2010, 20:55
Thanks for all the great infos!
|
|||
30 Jul 2010, 20:55 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.