SHL and SHR / Using Interrupts in Protect Mode

Quote:

>I have heard that SHL and SHR are considerably faster than standard divide

>and multiply commands, but how do I use them? For 2*2 I tried 2 shl 2 (and

>2 shr 2) but I didn't anything close to a right answer. So how can I

>effectively use them when I need to do a LOT of multiplying and dividing?

>(examples would help!)

>Thanks! Email me if possible.

Email has been sent as requested but others seem to have this problem

to. Hopefully this simple example will help.

Regards,

Clif

Program ShiftOps;

{ Turbo v.6.0 demo of SHL and SHR for multiplying and integer dividing

POSITIVE integers by multiples of two. No overflow or underflow

VAR

n, ans:LongInt; (* 32 bit maximum values *)

shift:Byte;

Begin

Writeln; Writeln; Writeln;

n := 1;

For shift := 1 to 20 Do

Begin

ans := n SHL 1;

Writeln('2 ^ ', shift:2, ' = ', ans:8);

n := ans;

End;

Write(' <<< Press Enter>>> '); Readln; Writeln;

For shift := 1 to 20 Do

Begin

ans := n SHR 1;

Writeln(n:7, ' div 2 = ', ans);

n := ans;

End;

n := 537169;

ans := n SHL 3;

Writeln(n, ' * 8 = ', ans);

ans := n SHR 4;

Writeln(n, ' div 16 = ', ans);

Write(' <<< Press Enter>>> '); Readln;

End.