gcc and 16bits code
Posted: Thu Mar 03, 2005 12:00 am
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??
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.__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.
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?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
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.Hery Sasta wrote:so, the best is to use compiler, which make normal 16 bits code?? (like turbo c)
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.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.