Thursday, January 7, 2010

How the CPU Executes Program Instructions



How Computers Work: The CPU and Memory


Figure 2: The Machine Cycle

Before an instruction can be executed, program instructions and data must be placed into memory from an input device or a secondary storage device (the process is further complicated by the fact that, as we noted earlier, the data will probably make a temporary stop in a register). As Figure 2 shows, once the necessary data and instruction are in memory, the central processing unit performs the following four steps for each instruction:
  1. The control unit fetches (gets) the instruction from memory.
  2. The control unit decodes the instruction (decides what it means) and directs that the necessary data be moved from memory to the arithmetic/logic unit. These first two steps together are called instruction time, or I-time.
  3. The arithmetic/logic unit executes the arithmetic or logical instruction. That is, the ALU is given control and performs the actual operation on the data.
  4. Thc arithmetic/logic unit stores the result of this operation in memory or in a register. Steps 3 and 4 together are called execution time, or E-time.

The control unit eventually directs memory to release the result to an output device or a secondary storage device. The combination of I-time and E-time is called the machine cycle. Figure 3 shows an instruction going through the machine cycle.

Each central processing unit has an internal clock that produces pulses at a fixed rate to synchronize all computer operations. A single machine-cycle instruction may be made up of a substantial number of sub-instructions, each of which must take at least one clock cycle. Each type of central processing unit is designed to understand a specific group of instructions called the instruction set. Just as there are many different languages that people understand, so each different type of CPU has an instruction set it understands. Therefore, one CPU-such as the one for a Compaq personal computer-cannot understand the instruction set from another CPU-say, for a Macintosh.
Figure 3: The Machine Cycle in Action

It is one thing to have instructions and data somewhere in memory and quite another for the control unit to be able to find them. How does it do this?

Figure 4: Memory Addresses Like Mailboxes
The location in memory for each instruction and each piece of data is identified by an address. That is, each location has an address number, like the mailboxes in front of an apartment house. And, like the mailboxes, the address numbers of the locations remain the same, but the contents (instructions and data) of the locations may change. That is, new instructions or new data may be placed in the locations when the old contents no longer need to be stored in memory. Unlike a mailbox, however, a memory location can hold only a fixed amount of data; an address can hold only a fixed number of bytes - often two bytes in a modern computer.

Figure 4 shows how a program manipulates data in memory. A payroll program, for example, may give instructions to put the rate of pay in location 3 and the number of hours worked in location 6. To compute the employee's salary, then, instructions tell the computer to multiply the data in location 3 by the data in location 6 and move the result to location 8. The choice of locations is arbitrary - any locations that are not already spoken for can be used. Programmers using programming languages, however, do not have to worry about the actual address numbers, because each data address is referred to by a name. The name is called a symbolic address. In this example, the symbolic address names are Rate, Hours, and Salary.

Wednesday, January 6, 2010

Linux Commands

Linux Commands I Hardly Knew


Ubuntu
How To Enable Vi Syntax Highlighting In Ubuntu
sudo apt-get remove vim-tiny
sudo apt-get install vim
sudo vi /etc/vim/vimrc
( Remove the quote mark from the "syntax on" line, uncommenting it)

Adding Environment variables...

$ echo 'export GOROOT=$HOME/go' >> ~/.bashrc
$ echo 'export GOOS=linux' >> ~/.bashrc
$ echo 'export GOARCH=386' >> ~/.bashrc
$ echo 'export GOBIN=$GOROOT/bin' >> ~/.bashrc
$ echo 'export PATH=$PATH:$GOBIN' >> ~/.bashrc
$ . ~/.bashrc

You can source the files instead of restarting the machine:
source /etc/profile
source ~/.bashrc

ALLOWING OTHER USERS TO RUN SUDO

By default, only the user who installed the system is permitted to run sudo. To add more administrators, i. e. users who can run sudo, you have to add these users to the group 'admin' by doing one of the following steps:

sudo adduser username admin

To enable the root account (i.e. set a password) use:

sudo passwd root

Afterwards, edit /etc/sudoers and comment out the line

%admin ALL=(ALL) ALL

to disable sudo access to members of the admin group.

Context Free Languages

Tuesday, January 5, 2010

The Go Programming Language

Matsumoto Yukihiro(Matz) - Ruby1.9

Ruby On Rails





Understanding Python

Guido van Rossum - Author of Python




Interview With Guido van Rossum

Part I: The Making of Python

Part II: Python's Design Goals

Part III: Programming at Python Speed

Part IV: Contracts in Python

Part V: Strong versus Weak Typing

Part VI:Designing with the Python Community

Towards a Standard Parser Generator

Abstract

Developing parsers for "little" languages is a common task for many software developers. People have frequently requested inclusion of a specific parser generator framework into the Python library. In this paper, we compare several Python parser generators, using the XPath language as an application. Criteria for comparison are ease of use, performance, and ease of deployment. Using these criteria, we give a recommendation for including parser generators into the standard library..

Keywords: Parsers, XPath, YAPPS, Spark, BisonGen

continue...

Algorithm Education in Python

Abstract

Design and analysis of algorithms are a fundamental topic in computer science and engineering education. Many algorithms courses include programming assignments to help students better understand the algorithms. Unfortunately, the use of traditional programming languages forces students to deal with details of data structures and supporting routines, rather than algorithm design. Python represents an algorithm-oriented language that has been sorely needed in education. The advantages of Python include its textbook-like syntax and interactivity that encourages experimentation. More importantly, we report our novel use of Python for representing aggregate data structures such as graphs and flow networks in a concise textual form, which not only encourages students to experiment with the algorithms but also dramatically cuts development time. These features have been implemented in a graduate level algorithms course with successful results.

continue...

Saturday, January 2, 2010

Ruby Basics



Ref - http://remi.org/