Getting Binary Instructions

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

Getting Binary Instructions

Kuro
Should we use a straight forward if, else if etc. to find the binary values?
Or should we try to do something similar to the ALU where we say
if A is not contained in comp substring: c1 = 1?
Reply | Threaded
Open this post in threaded view
|

Re: Getting Binary Instructions

cadet1620
Administrator
Kuro wrote
Should we use a straight forward if, else if etc. to find the binary values?
Or should we try to do something similar to the ALU where we say
if A is not contained in comp substring: c1 = 1?
The TECS answer is "if it works, it's correct," but some things are easier than others...

If you are using a language like Java, Python or Ruby, there is an object/data type that lets you store values indexed by strings. In Python it's dictionary, in Ruby it's Hash, in Java I think it's HashMap.

In the initialization part of my Code Module I create 3 constant dictionaries that map the dest, comp and jump string values to their corresponding string of bits.

The three functions in the Code Module simply need to return the value stored in the dictionary for their given argument. If the argument is not a valid key for the dictionary, they print an error message and halt.

--Mark