Some Generic Questions

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

Some Generic Questions

invin
I am not very clear about the details of some of the concepts explained in the chapters. I would appreciate a not too lengthy explanation for the following questions:

1) What code/programs scans Keyboard and Screen? Where do they run i.e. on Hack computer or are they Java programs that directly run on my computer or is it some other controller that controls them? Please explain.

2) How does a program terminate on a generic CPU? Does a compiler (generic) insert infinite loop instructions at the end of each program/application?

3) If a CPU is 64 bits, does it mean that everything in the CPU is 64 bits i.e instruction sets, addressable words, buses, registers? The reason I ask this question is that the x86 Intel CPU has different length instructions, registers and memory is byte addressable?

4) In a Von Neumann architecture, there is only one main memory. Is there an actual partition inside these memories for separating the data and instructions? What makes the instruction "read-only" in the instruction area (because it would be a security risk otherwise)?

5) What loads a program into the Main Memory of a generic computer? Is it the operating system?
Reply | Threaded
Open this post in threaded view
|

Re: Some Generic Questions

cadet1620
Administrator
invin wrote
I am not very clear about the details of some of the concepts explained in the chapters. I would appreciate a not too lengthy explanation for the following questions:

1) What code/programs scans Keyboard and Screen? Where do they run i.e. on Hack computer or are they Java programs that directly run on my computer or is it some other controller that controls them? Please explain.
The connection between your PC's keyboard and monitor and the simulated Hack keyboard and screen is all Java code running on your PC.

The code simulates the Keyboard hardware device as described in chapter 4. When you access the keyboard in assembly language using @KEYBOARD, D=M, your code is accessing that simulated keyboard hardware. When you run Jack programs on the Hack computer you access the keyboard using commands like let key = Keyboard.readChar(); you are calling keyboard driver code that runs on the Hack computer. (You will later write this driver code in project 12.)
2) How does a program terminate on a generic CPU? Does a compiler (generic) insert infinite loop instructions at the end of each program/application?
Programs normally terminate by calling an OS function that tells the OS that the program is done.  In some environments this is handled by library code so that the OS exit call is made when the program's main() functions returns.
3) If a CPU is 64 bits, does it mean that everything in the CPU is 64 bits i.e instruction sets, addressable words, buses, registers? The reason I ask this question is that the x86 Intel CPU has different length instructions, registers and memory is byte addressable?
For an N-bit computer, the N is the size of the data paths and registers in the CPU. This is the word size for the computer. Memory is usually addressed using 8-bit bytes so that smaller data, like characters, can be handled efficiently.  Some computers require that data that is wider than bytes must be properly aligned in memory. They can not for instance read/write a 16-bit value from an odd byte address. Others can do "word assembly" for misaligned accesses.

The same is true for instructions. Most computers have variable length instructions and the instructions can  be packed into the longer memory words.
4) In a Von Neumann architecture, there is only one main memory. Is there an actual partition inside these memories for separating the data and instructions? What makes the instruction "read-only" in the instruction area (because it would be a security risk otherwise)?
In the simplest computers, there is no differentiation between code and data in the memory and the code is not read only. In more complex computers there is memory management hardware the enforces access restrictions of various memory ranges. This hardware is controlled by the OS to prevent bad memory access by user programs.
5) What loads a program into the Main Memory of a generic computer? Is it the operating system?
Yes, ultimately it is the OS that loads programs into memory and starts them running. This is usually done at the request of another program, like the command shell or desktop manager.
Reply | Threaded
Open this post in threaded view
|

Re: Some Generic Questions

invin
A follow-up question on (2)

In hack, a program does not terminate, instead, it is put into an infinite loop as explained in the 4th unit. Isn't there any way in the hack CPU to terminate the program and not put it into the infinite loop?
Reply | Threaded
Open this post in threaded view
|

Re: Some Generic Questions

cadet1620
Administrator
There is no way for a program to halt the Hack CPU.  (The hardware "reset" signal does halt the CPU by holding the PC at 0.)

In project 12 you will be writing the "OS" for the Hack computer in the Jack language. It includes Sys.halt() which is documented as "halts the program execution". The implementation of Sys.halt() is simply a while(true) loop.