Instruction memory

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

Instruction memory

Greemngreek
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Instruction memory

ivant
It's filled with a specific program, which is a sequence of instructions. For example, the program, that implements the breakout game is one specific program. If you want to instead draw a house, that would be another program.

The fact that it's read-only memory means that the only way to change the program is to replace the ROM chip. Since all this runs in an emulator, the ROM chip's contents are loaded by the emulator before starting the execution. But the contents of this memory cannot be changed "from within". In other words, a HACK program cannot modify this memory.

It is similar to the old, cartridge-based game consoles. The cartridge contains a ROM chip with the program. To make the console run another program you need to replace the cartridge.
Reply | Threaded
Open this post in threaded view
|

Re: Instruction memory

Greemngreek
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Instruction memory

ivant
HACK computer has 32K ROM uses to store the program, 16K RAM used by the program at run-time, 8K video memory (RAM) and 1 word for the keyboard interface.

It's not necessary to use all 32K. When the computer is started, it starts executing the instructions from address 0 onward. Small programs can take just a few instructions, but larger ones will use most of the available memory.

The CPU itself doesn't know where the instructions or the data come from. The HACK computer architecture is such, that the CPU's instruction input is connected to the ROM chip. That said, there are some things in the HACK CPU, which make it well suited for this computer architecture, and harder to use in more conventional, Von Neumann architecutre: namely, the fact that it has separate instructions and data buses. Most modern CPUs have just one such bus and it serves for reading both instructions and data.

The reason HACK CPU is the way it is, is ease of implementation. The course goes from zero to building a full computer, assembler and high level language compiler for it. To pull it off, it has to make all these much simpler than what you'll find in the real world. Still it gives a very good overview of the hole picture and one can dive to more detailed understanding in any part afterwards.
Reply | Threaded
Open this post in threaded view
|

Re: Instruction memory

WBahn
Administrator
In reply to this post by Greemngreek
Let's try to clear up a few things.

You talk about a 32K "bit" instruction memory. There are actually 32K "words" of instruction ROM, where each word is 16 bits. So the memory size, in bits, is actually 512 Kb.

Even if they wanted to put all possible A- and C-type instructions into the 32K word ROM, that wouldn't be enough room. There are 32K possible A-instructions all by itself (all possible 16-bit combinations having a leading 0 bit, or 2^15 = 32,768 = 32K).

As already described by ivant, the ROM is loaded with a sequence of instructions that constitute the program that is going to be executed. These instructions, once loaded, cannot be changed except by replacing the ROM. The memory that the program can manipulated, the "data memory" is a separate block of RAM memory, with it's own address and data lines. This is what makes the Hack a "Harvard Architecture" and not a "von Neumann architecture" -- the book calls it "von Neumann" because there is a school of thought that classifies all stored-program computers and "von Neumann" and breaks that into two subclasses -- the Harvard architecture and the Princeton architecture. The Princeton architecture (which is what many people mean when they talk about a "von Neumann" machine) has a single memory space that contains both program instructions and data memory.

There are advantages to both architectures. The Princeton architecture is much more flexible, but in ways that can count in slow, simple processors, is slower. The Harvard architecture lends itself to application-specific processors used in embedded systems, which often are resource-starved, meaning that they have very limited clock speeds and/or memory. One family I've worked with has just 18 bytes of RAM -- not kilobytes, bytes -- and is commonly clocked at 32.768 kHz yielding a whopping 8192 instructions per second execution speed. Also, in application-specific embedded applications, often the last thing you want is for the computer to be able to modify the program it is running and a Harvard architecture makes that either very difficult or outright impossible, depending on the processor details.

Today's mainstream processors are actually a hybrid. At the level that we interact with them, they are Princeton architecture, but down close to the CPU, there are smaller memories where instructions get routed to one and data to the other and, as far as the hardware near the level of the CPU itself is concerned, it is a Harvard architecture.
Reply | Threaded
Open this post in threaded view
|

Re: Instruction memory

