www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/02/24/06:23:40

Xref: news2.mv.net comp.os.msdos.djgpp:1381
From: mdm1004 AT cus DOT cam DOT ac DOT uk (M.D. Mackey)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Why the crash ?
Date: 21 Feb 1996 13:37:15 GMT
Organization: University of Cambridge, England
Lines: 49
Message-ID: <4gf76b$q4q@lyra.csx.cam.ac.uk>
References: <Pine DOT SUN DOT 3 DOT 91 DOT 960220095423 DOT 24086A AT chris>
NNTP-Posting-Host: ursa.cus.cam.ac.uk
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019