Bit shift bug. (*solved*) - Printable Version +- Forum (https://www.boriel.com/forum) +-- Forum: Compilers and Computer Languages (https://www.boriel.com/forum/forumdisplay.php?fid=12) +--- Forum: ZX Basic Compiler (https://www.boriel.com/forum/forumdisplay.php?fid=11) +---- Forum: Bug Reports (https://www.boriel.com/forum/forumdisplay.php?fid=15) +---- Thread: Bit shift bug. (*solved*) (/showthread.php?tid=510) |
Bit shift bug. (*solved*) - britlion - 11-17-2012 Bit shift by 0, when 0 is from a variable=0, which is incorrect! Code: DIM num as uByte=1 All three lines should read "1" Re: Bit shift bug. - britlion - 11-17-2012 britlion Wrote:Bit shift by 0, when 0 is from a variable=0, which is incorrect! Code: ld hl, (_num2 - 1) Putting a byte through HL is a bit inefficient (as opposed to ld a,(_num2) / ld b,a / ld a,(_num)- but I see the heart of the problem. DJNZ decreases first (to 255) then loops if not zero. So this does 256 bit shifts before releasing - making the result bit shift right off the top of the byte value. Not trivial to solve this and still be efficient, however. Looks like it might need a CP test I like how var<<0 is completely ignored to just print var though - very nice coding for that constant. Same code as the line above. Re: Bit shift bug. - boriel - 11-17-2012 britlion Wrote:Yes, I supposed this was the problem. Anyway, the rule of thumb is that from the BASIC programmer point of view expr << 0 and expr << var must return the same result when 'var' = 0, as you pointed.britlion Wrote:Bit shift by 0, when 0 is from a variable=0, which is incorrect! I could rearrange the instructions above, in the backend, to produce this: Code: ; Loads a and h in reverse order so, a = number of shift iterations Re: Bit shift bug. - boriel - 11-18-2012 I think it's fixed for 8 bits (16 and 32 pending). Please, download version 1.3.0s938, and tell me if it works. This version also changes the way Floating point numbers are managed. They are some (a few) t-states slower, but uses much less memory (basically, using a subroutine), so new programs will save some precious bytes Re: Bit shift bug. - boriel - 12-30-2012 Britlion, Did you test it? It worked for me. Re: Bit shift bug. - britlion - 02-01-2013 Test: Sadly, I still hadn't. I've been so crazy busy this month, I've done no coding at all... I still have the same job, though. So you win on that... |