'Missing ]' error with LDRH/STRH + shifted offset
David Williams (2619) 103 posts |
In the ARM BBC BASIC assembler, the following instructions both result in a ‘Missing ]’ error: LDRH R5, [R2, R3, LSL #1] Omitting the shifts leads to successful assembly, as does omitting the ‘H’ suffix. I thought those would be valid instructions? Might this be down to a bug in BASIC’s assembler? I realise that I can shift R3 with a preceding MOV R3,R3,LSL #1, but it seems odd that the assembler doesn’t like shifted offset. Using BBC BASIC V 1.59 (24 Sep 2014) on a Raspberry Pi 2, RISC OS 5.21 (17-Feb-15). I’m writing graphics routines which handle 16bpp (RGB565) bitmap images, hence the need for the halfword loads & stores. David. |
Jeffrey Lee (213) 6048 posts |
It’s not a bug – LDRH/STRH don’t support shifted register offsets. (OK, the Thumb versions of the instructions do support small shift values, but BASIC assembler and RISC OS as a whole don’t really support Thumb so that doesn’t help you much) |
David Williams (2619) 103 posts |
Thank you, Jeffrey. |
Fred Graute (114) 645 posts |
It’s not a bug but it is a rather unhelpful error message. Could it be changed to something more clear, say “Illegal instruction”? |
Kuemmel (439) 384 posts |
…if you are doing image manipulation or similar I can encourage you to use NEON code. There are also tons of load/store variations like VLD/VLDR/VLDMIA…and when I read RGB565 this comes to my mind (in french…) => Link |
Jeffrey Lee (213) 6048 posts |
“Illegal instruction” is even more vague. If it was a standalone assembler then you could probably go for something like this, similar to the way modern C compilers annotate their error messages: ']' expected LDRH R5, [R2, R3, LSL #1] ^ Usually that would be enough for the programmer to be able to work out what the problem is, and it doesn’t require the author of the compiler/assembler to write hundreds of different context-specific error messages. However BASIC’s error handling means that annotated error messages will be difficult (essentially all errors need to be a RISC OS error block, and also most programs start with ON ERROR since the default error handler doesn’t list the line number). So I think the only way of improving the message(s) would be the hard way – add extra code to each place an error is generated to try and infer what the programmer intended, and then produce a more specific message like “LDRH doesn’t support shifted register offsets”.
Here’s the ARM blog post it links to (the original URL is dead and it doesn’t look like ARM set up a redirect. Grr!) |
David Williams (2619) 103 posts |
Kuemmel wrote:
Thanks for the link. Yes, I’ve seen some of your NEON-powered graphics code in action! Very instructive, and I’ll probably be looking at it again over the next few weeks or months. David. |
Jeffrey Lee (213) 6048 posts |
Just don’t expect to get astronomical performance improvements from using NEON on the Pi 2 – the Cortex-A7 NEON unit is designed for low power/die space, not speed. For integer performance it’s probably OK, but for float apparently it’s not much faster than VFP. |