🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: rec.games.programmer
Article #506

Re: need help with assembly code, etc.

#506
From: Khan
Date: Wed, 05 Aug 1992 13:51
72 lines
3670 bytes
In article <1992Aug4.214421.5075@esds.mdc.com> bonney@esds.mdc.com (Greg Bonney) writes:
>M. Abrash's assembly code for doing fixed-point multiplies contains the
>following lines:
>
>	mov	eax,[bp+M1]
>	imul	dword ptr [bp+M2] ;multiply
>	add	eax,8000h	;round by adding 2^(-16)
>	adc	edx,0		;whole part of result is in DX
>	shr	eax,16		;put the fractional part in AX
>
>Okay, the first line puts the argument M1 into eax (a 32 bit register),
>the second line multiplies M2 by what's in eax.  Now, where does the result
>of the imul end up?

The clues are right there in the code:

The high order dword (integer part) ends up in edx, the low order dword
(fractional part) in eax.

>How does the adc (add with carry) work?

The add eax,8000h instruction may or may not set the carry flag,
depending on the result of the addition. The adc (add with carry)
instruction says to add 0 plus the value of the carry flag (0 or 1) to
the quantity in edx, which happens to be the high order dword. Thus, it
adds the carry bit into the high order dword of the product.

>Is the final result in eax?

Yes, after the shift, the 16 bit integer part is in the upper word, and
the 16 bit fractional part is in the lower word, just as it should be.

>Okay, now that we've got that out of the way, I've noticed that the Turbo C++
>BASM (built-in assembler) doesn't support 386 instructions, but I don't have
>TASM (Turbo Assembler).  I've noticed there are some public-domain assemblers
>(one called A86).  Do any of them support 386?

Not that I know of. You know, Turbo Assembler is pretty darned cheap.
Why not just go out and buy it? It handles all the instruction sets,
interfaces to any other Borland compiler with no problem, and includes
the fabulous Turbo Debugger, which will be of immense help if you're
developing any sort of graphics applications. It includes a quick
reference manual, which gives a synopsis of every instruction (including
the IMUL you asked about).

If you're really destitute, you can always buy a used copy or an older
version. TA is up to 3.0, which means there are probably copies of 1.0 and
2.0 floating around unneeded by their owners. As a matter of fact, I have a
copy of Turbo Assember and Debugger 1.0 which I no longer need (I bought
BC++&AF, which comes with version 3.0 of TA). I'll let you have it dirt
cheap. Email me.

>Will any of them link with
>Turbo C++?  (I've heard that Borland and Microsoft object files are
>incompatible.)

That's not true. You can use Microsoft's Macro Assembler to generate OBJ
files which link just fine with Turbo C++ OBJ files, using either
Borland's or Microsoft's linker.

>Finally, could this be implemented reasonably in C++ instead of Assembly?
>How much speed would you lose?

You would lose a great deal of speed. You're better off getting the
assembler. It's not like you're only going to use the assembler for this
ONE THING and then it will collect dust. You'll use it all the time.
As high-performance graphics programming tool investments go, it's one of the
best you can buy.

No, I don't work for Borland, nor do I represent the Assembly Hackers of
America (AHA!).
Technical Details
Message-ID: <BsIJtF.8L1@news.cso.uiuc.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!sun-barr!ames!elroy.jpl.nasa.gov!sdd.hp.com!ux1.cso.uiuc.edu!news.cso.uiuc.edu!usenet
References: <1992Aug4.214421.5075@esds.mdc.com>

Show Full Headers
Complete Article Headers
Newsgroups: rec.games.programmer
Path: arc1-ca.pugleaf.net!sparky!uunet!sun-barr!ames!elroy.jpl.nasa.gov!sdd.hp.com!ux1.cso.uiuc.edu!news.cso.uiuc.edu!usenet
From: tmkk@uiuc.edu (Khan)
Subject: Re: need help with assembly code, etc.
References: <1992Aug4.214421.5075@esds.mdc.com> 
Message-ID: <BsIJtF.8L1@news.cso.uiuc.edu>
Sender: usenet@news.cso.uiuc.edu (Net Noise owner)
Organization: University of Illinois at Urbana
Date: Wed, 5 Aug 1992 13:51:14 GMT
Lines: 73