Operation code and address in one instruction

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

Operation code and address in one instruction

scout
Hello everyone,

I would like to ask you a question about chapter 4, more specifically about this sentence:
"Since Hack instructions are 16-bit wide, and since addresses are specified using 15 bits, it is impossible to pack both an operation code and an address in one instruction."

My question is, if our CPU only allowed two operations, say AND and ADD, wouldn't it be possible to actually store a 15 bit address and an operation in one instruction?

I'm not trying to be funny or pedantic, I just want to make sure that I got the essentials right. Of course my hypothetical CPU wouldn't be very helpful or "powerful" but it would be possible, right?

Reply | Threaded
Open this post in threaded view
|

Re: Operation code and address in one instruction

cadet1620
Administrator
scout wrote
My question is, if our CPU only allowed two operations, say AND and ADD, wouldn't it be possible to actually store a 15 bit address and an operation in one instruction?

I'm not trying to be funny or pedantic, I just want to make sure that I got the essentials right. Of course my hypothetical CPU wouldn't be very helpful or "powerful" but it would be possible, right?
That is correct. One op-code bit and 15 address bits would fit in a word.

It's actually possible to make a computer with only one instruction. Check out One instruction set computer (Wikipedia).

Most OISC require multiple addresses in their instruction. Your 2ISC could have a single register and one instruction could be a subtract and the other a JLE.

Keep thinking these strange thoughts and keep asking questions!

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

Re: Operation code and address in one instruction

scout
Thank you so much for your reply Mark (should I address you by Professor Mark?).

You see this is amazing, it's a whole new world to me. My academic pursuits are not computer science, this is just a curiosity/hobby/complement to my academic degree, so I want to make sure I understand every bit (no pun intended).

If I may let me ask you a couple more questions about my hypothetical 2ISC. You mention it could be implement with just a subtract and a JLE (I suppose it means Jump if Less or Equal than).
Could it also be implemented with an add and a JGE (let's just agree that it means Jump if Greater or Equal than)?
Should we prefer your proposal to avoid overflow problems, or my proposal is not viable at all?
Could this 2ISC computer actually run a full fledged operating system (like Linux or Windows), given that a team of highly skilled individuals with a lot of time and funds was working on it?
Reply | Threaded
Open this post in threaded view
|

Re: Operation code and address in one instruction

cadet1620
Administrator
scout wrote
Thank you so much for your reply Mark (should I address you by Professor Mark?).

You see this is amazing, it's a whole new world to me. My academic pursuits are not computer science, this is just a curiosity/hobby/complement to my academic degree, so I want to make sure I understand every bit (no pun intended).

If I may let me ask you a couple more questions about my hypothetical 2ISC. You mention it could be implement with just a subtract and a JLE (I suppose it means Jump if Less or Equal than).
Could it also be implemented with an add and a JGE (let's just agree that it means Jump if Greater or Equal than)?
Should we prefer your proposal to avoid overflow problems, or my proposal is not viable at all?
"Mark" will do, I'm an engineer/programmer.

Warning, it sounds like you've been bitten by the computer hobby.  I took up electronics as a hobby when I was 11 and it never let go of me... (late 1960's -- vacuum tube radios, slide rules, etc. Discovered computer programming a couple years later and it was all down hill from there! 8^)

In chapter 1 you learned that Nand can be used as a fundamental primitive to build all logic. Implied, but not stated is that you also need one constant, either true or false. (Once you derive Not, use false = Not(true) or true = Not(false) to get the other.) This system works because Nand includes Not in its operation.

For the One or Two-instruction computer, the arithmetic operation needs to include negation, and subtract is a useful way to do that. You can make addition from subtraction:
    a + b = a - (0 - b)
but you can't make subtraction from addition.

The OISC also needs a constant, either 1 or -1. One way to supply this constant is to hard wire a RAM address to always be that constant. An example would be have RAM[0] always be 0 and RAM[1] always be 1. (Hard wiring RAM[0]=0 saves every program from starting with SUB 0, 0.)

The compare operation needs to include either less than or greater than, including equals in the comparison is optional. All 4 of these compares are logically equivalent:
    a < 0   =   Not(a >= 0)
    a > 0   =   -a < 0
Could this 2ISC computer actually run a full fledged operating system (like Linux or Windows), given that a team of highly skilled individuals with a lot of time and funds was working on it?
The Hack computer designed in this course is almost powerful enough to run a simple operating system. (More like MSDOS than Linux or Windows). All it needs is larger RAM and ROM, some sort of data storage peripheral (disk), and a way for programs to get other programs loaded from the disk into ROM.

The VM translator (chapter 7) converts a virtual stack language to Hack assembler.  One could just as easily write a translator that output code for the 2ISC, and then Jack programs could be run on the 2ISC.

--Mark