Basic Shift Right
-
- Aurora
- Posts: 932
- Joined: Sat Oct 25, 2014 9:53 am
Re: Basic Shift Right
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?
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 123 times
-
- Aurora
- Posts: 932
- Joined: Sat Oct 25, 2014 9:53 am
Re: Basic Shift Right
...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 120 times
-
- Aurora
- Posts: 932
- Joined: Sat Oct 25, 2014 9:53 am
Re: Basic Shift Right
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...
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 125 times
Re: Basic Shift Right
There are already LSHIFT & RSHIFT keywords in the OUTPTR_bin toolkit from Wolfgang Lenerz.martyn_hill wrote:I thought that i might as well complete the set of 32-bit operators - Boolean and Shift/Rotate functions combined.
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
- NormanDunbar
- Forum Moderator
- Posts: 2277
- Joined: Tue Dec 14, 2010 9:04 am
- Location: Leeds, West Yorkshire, UK
- Contact:
Re: Basic Shift Right
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.
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.
Author of Arduino Software Internals
Author of Arduino Interrupts
No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
-
- Aurora
- Posts: 932
- Joined: Sat Oct 25, 2014 9:53 am
Re: Basic Shift Right
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?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.
--
All things QL - https://dilwyn.qlforum.co.uk/index.html
All things QL - https://dilwyn.qlforum.co.uk/index.html
-
- Font of All Knowledge
- Posts: 3973
- Joined: Mon Dec 20, 2010 11:40 am
- Location: Sunny Runcorn, Cheshire, UK
Re: Basic Shift Right
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
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
Derek
-
- Aurora
- Posts: 932
- Joined: Sat Oct 25, 2014 9:53 am
Re: Basic Shift Right
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.
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
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?
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
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