Code.comp()

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Code.comp()

James
Is there and easier way to translate the comp mnemonics then a really large switch statement (which i am currently doing)?  there must be some algorithmic way of doing this isn't there?
Reply | Threaded
Open this post in threaded view
|

Re: Code.comp()

ybakos
Definitely! But I believe going "algorithmic" is a bit too complicated.

Keep in mind that all comp/jump/dest mnemonics map directly to a particular binary code. Hmmm.... keys and values.... hmm...

Reply | Threaded
Open this post in threaded view
|

Re: Code.comp()

James
hmmm my data structures knowledge is super rusty.  Hash table??
Reply | Threaded
Open this post in threaded view
|

Re: Code.comp()

cadet1620
Administrator
James wrote
hmmm my data structures knowledge is super rusty.  Hash table??
Yes. They're very easy to use in higher level languages. Python calls them dictionaries, Java calls them HashMaps, Ruby calls them Hashs.

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: Code.comp()

James
This post was updated on .
cool thanks guys, but i have some interesting things here.  my program using the massive switch statement was able to assemble the pongL.asm (27,500 lines of assembly) in 121 milliseconds, but after i converted my assembler to use a hash table instead it actually ran slower and took 146 milliseconds to assemble.  any thoughts on this?? i though for sure hashing would be faster. I suspect the additional time taken was probably from loading the actual table itself, i suppose i could time how long it takes to load the table then subtract that from the time it takes to assemble the whole program.

EDIT: weird i just ran it again and this time it ran at 120 ms. a 1 ms gain! ill take it.
Reply | Threaded
Open this post in threaded view
|

Re: Code.comp()

ybakos
Keep in mind that while a switch statement of, say, 50 branches might be faster than a hashtable lookup of 50 elements, consider what happens when you have 1000 elements.

(I'm oversimplifying here.)
Reply | Threaded
Open this post in threaded view
|

Re: Code.comp()

James
yes that is very true, also i was thinking about how much more flexible the hash table is, like possible storing all the functions and binary codes in an external definition file that loads at run time so if i ever add additional functions to the hack CPU i can just modify the file and not the source :) good stuff.