RE: PicoBlaze Simulator in JavaScript
August 15, 2022 at 9:35 am
(This post was last modified: August 15, 2022 at 9:39 am by bennyboy.)
(August 15, 2022 at 6:44 am)FlatAssembler Wrote: Thank you, it would be a good thing to speed up the assembler a bit. But the assembler is, at least for the test programs, already running at an acceptable speed. It is the simulator that is running way too slowly.Well, at least this file was commented, so it's slightly more readable. It still seems to me that so many if/else statements is likely to cause trouble-- though if you're only running programs limited to 4KB, it's hard to believe that even an inefficient algorithm would take more than a split second.
Anyway, instead of so many repeated conditionals, I'd recommend using a large "switch":
Code:
var codebyte = currentDirective & 0xff000;
switch (codebyte){
case 0x00000:
//Call a Register load from register function here.
break;
case 0x01000:
//Call a Register load from value function here.
break;
}
It's (much) better to generate a lookup table on compile than to keep constantly doing new comparisons. (I'm not so sure how much this will actually affect processing a small amount of data though).