first post?
Pages: 1 2
Clive Semmens (2335) 3276 posts |
Steve: I presume you made clear the bit about minuses – it’s a hard-wired two digit limit, not two characters. You can have a minus sign (actually a hyphen) as well as two digits (as long as the minus sign comes first…) |
Steve Drain (222) 1620 posts |
I have just put a digits warning in for now. It is not only a minus but also a plus that can be inserted. |
Clive Semmens (2335) 3276 posts |
True, dat. I have to admit to not having a clue why one would want to put a plus or a leading zero in there, whereas a minus is necessary; but nor do I have a clue why anyone would have put a limit on leading zeroes if it actually increased the code size. |
nemo (145) 2546 posts |
It’s a microscopic optimisation: avoid a loop. I was looking at Basic’s number parsing because I am Making Something™, but I’ve not done anything useful in many days. It’s just too hot. There goes my plan to retire to the Algarve. |
Clive Semmens (2335) 3276 posts |
Cognitive dissonance? Or realization of implications? I’ve retired to where I lived already. If it wasn’t for family connections I’d retire to Iceland I think. |
Clive Semmens (2335) 3276 posts |
But makes the code bigger? And avoids a loop that will almost never be taken more than twice? OK – I’ve not read the code, and I’m talking out of my posterior orifice. |
nemo (145) 2546 posts |
Although this isn’t the exact code, reading a zero, one or two digit decimal is very titchy: LDRB R0, [R1],#1 SUB R0, R0, #"0" CMP R0, #10 MOVCS R0, #0 LDRCCB R2, [R1],#1 SUBCC R2, R2, #"0" CMPCC R2, #10 ADDCC R0, R0, R0, LSL#2 ADDCC R0, R2, R0, LSL#1 SUBCS R1, R1, #1 A loop is two fewer instructions, but more cycles because it has to repeat the loop for the terminator too: MOV R0, #0 lp LDRB R2, [R1],#1 SUB R2, R2, #"0" CMP R2, #10 ADDCC R0, R0, R0, LSL#2 ADDCC R0, R2, R0, LSL#1 BCC lp SUB R1, R1, #1 |
Clive Semmens (2335) 3276 posts |
So I wasn’t talking out of my posterior orifice then. That’s pretty much exactly what I’d imagined. A microscopic optimization indeed – optimizing speed v. optimizing code size, microscopic either way. |
Pages: 1 2