Our server costs ~$56 per month to run. Please consider donating or becoming a Patron to help keep the site running. Help us gain new members by following us on Twitter and liking our page on Facebook!
Current time: January 31, 2025, 5:09 pm

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PicoBlaze Simulator in JavaScript
#47
RE: PicoBlaze Simulator in JavaScript
(August 17, 2022 at 3:30 pm)FlatAssembler Wrote: I am a bit amazed people here are recommending me to use switch-case. In our "Razvoj Programske Podrške po Objektno Orijentiranim Načelima" classes, we were taught that using switch-case is a sign of bad style. Domagoj Kusalić in his book "Napredno Programiranje i Algoritmi u C-u i C++-u" also says switch-case should be used only rarely, if ever.
Does it say why?

Let me ask you a question. In your .js file (Hi, mom, I got mentioned in someone's github!), you have a series of conditions formed like this:
Code:
if ((currentDirective & 0xff000) === 0x00000) {  // Do your LOAD register,register stuff }
else if ((currentDirective & 0xff000) === 0x01000) {  // Do your LOAD register,constant stuff }

So you will have to do that bit operation every time. Why do you not do this:
Code:
var filteredDirective = currentDirective & 0xff000;
if (filteredDirective  === 0x00000) {  // Do your LOAD register,register stuff }
else if (filteredDirective === 0x01000) { // Do your LOAD register,constant stuff }

Now, personally, I don't think that this difference will matter much unless you have hamsters running the code, but it seems like a lot of unnecessary operations to me.

Also, for style, I'd probably replace the hex constanst with meaningful labels, so you can check them all in code easily without scanning through many nested conditionals, though I don't know enough about JavaScript to know if it is comparable with "===":
Code:
const LRR = 0x00000; // Load register, register
. . .
if (filteredDirective === LRR) { // Do your LRR stuff }



Messages In This Thread
PicoBlaze Simulator in JavaScript - by FlatAssembler - November 5, 2020 at 9:34 am
RE: PicoBlaze Simulator in JavaScript - by FlatAssembler - November 14, 2020 at 3:35 pm
RE: PicoBlaze Simulator in JavaScript - by Sal - November 15, 2020 at 7:37 am
RE: PicoBlaze Simulator in JavaScript - by FlatAssembler - November 15, 2020 at 7:45 am
RE: PicoBlaze Simulator in JavaScript - by Sal - November 15, 2020 at 8:10 am
RE: PicoBlaze Simulator in JavaScript - by LadyForCamus - August 16, 2022 at 7:24 pm
RE: PicoBlaze Simulator in JavaScript - by FlatAssembler - August 17, 2022 at 2:03 pm
RE: PicoBlaze Simulator in JavaScript - by BrianSoddingBoru4 - November 14, 2020 at 3:37 pm
RE: PicoBlaze Simulator in JavaScript - by FlatAssembler - November 15, 2020 at 4:56 am
RE: PicoBlaze Simulator in JavaScript - by BrianSoddingBoru4 - November 15, 2020 at 4:59 am
RE: PicoBlaze Simulator in JavaScript - by FlatAssembler - November 15, 2020 at 8:11 am
RE: PicoBlaze Simulator in JavaScript - by FlatAssembler - December 20, 2020 at 3:12 pm
RE: PicoBlaze Simulator in JavaScript - by FlatAssembler - September 7, 2021 at 5:52 pm
RE: PicoBlaze Simulator in JavaScript - by FlatAssembler - February 8, 2022 at 1:20 pm
RE: PicoBlaze Simulator in JavaScript - by arewethereyet - February 8, 2022 at 1:23 pm
RE: PicoBlaze Simulator in JavaScript - by FlatAssembler - February 8, 2022 at 1:33 pm
RE: PicoBlaze Simulator in JavaScript - by BrianSoddingBoru4 - February 8, 2022 at 2:38 pm
RE: PicoBlaze Simulator in JavaScript - by FlatAssembler - August 7, 2022 at 7:24 am
RE: PicoBlaze Simulator in JavaScript - by arewethereyet - August 7, 2022 at 6:59 pm
RE: PicoBlaze Simulator in JavaScript - by FlatAssembler - August 9, 2022 at 2:32 am
RE: PicoBlaze Simulator in JavaScript - by FlatAssembler - August 12, 2022 at 7:26 am
RE: PicoBlaze Simulator in JavaScript - by FlatAssembler - August 12, 2022 at 1:43 pm
RE: PicoBlaze Simulator in JavaScript - by HappySkeptic - August 12, 2022 at 9:24 am
RE: PicoBlaze Simulator in JavaScript - by FlatAssembler - August 12, 2022 at 1:41 pm
RE: PicoBlaze Simulator in JavaScript - by FlatAssembler - August 15, 2022 at 6:55 am
RE: PicoBlaze Simulator in JavaScript - by arewethereyet - August 15, 2022 at 6:57 am
RE: PicoBlaze Simulator in JavaScript - by FlatAssembler - August 16, 2022 at 12:37 pm
RE: PicoBlaze Simulator in JavaScript - by HappySkeptic - August 12, 2022 at 4:37 pm
RE: PicoBlaze Simulator in JavaScript - by FlatAssembler - August 15, 2022 at 6:48 am
RE: PicoBlaze Simulator in JavaScript - by bennyboy - August 12, 2022 at 6:34 pm
RE: PicoBlaze Simulator in JavaScript - by FlatAssembler - August 15, 2022 at 6:44 am
RE: PicoBlaze Simulator in JavaScript - by bennyboy - August 15, 2022 at 9:35 am
RE: PicoBlaze Simulator in JavaScript - by FlatAssembler - August 16, 2022 at 12:38 pm
RE: PicoBlaze Simulator in JavaScript - by HappySkeptic - August 16, 2022 at 1:23 pm
RE: PicoBlaze Simulator in JavaScript - by bennyboy - August 16, 2022 at 5:39 pm
RE: PicoBlaze Simulator in JavaScript - by arewethereyet - August 15, 2022 at 6:47 am
RE: PicoBlaze Simulator in JavaScript - by FlatAssembler - August 17, 2022 at 2:02 pm
RE: PicoBlaze Simulator in JavaScript - by HappySkeptic - August 17, 2022 at 3:08 pm
RE: PicoBlaze Simulator in JavaScript - by FlatAssembler - August 17, 2022 at 3:25 pm
RE: PicoBlaze Simulator in JavaScript - by bennyboy - August 17, 2022 at 3:25 pm
RE: PicoBlaze Simulator in JavaScript - by FlatAssembler - August 17, 2022 at 3:30 pm
RE: PicoBlaze Simulator in JavaScript - by bennyboy - August 17, 2022 at 3:34 pm
RE: PicoBlaze Simulator in JavaScript - by HappySkeptic - August 18, 2022 at 11:06 am
RE: PicoBlaze Simulator in JavaScript - by HappySkeptic - August 17, 2022 at 3:57 pm
RE: PicoBlaze Simulator in JavaScript - by bennyboy - August 17, 2022 at 4:43 pm
RE: PicoBlaze Simulator in JavaScript - by FlatAssembler - August 18, 2022 at 6:43 am
RE: PicoBlaze Simulator in JavaScript - by HappySkeptic - August 18, 2022 at 9:31 am
RE: PicoBlaze Simulator in JavaScript - by FlatAssembler - August 18, 2022 at 9:08 am
RE: PicoBlaze Simulator in JavaScript - by bennyboy - August 18, 2022 at 9:41 am
RE: PicoBlaze Simulator in JavaScript - by HappySkeptic - August 18, 2022 at 10:10 am
RE: PicoBlaze Simulator in JavaScript - by FlatAssembler - August 18, 2022 at 12:00 pm
RE: PicoBlaze Simulator in JavaScript - by HappySkeptic - August 18, 2022 at 12:12 pm
RE: PicoBlaze Simulator in JavaScript - by FlatAssembler - August 19, 2022 at 9:41 am
RE: PicoBlaze Simulator in JavaScript - by FlatAssembler - August 19, 2022 at 9:44 am
RE: PicoBlaze Simulator in JavaScript - by FlatAssembler - August 21, 2022 at 5:31 am
RE: PicoBlaze Simulator in JavaScript - by bennyboy - August 21, 2022 at 10:10 am
RE: PicoBlaze Simulator in JavaScript - by FlatAssembler - August 21, 2022 at 11:05 am
RE: PicoBlaze Simulator in JavaScript - by bennyboy - August 21, 2022 at 7:12 pm
RE: PicoBlaze Simulator in JavaScript - by bennyboy - August 21, 2022 at 7:31 pm
RE: PicoBlaze Simulator in JavaScript - by FlatAssembler - August 22, 2022 at 9:07 am
RE: PicoBlaze Simulator in JavaScript - by bennyboy - August 22, 2022 at 11:38 am
RE: PicoBlaze Simulator in JavaScript - by FlatAssembler - August 22, 2022 at 11:49 am
RE: PicoBlaze Simulator in JavaScript - by bennyboy - August 22, 2022 at 5:19 pm
RE: PicoBlaze Simulator in JavaScript - by FlatAssembler - August 23, 2022 at 2:33 pm
RE: PicoBlaze Simulator in JavaScript - by bennyboy - August 23, 2022 at 6:04 pm
RE: PicoBlaze Simulator in JavaScript - by FlatAssembler - August 24, 2022 at 7:18 am
RE: PicoBlaze Simulator in JavaScript - by bennyboy - August 24, 2022 at 7:43 am
RE: PicoBlaze Simulator in JavaScript - by bennyboy - August 25, 2022 at 7:33 am
RE: PicoBlaze Simulator in JavaScript - by FlatAssembler - August 31, 2022 at 7:12 am
RE: PicoBlaze Simulator in JavaScript - by bennyboy - August 31, 2022 at 11:13 am
RE: PicoBlaze Simulator in JavaScript - by FlatAssembler - September 2, 2022 at 12:59 am
RE: PicoBlaze Simulator in JavaScript - by FlatAssembler - September 14, 2022 at 9:31 am

Possibly Related Threads...
Thread Author Replies Views Last Post
  A weird bug in the preprocessor of PicoBlaze Simulator in JavaScript FlatAssembler 81 10127 December 19, 2023 at 4:46 pm
Last Post: BrianSoddingBoru4
  Reformatting tools for JavaScript FlatAssembler 0 467 June 14, 2020 at 10:13 am
Last Post: FlatAssembler
  Anatomy of religion in RELIGION SIMULATOR game gravitysoftware 12 3463 February 8, 2015 at 12:52 pm
Last Post: c172
  Analysis of a Facebook social engineering/Javascript "hack" Autumnlicious 4 3539 March 2, 2011 at 9:29 am
Last Post: fr0d0



Users browsing this thread: 1 Guest(s)