flat assembler
Message board for the users of flat assembler.
Index
> Compiler Internals > directive org |
Author |
|
beppe85 05 Feb 2005, 21:13
Endre wrote: The code below does however not want to compile correctly. Fasm ignores the org directive. I'll try to explain. Reaching a org directive, FASM will assembly addresses from that place on taking the new origin as base. It will not physically put padding. See a template: Code: org 0x7c00 origin: ; any bootloader codes rb $ + $200 - origin - 2 dw 0xaa55 ; boot signature _________________ "I assemble, therefore I am" If you got some spare time, visit my blog: http://www.beppe.theblog.com.br/ and sign my guestmap |
|||
05 Feb 2005, 21:13 |
|
Endre 05 Feb 2005, 22:17
beppe85 wrote:
Yes, I know, and with this we can reach the following inconvenient behavior (sorry for the stupid example): Code: ... cmp word [qqq], 0xaa55 ... org 0x7dfe qqq: dw 0xaa55 That compiles to Code: ... cmp word [0x7dfe], 0xaa55 ; from here on you already lost ... One sentence from fasm.txt: Quote: "org" directive sets address at which the following code is expected to appear in memory. |
|||
05 Feb 2005, 22:17 |
|
beppe85 05 Feb 2005, 22:29
From "expected to appear" you can presume that is not FASM responsibility put put your code/data there, but some other thing, be it BIOS, CPU or yourself. In a bootloader you usually put a rb just before dw $aa55.
Endre wrote: The code below does however not want to compile correctly. So what exactly you want? _________________ "I assemble, therefore I am" If you got some spare time, visit my blog: http://www.beppe.theblog.com.br/ and sign my guestmap |
|||
05 Feb 2005, 22:29 |
|
Endre 06 Feb 2005, 10:52
beppe85 wrote: From "expected to appear" you can presume that is not FASM responsibility put put your code/data there, but some other thing, be it BIOS, CPU or yourself. In a bootloader you usually put a rb just before dw. |
|||
06 Feb 2005, 10:52 |
|
Tomasz Grysztar 06 Feb 2005, 12:11
If the org worked like you want, the initial "org 0x7c00" would put 7C00h zero bytes at the beginning of your file (because binary file always starts at offset 0) and "org 100h" used when you want to make .com file would put the 100h zero bytes there - of course making the file unusable in both those case - because this is operating system who loads the codes at these addresses - with "org" directive you just tell the assembler where in memory the following piece of code will be loaded.
You use "org" more than once in your code, when you write a code that will have different parts loaded in different memory areas - but it's your responsibility to put the generated code in the place for which you have designed it. This is what the "org" directive tells: "the following code is designed to work in this place of memory". |
|||
06 Feb 2005, 12:11 |
|
Endre 06 Feb 2005, 12:41
Yes, that's why I use the next macro, which does I expect from built in org to do. Rather unelegant...
Code: macro org addr { if $ = 0 org addr else if addr >= $ rb addr - $ else display "origin error", 0xd, 0xa end if } |
|||
06 Feb 2005, 12:41 |
|
Tomasz Grysztar 06 Feb 2005, 16:37
Why unelegant? It's pretty nice example of adapting fasm's syntax for your needs. Even though those needs are inconsequent.
|
|||
06 Feb 2005, 16:37 |
|
Endre 06 Feb 2005, 17:20
Privalov wrote: Even though those needs are inconsequent. My needs were never consequent It's enough to me keeping thoughts consequent. Sometimes even unsuccessfuly... |
|||
06 Feb 2005, 17:20 |
|
beppe85 06 Feb 2005, 20:14
Endre wrote: Yes, that's why I use the next macro, which does I expect from built in org to do. How would your bootsector fit in a 512B sector, if it contains at beginning 0x7c00 zeros? A BIOS would contain almost 64KB of unneeded stuff... And your macro shows clearly that this org as you think, is totally redundant. _________________ "I assemble, therefore I am" If you got some spare time, visit my blog: http://www.beppe.theblog.com.br/ and sign my guestmap |
|||
06 Feb 2005, 20:14 |
|
Endre 07 Feb 2005, 09:58
beppe85 wrote: How would your bootsector fit in a 512B sector, if it contains at beginning 0x7c00 zeros? A BIOS would contain almost 64KB of unneeded stuff... Binary format starts from zero that is the condition $ = 0 is true so the next line, the built in org directive is achieved. When you use org again (i.e. $ >= 0) then the second condition is fulfilled and the 'rb addr - $' is carried out. Ok? |
|||
07 Feb 2005, 09:58 |
|
beppe85 07 Feb 2005, 10:20
Endre wrote: Binary format starts from zero that is the condition $ = 0 is true so the next line, the built in org directive is achieved. When you use org again (i.e. $ >= 0) then the second condition is fulfilled and the 'rb addr - $' is carried out. Ok? Ok. But redundant if were to be the original meaning of org, and subtracting a feature of FASM. Ok? I'm not questioning your macro, but that as the default way. How could you get "org $ - some_unsigned_immediate_value"? At least, the first condition should be "$ = 0 or addr <= $", but if you try to go back and forth, you may cause a chaos. And you think going back is an error... _________________ "I assemble, therefore I am" If you got some spare time, visit my blog: http://www.beppe.theblog.com.br/ and sign my guestmap |
|||
07 Feb 2005, 10:20 |
|
Endre 07 Feb 2005, 10:45
You ain't an assembly practitioner, are you?
|
|||
07 Feb 2005, 10:45 |
|
beppe85 07 Feb 2005, 11:12
No. Not as you.
|
|||
07 Feb 2005, 11:12 |
|
Octavio 08 Feb 2005, 18:19
Code: org 7c00h ;boot code align 7c00h+510 dw 0xaa55 I think that newer versions of fasm only acept powers of two as align parameters ,but it shoud work with the align macro used on the firsts versions. |
|||
08 Feb 2005, 18:19 |
|
Endre 09 Feb 2005, 06:58
My path was the org directive and yours is the align one. All the same. I guess other people would use fully other solutions. The only argument I chose org is, that I had formerly used AS (gnu assembler) which handles org directive as I expected fasm to do it the same way, the way I tried to emulate with my macro.
|
|||
09 Feb 2005, 06:58 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.