11.07.2015 Views

PICBASIC PLUS LITE Manual - Profe Saul

PICBASIC PLUS LITE Manual - Profe Saul

PICBASIC PLUS LITE Manual - Profe Saul

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>PICBASIC</strong> <strong>PLUS</strong> Compiler4.3. Multiply ‘*’.The Multiply operator (*) multiplies variables and/or constants, returning the low 16 bitsof the result. Works exactly as you would expect with unsigned integers from 0 to65535. If the result of multiplication is larger than 65535, the excess bits will be lost.DIM Value1 as WORDDIM Value2 as WORDValue1 = 1000Value2 = 19Value1 = Value1 * Value2PRINT @Value1' Multiply Value1 by Value2.' Display the result4.4. Multiply HIGH ‘**’.The Multiply High operator (**) multiplies variables and/or constants, returning the high16 bits of the result. When multiplying two 16-bit values, the result can be as large as 32bits. Since the largest variable supported by the compiler is 16-bits, the highest 16 bitsof a 32-bit multiplication result are normally lost. The ** (double-star) operand producesthese upper 16 bits.For example, suppose 65000 ($FDE8) is multiplied by itself. The result is4,225,000,000 or $FBD46240. The * (star, or normal multiplication) instruction wouldreturn the lower 16 bits, $6240. The ** instruction returns $FBD4.DIM Value1 as WORDDIM Value2 as WORDValue1 = $FDE8Value2 = Value1 ** Value1PRINT hex Value2' Multiply $FDE8 by itself' Return high 16 bits.4.5. Multiply MIDDLE ‘*/’.The Multiply Middle operator (*/) multiplies variables and/or constants, returning themiddle 16 bits of the 32-bit result. This has the effect of multiplying a value by a wholenumber and a fraction. The whole number is the upper byte of the multiplier (0 to 255whole units) and the fraction is the lower byte of the multiplier (0 to 255 units of 1/256each). The */ operand allows a workaround for the compiler’s integer-only math.Suppose we are required to multiply a value by 1.5. The whole number, and thereforethe upper byte of the multiplier, would be 1, and the lower byte (fractional part) would be128, since 128/256 = 0.5. It may be clearer to express the */ multiplier in HEX as $0180,since hex keeps the contents of the upper and lower bytes separate. Here's an example:DIM Value1 as WORDValue1 = 100Value1 = Value1 */ $0180 ' Multiply by 1.5 [1 + (128/256)]PRINT @Value1 ' Show result (150).16Copyright Crownhill 2001

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!