Mail Archives: djgpp/1996/02/24/06:23:40
Carrot <st2edea AT doc DOT ntu DOT ac DOT uk> writes:
>Here's an example of the problem I'm getting...
>
>int DOS_SEG;
>
>
>void Clear_VGA()
> {
> DOS_SEG=_go32_conventional_mem_selector();
> ASM_LENGTH=16000;
>
> asm("
> pushw %es
> movw _DOS_SEG,%es
> movl $0xA0000,%edi
> movw $0,%eax
> movw _ASM_LENGTH,%cx
> rep
> stosl
> pop %es
> ")
> }
>
Someone else has already posted what may be a better way of doing this,
but since you wanted to improve your assembly language skills I'll
concentrate on the code snippet above. Firstly, you're not telling DJGPP
which registers you're clobbering, which will cause problems. Secondly,
you are assuming that the top words of %eax and %ecx are zero, which is
not necessarily true. Note that rep stosl fills %ecx dwords with the
value in %eax. If, before your code starts, %eax=0xFFFFFFFF and
%ecx=0x10000000, then your code fills 0x10003E80 dwords with 0xFFFF0000,
which will give you a seg fault pretty quickly :).
In general, avoid using 16-bit instructions and operands, particularly
for code that will be running on a Pentium. A 16-bit MOV on a Pentium ca
take up to 4 times longer than a 32-bit one, which is a pretty
significant time penalty :). This is because a 16-bit instruction needs
to be signaled by a prefix byte, which takes up 1 full cycls, must
execute in the U-pipe, and can't pair.
For the same reason, avoid using shorts in your C code if at all
possible.
--
Mark Mackey Beam the offer. Two for a
Trinity Hall, Cambridge. cootie-coated Lathian and
http://www.ch.cam.ac.uk/MMRG/mdm.html his Willie Terwilliger.
- Raw text -