flat assembler
Message board for the users of flat assembler.
Index
> DOS > Pls help me to convert the following code to FASM |
Author |
|
scientica 05 Sep 2003, 04:51
I'm soon of to schools so I'll just (try to) explain the org directive.
In short it sets the address origin (where it begins) to the number after it, for instance: Code: label1: org 100h label2: label1 has the address/offset 0, where as label 2 has the address/offset 100h. Org is used mostly in .COM files (org 100h), and boot loaders (org 7500h, iirc) Sorry if my explanation is too short, I hope you at least. _________________ ... a professor saying: "use this proprietary software to learn computer science" is the same as English professor handing you a copy of Shakespeare and saying: "use this book to learn Shakespeare without opening the book itself. - Bradley Kuhn |
|||
05 Sep 2003, 04:51 |
|
prana 05 Sep 2003, 05:17
Thanks Scientica.
My original intention was to ask how to manage those two ORG s in the code. Neither NASM nor FASM supports this kind of organisation. A restructuring of that code would be more helpful. Thanks. |
|||
05 Sep 2003, 05:17 |
|
Tomasz Grysztar 05 Sep 2003, 09:34
For such purpose you should use "virtual", not "org".
Also, as you probably want to make .com file (as you are using "org 100h" and "int 20h" to exit), you should use MZ format for it. Here's how this whole program should be written for FASM: Code: label rom_bios_data at 40h virtual at 1Ah head dw ? tail dw ? buffer rw 16 label buffer_end word end virtual org 100h mov bx,rom_bios_data mov ds,bx get_char: mov bx,[head] cmp bx,[tail] je get_char mov dx,[bx] mov [tail],bx cmp dl,'q' je bye cmp dl,'Q' je bye mov ah,2 int 21h jmp get_char bye: int 20h |
|||
05 Sep 2003, 09:34 |
|
prana 05 Sep 2003, 10:37
Great!
Just one more question for now, does FASM uses proc/endp directives, or r they macros? If so, when their use is advisable. Also could you throw some light on segment? Does it use nasm style segment name use16/use32 etc? I know you are very busy and also writing a tutorial for us but knowing these small details would help me a lot to get started. Thanks. |
|||
05 Sep 2003, 10:37 |
|
Tomasz Grysztar 05 Sep 2003, 10:48
proc/endp are macros, and for DOS programming I would not recommend using them at all, unless you need to operate with some HLL routines.
segment directive is valid for MZ format only, and it labels a segment in the memory block of your program, other segments can be defined just as a labels, absolute or relative to your segments. For example, here's how you can make MZ program, which works the same way as standard .com (with PSP being common segment for all, so you have to use "org 100h" and can exit with "int 20h"): Code: format MZ entry PSP:100h segment main use16 PSP = main - 10h org 100h mov ah,9 mov dx,_message int 21h int 20h _message db '.com emulated with MZ format',24h More examples of MZ programs you can find in the DOS distrubution of fasm. Last edited by Tomasz Grysztar on 05 Sep 2003, 11:06; edited 1 time in total |
|||
05 Sep 2003, 10:48 |
|
prana 05 Sep 2003, 11:02
Ok, so here PSP is the label at 100h, but why it is equal to main-10h?
Another thing is when I compile the first example without a format MZ the resulting com size is 39bytes, but when compiled with format MZ the size is 71 bytes. Why so? Can I avoid writing the format directive in my program like this? Thanks. |
|||
05 Sep 2003, 11:02 |
|
Tomasz Grysztar 05 Sep 2003, 11:05
.com files are simple binary programs, while MZ programs have special headers, defining more settings for program, so you can use more segments, define entry point, stack, etc.
For programs that don't need more that 64 kilobytes of memory, binary format is enough. |
|||
05 Sep 2003, 11:05 |
|
prana 05 Sep 2003, 11:14
Ok, thanks.
|
|||
05 Sep 2003, 11:14 |
|
prana 05 Sep 2003, 12:45
Privalov, is the following a valid COFF format file under FASM?
Code: format COFF public _start section '.data' hello db 'Hello world!',24h section '.code' _start: mov ah,9 mov dx,word ptr hello int 21h mov ah,1ch int 21h ret Though it compiled and linked, I see no output I must be doing something wrong, what's that? And how in general a COFF template should look like. I also didn't yet understand the placement of Prog Seg Prefix in your last post. Could u pls help? |
|||
05 Sep 2003, 12:45 |
|
Tomasz Grysztar 05 Sep 2003, 12:53
What linker are you using? COFF format is designed for the flat protected mode programs, and is not very usable for 16-bit DOS programming.
"mov dx,word ptr hello" is definitely wrong here, as it is the same as "mov dx,word [hello]". Use "mov edx,hello" instead |
|||
05 Sep 2003, 12:53 |
|
prana 05 Sep 2003, 13:03
I am using LINK. I changed the mov dx, word ptr hello to mov edx, hello, but somehow confused btw the two. A little explanation would be good. Also nothing gets printed. I want to know that whether the segment directives are ok here.
And in a previous example you showed something segment main use16 PSP = main - 10h What purpose it solved? Could u explain a bit. Thanks. |
|||
05 Sep 2003, 13:03 |
|
Tomasz Grysztar 05 Sep 2003, 13:35
LINK of what package? What kind of executables it creates?
And for your second question - when your program is loaded into memory, it is preceded by the so-called Program Segment Prefix (PSP in short), which is 100h bytes in size. Then the data of your program follows. In case of simple binary program everything is located in one segment, so PSP is at address 0 in that segment, and your program just after it, at address 100h - that's why you have to use "org 100h" there. In case of MZ programs, you can have multiple segments, and your first segment is defined to be the segment just after the PSP. As the number of segment is the count of paragraphs from the beginning of memory, and one paragraph is 10h bytes, the difference of 100h bytes in addresses is difference of 10h in paragraphs, so to get your PSP segment number, you have to substract 10h from the number of first segment of your code. Also, for all DOS programs DS is initially set to the number of PSP segment, so you can just put the "org 100h" at the beginning of your first segment and do everything the same way as in case of .com program. The entry point is defined in the PSP segment, too - so CS is also equal to it, and you can use "int 20h" function (which needs your CS to be the number of your PSP segment). |
|||
05 Sep 2003, 13:35 |
|
prana 05 Sep 2003, 13:41
Thanks a lot for the explanation Privalov. I worked earlier with PSP, but forgot many details now.
Thanks again for your time. And for your other question, I'm using the LINK comes with VC. |
|||
05 Sep 2003, 13:41 |
|
Tomasz Grysztar 05 Sep 2003, 13:45
So it generates Win32 programs, not DOS ones - that's why interrupt functions are not working for you. But there are also some linkers, that can link COFF into programs for protected mode DOS with extenders.
|
|||
05 Sep 2003, 13:45 |
|
prana 05 Sep 2003, 13:50
Ok! I have alink, should I try that one? I compiled some program long ago with it int 33h I believe, forgot a lot though.
|
|||
05 Sep 2003, 13:50 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.