[alt.lang.asm] Need help in porting 8088/286 assembly code to 386.

jdm@kofax.uucp (James D. Murray) (06/21/91)

    I am looking for any books/magazine articles that could help me in
realizing the changes that must be made to 8086/80286 assembly code
to make it 80386-only.  I am porting some assembly code from DOS and
Windows to SCO Unix on a 386 machine and I need to optimize it for
386-only operation.

	I'm told that I need to do away with the lds and les instructions
and rewrite code that considers the segement in address calculations.  I am
not an Intel assembly programmer and any printed information on this specific
problem would be very helpful.

Thanks
-- 

-----

/*

timur@seas.gwu.edu (The Time Traveler) (06/23/91)

In article <1991Jun21.161443.13880@kofax.uucp> jdm@kofax.uucp (James D. Murray) writes:
>
>    I am looking for any books/magazine articles that could help me in
>realizing the changes that must be made to 8086/80286 assembly code
>to make it 80386-only.  I am porting some assembly code from DOS and
>Windows to SCO Unix on a 386 machine and I need to optimize it for
>386-only operation.
>

The God of optimized 80x86 assembly is Michael Abrash, and he has one book
out (Zen of Assembly) that is very useful.  There's a second volume coming.
He has articles on graphics programming in Programmer's Journal.  Basically,
he specializes in optimized assembly with a concentration in graphics.

80286 code would probably be an easy conversion - 8088 code wouldn't.  
Why not?  Because coding for 386 Unix means protected mode assembly,
and that's very different real mode.  Granted, the operating system takes
care of most of the stuff, but assembly programming always means you
have to do most of the work yourself.

----------------------------------------------------------- The Time Traveler
Let me take you far away                                    a.k.a. Timur Tabi
You'd like a holiday                             Internet: timur@seas.gwu.edu
Exchange the cold days for the sun              Bitnet:          HE891C@GWUVM
The good times ... and fun         -- Scorpions (awesome concert 5/10/91!)

suitti@ima.isc.com (Stephen Uitti) (06/24/91)

In article <1991Jun21.161443.13880@kofax.uucp> jdm@kofax.uucp (James D. Murray) writes:
>
>    I am looking for any books/magazine articles that could help me in
>realizing the changes that must be made to 8086/80286 assembly code
>to make it 80386-only.  I am porting some assembly code from DOS and
>Windows to SCO Unix on a 386 machine and I need to optimize it for
>386-only operation.
>
>	I'm told that I need to do away with the lds and les instructions
>and rewrite code that considers the segement in address calculations.  I am
>not an Intel assembly programmer and any printed information on this specific
>problem would be very helpful.

The March 1991 Dr. Dobbs has an article explaining this with some detail.

My guess is that if the code ran on an 8088, it should run
reasonably quickly on a '386 without changes.  The 386/25 on my
desk runs 20 times faster than my 8088/4.77 at home.  Can an
additional 10%-50% going to buy anyone anything?

Stephen.
suitti@ima.isc.com
"We Americans want peace, and it is now evident that we must be
prepared to demand it.  For other peoples have wanted peace, and
the peace they received was the peace of death." - the Most Rev.
Francis J. Spellman, Archbishop of New York.  22 September, 1940

peter@ficc.ferranti.com (Peter da Silva) (06/25/91)

In article <1991Jun24.160828.6047@ima.isc.com> suitti@ima.isc.com (Stephen Uitti) writes:
> In article <1991Jun21.161443.13880@kofax.uucp> jdm@kofax.uucp (James D. Murray) writes:
> >realizing the changes that must be made to 8086/80286 assembly code
> >to make it 80386-only.
> >	I'm told that I need to do away with the lds and les instructions
> >and rewrite code that considers the segement in address calculations.

> My guess is that if the code ran on an 8088, it should run
> reasonably quickly on a '386 without changes.  The 386/25 on my
> desk runs 20 times faster than my 8088/4.77 at home.  Can an
> additional 10%-50% going to buy anyone anything?

Well, if the code uses segments extensively you can expect as much as a
factor of 10 slowdown because of the extra costs involved in doing
segment calculations. We have code here that runs slower on the 386
than on the 286 because of this.
-- 
Peter da Silva; Ferranti International Controls Corporation; +1 713 274 5180;
Sugar Land, TX  77487-5012;         `-_-' "Have you hugged your wolf, today?"

grs@cocam.oz.au (Gary Raymond Schmidt) (06/26/91)

In article <N_4C5L7@xds13.ferranti.com> peter@ficc.ferranti.com (Peter da Silva) writes:
>In article <1991Jun24.160828.6047@ima.isc.com> suitti@ima.isc.com (Stephen Uitti) writes:
>> In article <1991Jun21.161443.13880@kofax.uucp> jdm@kofax.uucp (James D. Murray) writes:
	[ ... much stuff deleted ... ]

Minor point - if he's porting to a Unix box, the only model available
to him is the _flat_ 32-bit model.  If he modifies the segment
registers on the '386, his code will crash with a resounding thud,
taking the machine with it.

The Operating System, being an O/S, not a glorified program loader
such as MesSy-DOS, handles _all_ memory protection considerations.

The safest, and easiest way to port to a '386 is to ignore the
segments and treat it as a pure 32-bit machine, a la M68000, and
re-code the assembler stuff from scratch, or better yet, re-write it
in C.

-- 

| Gary R. Schmidt         ||   MHSnet: grs@cocam.oz.au
|                         ||   or: grs%cocamrd@cocam.oz.au
| Co-Cam Computer Group,  ||   I sees it, but I don' believes it !!
| Melbourne, OZ           ||   VOX +61 3 412 3431   FAX +61 3 417 7857

dana@locus.com (Dana H. Myers) (06/28/91)

In article <N_4C5L7@xds13.ferranti.com> peter@ficc.ferranti.com (Peter da Silva) writes:
>In article <1991Jun24.160828.6047@ima.isc.com> suitti@ima.isc.com (Stephen Uitti) writes:
>> In article <1991Jun21.161443.13880@kofax.uucp> jdm@kofax.uucp (James D. Murray) writes:
>> >realizing the changes that must be made to 8086/80286 assembly code
>> >to make it 80386-only.
>> >	I'm told that I need to do away with the lds and les instructions
>> >and rewrite code that considers the segement in address calculations.
>
>> My guess is that if the code ran on an 8088, it should run
>> reasonably quickly on a '386 without changes.  The 386/25 on my
>> desk runs 20 times faster than my 8088/4.77 at home.  Can an
>> additional 10%-50% going to buy anyone anything?
>
>Well, if the code uses segments extensively you can expect as much as a
>factor of 10 slowdown because of the extra costs involved in doing
>segment calculations. We have code here that runs slower on the 386
>than on the 286 because of this.

  I'm a little surprised. Loading a segment register in Real Mode is
comparable on both CPUs. Loading a segment register in Protected Mode
is comparable on both CPUs. One would expect a factor of about 8 slowdown
on the same load between Real and Protected Modes. In order to get this
order of magnitude slowdown, one would have to compare a Real Mode 286
with a Protected Mode 386, which, in my judgement, is apples and oranges.

  However, since the 386 allows one to set up an environment with
essentially flat segments, segment loads can be completely eliminated,
thus gaining a performance increase, even when comparing a Protected
Mode 386 to a Real Mode 286.

  Note that the extra cost is only incurred when *loading* a segment
register; once loaded, they cost nothing to use.

  When waving around numbers like Peter did, try to support them with
a little more than simple hocus pocus. ;-)


-- 
 * Dana H. Myers KK6JQ 		| Views expressed here are	*
 * (213) 337-5136 		| mine and do not necessarily	*
 * dana@locus.com		| reflect those of my employer	*

add@sciences.sdsu.edu (James D. Murray) (06/29/91)

suitti@ima.isc.com (Stephen Uitti) writes:
> 
> My guess is that if the code ran on an 8088, it should run
> reasonably quickly on a '386 without changes.  The 386/25 on my
> desk runs 20 times faster than my 8088/4.77 at home.  Can an
> additional 10%-50% going to buy anyone anything?
> 
	Optimization is not the point.  I need to execute 16-bit, segmented
code under an operating system that runs 32-bit, flat-model code only.  The
conversion is necessary to have the code run at all.

-- 

--------------------

add@sciences.sdsu.edu

add@sciences.sdsu.edu (James D. Murray) (06/29/91)

dana@locus.com (Dana H. Myers) writes:
>
>   I'm a little surprised. Loading a segment register in Real Mode is
> comparable on both CPUs. Loading a segment register in Protected Mode
> is comparable on both CPUs.

	The problem is not how long is takes to load a segment register once,
but how many times does a program have to reload the segment registers during
execution.  I'm not sure why, but 8088/286 machines seem to loose track of
the information in their segments forcing them to reload their segments
periodically.  This causes programs to slow down quite a bit.  This is not a
problem for a 386 running one giant segment.

-- 

--------------------

add@sciences.sdsu.edu

pardo@gar.cs.washington.edu (David Keppel) (06/30/91)

add@sciences.sdsu.edu (James D. Murray) writes:
>	Optimization is not the point.  I need to execute 16-bit, segmented
>code under an operating system that runs 32-bit, flat-model code only.  The
>conversion is necessary to have the code run at all.

Depending on how badly one needs the code...

The company "Insignia Solutions" makes an IBM-PC emulator that runs on
many SPARC, MIPS, etc. workstations.  They might have a version running
on the '386, for all I know.  They're in San Jose area, or write me and
I'll send out the address and 'fone number.

Ob whatever:

The Insignia solutions simulator is purely software.  There is a rumor
that currently the absolutely fastest PC clone that you can buy is an
HP `Snake' running Insignia's emulator.  Faster than any '486 box!

Think about it: using a '386, which has an 80286 compatability mode,
but ignoring the compatability mode and instead running a simulator.
Sick, sick, sick.  I love it!

		;-D on  ( Ported in code blood )  Pardo