In article <81bqok$56...@ctb-nnrp1.saix.net>,

##### Quote

NLHG <Heinr...@mailroom.com> wrote:

>Hi there!

>I hope there someone who has been crazy enough to do this before!

>I hope you understand the term fixed point numbers!

>This is where u use a 32bit number to represent a "real" number!

>You use the top 16.bits for the integer part and the bottum 16-bits for the

>fraction part!

>The advantage is that you can do fairly accurate maths without the maths

>co-processor!

>I.E. FASTER

>Know I have a bit off a problem!

>How do I multiply 2 off these fixed point numbers!

>And how do I divide them!

Well if you want fast then Inline is the way to go. Assuming the numbers

are unsigned one can use the following:

type fixed=longint;

conbst overflow:word=0;

Function mul(x,y:fixed):fixed;

inline(

$66/$5B/ {POP EBX}

$66/$58/ {POP EAX}

$66/$F7/$E3/ {MUL EBX}

$66/$C1/$E8/$10/ {SHR EAX,10H}

$66/$89/$D3/ {MOV EBX,EDX}

$66/$C1/$EB/$10/ {SHR EBX,10H}

$09/$1E/Overflow {OR Overflow,BX}

);

Function dvd(x,y:fixed):fixed;

inline(

$66/$5B/ {POP EBX}

$66/$31/$D2/ {XOR EDX,EDX}

$58/ {POP AX}

$5A/ {POP DX}

$66/$C1/$E0/$10/ {SHL EAX,10H}

$66/$F7/$F3/ {DIV EBX}

$66/$0F/$A4/$C2/$10 {SHLD EDX,EAX,10h}

);

Division gives RTE200 if the result does not fit into the range so no

extra overflow information is carried out like with multiplication. (if

there is overflow in multiplication the overflow will be >0).

Sometimes one needs to do division after multiplication. If one writes

a separate routine for it the intermediate result can freely overflow

provided that the final results is in the range (otherwise one gets

RTE200).

Function muldiv(x,y,z:fixed):fixed;

inline(

$66/$59/ {POP ECX}

$66/$5B/ {POP EBX}

$66/$58/ {POP EAX}

$66/$F7/$E3/ {MUL EBX}

$66/$F7/$F1/ {DIV ECX}

$66/$0F/$A4/$C2/$10 {SHLD EDX,EAX,10h}

);

That is of course x*y/z

The last btw works also on normal longints provided they are positive (or

unsigned)

##### Quote

>Second about the 32-bit numbers!

>I use turbo pascal 7.0 wich is a 16-bit programming language!

>So it doesn't make use off the extended registers!

Actually the RTL uses them for longint multiplication and division. The

actual compiler does not use them.

##### Quote

>So if I like to use extended registers I must use NASM and use the inline

>function!

????

##### Quote

>Does someone know how pascal uses 32-bit numbers in it's code.

Well it uses two 16 bit registers. For example function results are

returned in DX:AX.

????