Qbasicnews.com

Full Version: Rotate left 2 bits (like assembler)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6 7 8 9 10
Quote:LOGICLRD, the challenge had already been closed.
*****

So re-open it :-) The current winner clearly does not wish to hold the title.
Quote:I request you remove me as winner.

Ok, Z!re, poof, you're no longer the winner. Mango and Blitz move up one position in the ranking.
*****
Quote:
Moneo Wrote:LOGICLRD, the challenge had already been closed.
*****

So re-open it :-) The current winner clearly does not wish to hold the title.
Ok, but you have to do some work. Write, and post, a test program using your solution, that prints onto a workfile every value from -32767 tp 32766 on individual lines, and on the same line prints the resultant value which has been shifted left and rotated 2 bits.

I should then be able to take your test program, compile it, and run it producing the workfile. I'll then examine the workfile and make sure the results are correct.
*****
If you had told me that you wasn't using the IDE it could have posted simpler and faster code. I thought having it run in the IDE was one of the requirments. But whatever, i'm done with this challenge.
Quote:Ok, but you have to do some work. Write, and post, a test program using your solution, that prints onto a workfile every value from -32767 tp 32766 on individual lines, and on the same line prints the resultant value which has been shifted left and rotated 2 bits.

What is the exact format you want for this? Here are a few possibilities:

-32767 6
-32767 => 6
-32767 , 6
Before: -32767 After: 6

I will post the test program once you tell me what the format should be :-)
How about:
010100101101001 -> 010010110100101



And my name is still there, as the winner.
Nice avtar, really nice, really Big Grin
i'd say zires avatar is the winner, no really
logiclrd,

A simple format is fine, like:

print #1, input.value , result.value

where input.value and result.value are integers, and #1 is the workfile opened for output.
*****
Code:
DECLARE SUB ROL2 (a%)
DECLARE SUB ROL2ASM (a%)

' Set to 1 in order to test the CALL ABSOLUTE implementation.
CONST UseCallAbsoluteVersion% = 0

' The message board post clearly stated that values from -32767
' to +32766 should be used. However, an INTEGER can also store the
' values -32768 and +32767. To test the full range, set this to 0.
CONST SkipMinAndMax% = 1

DIM SHARED shiftLeft%(255), shiftRight%(255)

IF UseCallAbsoluteVersion% = 0 THEN
OPEN "ROL2POKE.TXT" FOR OUTPUT AS #1

' These lookup tables are only used in SUB ROL2, and not SUB ROL2ASM
FOR i% = 0 TO 255
  shiftLeft%(i%) = (i% * 4) AND 255
  shiftRight%(i%) = i% \ 64
NEXT i%
ELSE
OPEN "ROL2ASM.TXT" FOR OUTPUT AS #1
END IF

FOR i& = -32768 + SkipMinAndMax% TO 32767& - SkipMinAndMax%
a% = i&
PRINT #1, a%,
IF UseCallAbsoluteVersion% = 0 THEN ROL2 a% ELSE ROL2ASM a%
PRINT #1, a%
NEXT i&

CLOSE #1

SUB ROL2 (a%)
DEF SEG = VARSEG(a%)
ptr% = VARPTR(a%)
l% = PEEK(ptr%)
h% = PEEK(ptr% + 1)
POKE ptr%, shiftLeft%(l%) OR shiftRight%(h%)
POKE ptr% + 1, shiftLeft%(h%) OR shiftRight%(l%)
END SUB

SUB ROL2ASM (a%)
DIM code&(3)
code&(0) = -1959337079: code&(1) = 126551135
code&(2) = -1059913039: code&(3) = 13305737
DEF SEG = VARSEG(code&(0))
CALL ABSOLUTE(a%, VARPTR(code&(0)))
END SUB
Pages: 1 2 3 4 5 6 7 8 9 10