From: Leath Muller Message-Id: <199607230018.KAA25409@gbrmpa.gov.au> Subject: Re: Inline assembly and DMA transfers. To: luke AT jaglogic DOT demon DOT co DOT uk (Luke Steele) Date: Tue, 23 Jul 1996 10:18:40 +1000 (EST) Cc: djgpp AT delorie DOT com In-Reply-To: from "Luke Steele" at Jul 22, 96 05:07:19 pm Content-Type: text > Hi, > I'm planning to write some code that will require inline assembly. > However, I have been unable to work out how to do this - specifically, > how do I indicate to the compiler that the code is assembly, in the > way that the 'asm' statement does in Borland C? I've read the FAQ in > some detail, and the online documentation as well, but these only > illustrate the syntax of the assembly, and not how to place it inline > with the C code. Actually, you would be suprised to know just how easy it is...one thing tho, get used to global variables... :) Basically, I learnt two simple rules to using inline which seem to simplify the whole process: 1) Use global variables. This allows easy access to C variables from your code. It may not be what they teach at uni, etc, but it is required to access C vars from asm easily... 2) Do your own pushing and popping. I dont think a lot of people will agree with this one - anybody? eg: include volatile char *mem_block = NULL; volatile int value = 0; void fill_block() { asm volatile (" pushl %eax; pushl %ebx; pushl %ecx; movl $50, %ecx; movl _value, %ebx; movl _mem_block, %eax; loop: movl %ebx, (%eax); addl $4, %eax; decl %ecx; cmpl $0, %ecx; jnz loop; popl %ecx; popl %ebx; popl %eax; "); } int main(void) { mem_block = (char *)malloc(200); value = 0; // not really needed fill_block(); free(mem_block); } this code (should) fill the 200 bytes at mem_block with zeros... Any comments on this code? :) I would like any comments/suggestions too, as this is how I am doing most of my coding...it eliminates the need for the destroyed/returned etc register bits at the end of the routine. If I intend to return a value, I have been manually putting into eax at the end of the routine... Actually, you could even do something like this in the main routine: int main(void) { mem_block = (char *)malloc(200); asm volatile (" movl $0, _value; "); fill_block(); free(mem_block); } > Also, I'm planning to do a DMA transfer. I've performed DMA transfers > in real mode before with no problem, but are there any special > considerations when making a transfer in protected mode? > Any help is appreciated. Thanks! Hmmm...havent played with this yet... :) Leathal.