Basic Shift Right

Anything QL Software or Programming Related.
martyn_hill
Gold Card
Posts: 373
Joined: Sat Oct 25, 2014 9:53 am

Re: Basic Shift Right

Postby martyn_hill » Mon Sep 04, 2017 11:57 am

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 22 times


martyn_hill
Gold Card
Posts: 373
Joined: Sat Oct 25, 2014 9:53 am

Re: Basic Shift Right

Postby martyn_hill » Mon Sep 04, 2017 12:01 pm

...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 21 times


martyn_hill
Gold Card
Posts: 373
Joined: Sat Oct 25, 2014 9:53 am

Re: Basic Shift Right

Postby martyn_hill » Mon Sep 04, 2017 7:33 pm

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 21 times


User avatar
BSJR
Chuggy Microdrive
Posts: 50
Joined: Sun Oct 18, 2015 12:53 pm
Location: Amsterdam
Contact:

Re: Basic Shift Right

Postby BSJR » Tue Sep 05, 2017 12:35 pm

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
Gold Card
Posts: 423
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: Basic Shift Right

Postby NormanDunbar » Tue Sep 05, 2017 1:43 pm

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?
How come Tarzan never grew a beard?
martyn_hill
Gold Card
Posts: 373
Joined: Sat Oct 25, 2014 9:53 am

Re: Basic Shift Right

Postby martyn_hill » Tue Sep 05, 2017 2:15 pm

Trust me to re-invent the wheel :-)


User avatar
dilwyn
Mr QL
Posts: 1279
Joined: Wed Dec 01, 2010 10:39 pm
Location: Wales
Contact:

Re: Basic Shift Right

Postby dilwyn » Tue Sep 05, 2017 3:17 pm

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?


Dilwyn
All things QL: see www.dilwyn.me.uk
Derek_Stewart
Aurora
Posts: 970
Joined: Mon Dec 20, 2010 11:40 am
Location: Runcorn, Cheshire, UK

Re: Basic Shift Right

Postby Derek_Stewart » Tue Sep 05, 2017 10:08 pm

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
Gold Card
Posts: 373
Joined: Sat Oct 25, 2014 9:53 am

Re: Basic Shift Right

Postby martyn_hill » Wed Sep 06, 2017 12:46 am

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
Trump Card
Posts: 151
Joined: Sun Jan 18, 2015 1:29 am

Re: Basic Shift Right

Postby ql_freak » Tue Sep 12, 2017 2:37 am

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 :-)

Return to “Software & Programming”

Who is online

Users browsing this forum: No registered users and 4 guests