RE: PicoBlaze Simulator in JavaScript
August 21, 2022 at 10:10 am
(This post was last modified: August 21, 2022 at 10:11 am by bennyboy.)
(August 21, 2022 at 5:31 am)FlatAssembler Wrote: Anyway, @bennyboy , I have managed to modify the simulator to use switch-case instead of if-else, and the "Decimal to Binary" and "Binary to Decimal" examples work again. Unfortunately, they are not significantly faster. https://github.com/FlatAssembler/PicoBla...mulator.js
Yeah, I wasn't sure that it would. However, as a work of the programming arts, the new file is vastly superior-- I think anyone reading that will take some interest, instead of getting a headache.
If it is issues with the DOM and so on, i.e. if the execution of JavaScript code is not the bottleneck, then I'd recommend separating out highly repeated code. For example, I see a lot of this kind of thing:
Code:
case 0x31000:
// RETURN Z ; Return from a function only if the Zero Flag is set.
if (flagZ[regbank]) {
if (callStack.length)
PC = callStack.pop() + 1;
else {
if (playing)
clearInterval(simulationThread);
alert("The program exited!");
}
} else
PC++;
break;
case 0x35000:
// RETURN NZ ; Return from a function only if the Zero Flag is not set.
if (!flagZ[regbank]) {
if (callStack.length)
PC = callStack.pop() + 1;
else {
if (playing)
clearInterval(simulationThread);
alert("The program exited!");
}
} else
PC++;
break;
Could be
Code:
case 0x31000:
// RETURN Z ; Return from a function only if the Zero Flag is set.
PopIf (flagZ[regbank]);
break;
case 0x35000:
// RETURN NZ ; Return from a function only if the Zero Flag is not set.
PopIf (!flagZ[regbank]);
break;