Page 2 of 3
Re: Basic Shift Right
Posted: Mon Sep 04, 2017 11:57 am
by martyn_hill
Hi Derek
When you showed us an example of the BlitzMax SHR call, it appeared to be a binary operator, rather than a function, i.e. x SHR y versus SHR(x,y).
As we can't create new Operators in SB, only Functions, is that going to be a problem?
The attached assembler (zipped-up, to allow attachment here), works on 16-bit parameters and could easily be renamed or ALIASed to the form used by BlitzMax - as long as a function rather than operator is acceptable.
RSHIFT% and LSHIFT% (val%, disp%)
Where disp% is the number of bits to 'displace' val%:
. disp% can be 0 without error.
. disp% > 15 or < 0 will generate an error.
. no attempt is made to 'catch' the bits that fall off the end...
Any use?
Re: Basic Shift Right
Posted: Mon Sep 04, 2017 12:01 pm
by martyn_hill
...for completeness and as an example of handling Long-integers (32-bit) within a SB extension, I also attach the Long boolean functions as assembler.
Re: Basic Shift Right
Posted: Mon Sep 04, 2017 7:33 pm
by martyn_hill
I thought that i might as well complete the set of 32-bit operators - Boolean and Shift/Rotate functions combined.
For all my reading around the subject - including Dilwyn's terrific exposition on the topic - I'm still a bit unsure about the Maths/RI Stack handling, so take care if you use the attached extensions without validatng the assembler logic first. I've carried out only minimal testing...
Re: Basic Shift Right
Posted: Tue Sep 05, 2017 12:35 pm
by BSJR
martyn_hill wrote:I thought that i might as well complete the set of 32-bit operators - Boolean and Shift/Rotate functions combined.
There are already LSHIFT & RSHIFT keywords in the OUTPTR_bin toolkit from Wolfgang Lenerz.
http://www.wlenerz.com/QLStuff/#outptr
I found this while browsing the Keyword database on the SMSQ/E site.
http://www.wlenerz.com/smsqe/addkeys.html
AND_L, OR_L, NOT_L, XOR_L can also be found in various old toolkits like DP's TK3, Hi_tool2_bin & io2m_byt.
I Have not used any so cannot say if they perform the same way else name conflicts should be avoided.
Bob
Re: Basic Shift Right
Posted: Tue Sep 05, 2017 1:43 pm
by NormanDunbar
You might also find some others listed on the Online SuperBASIC Manual at
http://superbasic-manual.readthedocs.io/en/latest/ - do a quick search and see what turns up.
HTH
Cheers,
Norm.
Re: Basic Shift Right
Posted: Tue Sep 05, 2017 2:15 pm
by martyn_hill
Trust me to re-invent the wheel

Re: Basic Shift Right
Posted: Tue Sep 05, 2017 3:17 pm
by dilwyn
While Martyn slaps himself for reinventing the wheel, would someone like to gather together the best of these into a single package I could make available for these types of functions/operators?
Re: Basic Shift Right
Posted: Tue Sep 05, 2017 10:08 pm
by Derek_Stewart
Hi,
This question I asked seems to of digressed some what.
I was trying to convert BlitzMax source code of the Manic Miner game
BlitzMax has a function called SHR. Which is SHift Right
Re: Basic Shift Right
Posted: Wed Sep 06, 2017 12:46 am
by martyn_hill
Hi Derek
Are you concerned about the precise name of the extension (to match exactly the BlitzMax syntax), or some other aspect of what is being discussed?
It would be trivial to rename one of the available Right-shift extensions presented below.
Re: Basic Shift Right
Posted: Tue Sep 12, 2017 2:37 am
by ql_freak
This is one of the cases, where it is much easier to write a SuperBASIC extension. We need a logical and an arithmetic shift operation (arithmetic shift preserves sign - most significant bit). So a good SHIFT Function should be( (example for left [multiply by 2 on 68000]):
32 Bit:
shiftedNumber = SHIFTL(numberToShift, [noOfBitsToShift [, 0|1]])
Last argument is per default (if not given) logical shift (0), else arithmetic shift.
16 Bit:
shiftedNumber% = SHIFTL%(numberToShift [, noOfBitsToShift, [0|1]])
In 68000 Assembler there are logical and arithmetic shift operations inbuild, up to 256 Bits shifting (1 Byte) AFAIK.
Problem is for 32 Bit: What should be returned, if numberToShift is no long integer?
Return shifted value of nearest (lower?) integer?
Return an error?
Or make a 4th, optional argument, which tells what to do?