Greemngreek
This post was updated on .
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Instruction memory

WBahn
Administrator
Greemngreek wrote
How does a normal CPU carry out different programs if the ROM has to be replaced for every program?

P.S - Please forgive me for all my silly doubts. I am a sixteen year old guy with no prior experience in computer science and took up this course because I am very interested in knowing how a computer works at the lowest level...
It's preferred that you leave the profanities off the forum, thank you.

Remember that we have two types of architectures, Harvard and Princeton. The Princeton has the program instructions stored in the same RAM as the data. That makes it very easy to change programs and that is why most general-purpose computers use this architecture.

But you also have billions (literally, if not trillions by now) of computers that you don't WANT to be able to carry out different programs. A standard digital wristwatch, or remote control, or coffee maker, or dishwasher, or battery charge controller in a rechargeable battery pack, or any of the other millions upon millions of applications that have a processor embedded inside of them that is there to do one very specific thing. This is the realm of "embedded systems" and the Harvard architecture has dominated there for a very long time (though that is shifting as more and more small electronics become "smart" and take on increasingly "general-purpose" type uses). In these kinds of systems, the manufacturer burns the program into the chip (what is known as "masked-ROM" because it is literally part of the photomasks used to make the processor on the silicon wafer) and that is the program that that part runs for its entire life.

Reply | Threaded
Open this post in threaded view
|

Re: Instruction memory

Greemngreek
This post was updated on .
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Instruction memory

WBahn
Administrator
Actually, almost all of them do.

When you boot a computer, where do the instructions come from that it executes to start the boot process? They can't come from a program than is loaded into RAM, because then how did that program get loaded into RAM? It had to be via a program that could run without being loaded into RAM first. The answer... the boot ROM!

Back in the day, these are actual ROM devices -- if you needed to upgrade your boot ROM, you pulled out the existing one and replaced it with a new one. Today most computers and other devices use FLASH memory which is basically a ROM that can be changed a limited number of times.
Reply | Threaded
Open this post in threaded view
|

Re: Instruction memory

ivant
WBahn wrote
Actually, almost all of them do.

When you boot a computer, where do the instructions come from that it executes to start the boot process? They can't come from a program than is loaded into RAM, because then how did that program get loaded into RAM? It had to be via a program that could run without being loaded into RAM first. The answer... the boot ROM!
I just wanted to mention here, that unlike the HACK computer, the ROM in "normal" computers is just part of the normal memory. Much like the video RAM in the HACK computer is part of the RAM, it's mapped to specific addresses, at least part of which are the ones that the computer starts running from. This makes it possible to have a boot-time program and still be able to load and execute other programs, just in different parts of the memory.
Reply | Threaded
Open this post in threaded view
|

Re: Instruction memory

WBahn
Administrator
Yep -- it's pretty much a straight up Princeton architecture in which the low memory just happens to be ROM instead of RAM. Didn't mean to imply that it was a separate instruction memory space like you have in a Harvard architecture, but I can see how it might be interpreted that way.

I don't know about modern machines, but it was common for older machines to copy their ROM contents to RAM as part of the boot up so that they could access the functions there from the often faster RAM (plus not put excessive read cycles on the ROM).
Reply | Threaded
Open this post in threaded view
|

Re: Instruction memory

Greemngreek
In reply to this post by WBahn
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Instruction memory

WBahn
Administrator
You'd have to ask the authors for a definitive answer, but if I were building a course like this I would probably use a Harvard architecture, too. It's structurally a simpler architecture since you aren't having to ping pong back and forth between getting instructions and getting/storing data. Since this computer has no sense of a file system, you'd have to deal with a means of loading the program into memory. With a Harvard architecture that is simple -- you just do it the same way brain-dead processors do it and store the program in ROM before you start running.

Keep in mind the amazing breadth of the material in this course. The depth has to be carefully managed in order to make it even remotely doable.
Reply | Threaded
Open this post in threaded view
|

Re: Instruction memory

Greemngreek
CONTENTS DELETED
The author has deleted this message.