Page 1 of 1

gcc and 16bits code

Posted: Thu Mar 03, 2005 12:00 am
by Hery
when i try to link my system i had got problems. after reading articles i know that my code must be 16 bits how i can make 16bits code in gcc?? is it possible??

Re: gcc and 16bits code

Posted: Thu Mar 03, 2005 12:00 am
by __matt__
Use the assembler directives .code16 and .code32 to specify whether you want the assembler to generate 16- or 32-bit code. Read the `as' man and info pages for more info.

Re: gcc and 16bits code

Posted: Fri Mar 04, 2005 12:00 am
by rexlunae
__matt__ wrote:Use the assembler directives .code16 and .code32 to specify whether you want the assembler to generate 16- or 32-bit code. Read the `as' man and info pages for more info.
More useful for using gcc to make 16-bit code, and also more obscure, is the <i>as</i> directive .code16gcc, which specifically tells the assembler that you want to assemble gcc-produced code. I think the main difference is that it overrides the jump addresses to be 32-bit. This will work much better than just .code16.

One more thing...
Code produced by gcc is never truely 16-bit. It is made to run in 16-bit segments by inserting overrides. So, the code produced will run in real mode, and in a 16-bit protected mode segment, but not on a 286.

Re: gcc and 16bits code

Posted: Thu Mar 10, 2005 12:00 am
by Hery
ok, thanks :D

Re: gcc and 16bits code

Posted: Fri Mar 11, 2005 12:00 am
by Hery
i've got next problem :/ i write on the begin __asm__(".code16"); everthing is ok, but when i try to compile i've got problems, i know why, as get commcands like mov eax, 01h (example) but it must be 16 bits

Re: gcc and 16bits code

Posted: Fri Mar 11, 2005 12:00 am
by rexlunae
Hery Sasta wrote:i've got next problem :/ i write on the begin __asm__(".code16"); everthing is ok, but when i try to compile i've got problems, i know why, as get commcands like mov eax, 01h (example) but it must be 16 bits
The .code16 and .code16gcc directives (you really should be using .code16gcc for assmebly generated by gcc btw) do not generate 16-bit code. It generates code that will run correctly in a 16-bit segment with 32-bit processors. This means that when a 32-bit opperation is requested, it will insert the appropriate override to make it work correctly. So, your problem is probably not related to the use of eax instead of ax. I am wondering, based on your example, why you have Intel syntax? Perhaps you could detail the procedure you are using to compile and link complete with all commands?

Re: gcc and 16bits code

Posted: Sat Mar 12, 2005 12:00 am
by Hery
oh, now everything is ok, but i've got new question, does it "16" bit code run in Real Mode??

Re: gcc and 16bits code

Posted: Sat Mar 12, 2005 12:00 am
by Legend
I would guess not really - at best limited to 64kb for code and 64kb for data, as gcc doesn't know about segmentation.

Re: gcc and 16bits code

Posted: Sat Mar 12, 2005 12:00 am
by Hery
so, the best is to use compiler, which make normal 16 bits code?? (like turbo c)

Re: gcc and 16bits code

Posted: Sat Mar 12, 2005 12:00 am
by rexlunae
Hery Sasta wrote:so, the best is to use compiler, which make normal 16 bits code?? (like turbo c)
Your code should run in real mode, but as was mentioned, gcc is unaware of segmentation registers. That does not mean that you cannot use it, but you may need to do strange things to access more than 64KB of memory. I would avoid using compilers that support segmentation, because it is non-standard C.

Re: gcc and 16bits code

Posted: Sun Mar 13, 2005 12:00 am
by Legend
Working directly with segments (like Microsoft C 6.0 compilers allowed for example (not C++ 6.0 !) )
is not C standard.
If the compiler does this implictily (for example large memory models), then it is no problem.

Re: gcc and 16bits code

Posted: Sun Mar 13, 2005 12:00 am
by rexlunae
Legend wrote:Working directly with segments (like Microsoft C 6.0 compilers allowed for example (not C++ 6.0 !) )
is not C standard.
If the compiler does this implictily (for example large memory models), then it is no problem.
I guess the idea of the compiler implicitly handling segmentation registers has always bothered me, because it makes some of your pointers 48-bit, but it could work for some people is suppose.