Basic Shift Right

Anything QL Software or Programming Related.
martyn_hill
Aurora
Posts: 909
Joined: Sat Oct 25, 2014 9:53 am

Re: Basic Shift Right

Post 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?
Attachments
shift_asm.zip
LSHIFT% and RSHIFT% (16-bit) SB extensions
(1.18 KiB) Downloaded 121 times


martyn_hill
Aurora
Posts: 909
Joined: Sat Oct 25, 2014 9:53 am

Re: Basic Shift Right

Post 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.
Attachments
long_ops_asm.zip
Long-integer (32-bit) Boolean functions
(1.7 KiB) Downloaded 118 times


martyn_hill
Aurora
Posts: 909
Joined: Sat Oct 25, 2014 9:53 am

Re: Basic Shift Right

Post 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...
Attachments
long_ops_v20.zip
LONG (32-bit) Operators - Boolean and Shift/Rotate - v2.0 including ASM source and binary files
(2.85 KiB) Downloaded 123 times


User avatar
BSJR
Trump Card
Posts: 182
Joined: Sun Oct 18, 2015 12:53 pm
Location: Amsterdam
Contact:

Re: Basic Shift Right

Post 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


User avatar
NormanDunbar
Forum Moderator
Posts: 2251
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: Basic Shift Right

Post 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.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
martyn_hill
Aurora
Posts: 909
Joined: Sat Oct 25, 2014 9:53 am

Re: Basic Shift Right

Post by martyn_hill »

Trust me to re-invent the wheel :-)


User avatar
dilwyn
Mr QL
Posts: 2753
Joined: Wed Dec 01, 2010 10:39 pm

Re: Basic Shift Right

Post by dilwyn »

NormanDunbar wrote: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.
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?


Derek_Stewart
Font of All Knowledge
Posts: 3928
Joined: Mon Dec 20, 2010 11:40 am
Location: Sunny Runcorn, Cheshire, UK

Re: Basic Shift Right

Post 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


Regards,

Derek
martyn_hill
Aurora
Posts: 909
Joined: Sat Oct 25, 2014 9:53 am

Re: Basic Shift Right

Post 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.


User avatar
ql_freak
Gold Card
Posts: 353
Joined: Sun Jan 18, 2015 1:29 am

Re: Basic Shift Right

Post 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?


http://peter-sulzer.bplaced.net
GERMAN! QL-Download page also available in English: GETLINE$() function, UNIX-like "ls" command, improved DIY-Toolkit function EDLINE$ - All with source. AND a good Python 3 Tutorial (German) for Win/UNIX :-)
Post Reply