Friday, June 17, 2011

Operating systems - 2

Well, first of all, let me announce you, the availability of free code for the assignments you find in the standard Galvin book in the link below


Incase, if you are having the Operating systems course to study, these are the likely code snippets you will be given home work for.

Today, let's discuss some more things about operating systems.This is the def of operating system

"Operating system is a software, that makes the hardware do useful things"

There are many more definitions of it, but let's stick to this.One more thing most computer science students or IT students including me, when we join college is to fascinate of building an operating system entirely from scratch, knowing each and every detail.

If you try to do the above said thing, you will either become a mad person or get addicted to some other things in life.What I want you to learn is that, building every thing from scratch is not needed today :)

For example, let me give you the example of Linus Torvalds.He did not entirely build the Linux as people think.He used internet to connect with people and gather useful piece of code he needed, and using some of the code, that is already generated, he prepared Linux. I am not telling you to copy the code, but to steal it.In a sense, that you make it more beautiful.In the words of Picasso


"Good artists copy, great artists steal"

Learn to reuse the code and build something on top of it, which makes the software more usable or will be better than that software.And this is what, you cannot do with proprietary software.I recommend you to switch to one of open Source OS and start altering their code or the software you install in them.You willl really gain a lot of insight and knowledge into it.

Loaders - 2

Well, let's go into the boring facts of loader, which you need to learn even if you are unwilling.I'll try to make them interesting though



There are three main types of loaders.Their names and definetions are as follows :

Absolute Loader : As the name itself says, it does nothing other than loading

Relocating Loader : This loader, helps in the relocation of program in main memory (just in case a program needs to be moved up and down in memory)

Generally this task is performed by Assembler, but here relocating loader takes care of that



Direct Linking Loader : This loader, helps in loading the linked subroutines dynamically.It means that if a program is made from a lot of sub routines, each subroutine is treated as a separate program that needs to be loaded as and when linked or needed.

Also remember, there are four main tasks of a loader


Allocation - Allocate space in main memory for program

Linking - Join the linked subroutines to the program

Relocation - Change the mnemonics, that change with their location

Loading -Loading the program to main memory in the allocated space


Let's take a quick look of our three loaders absolute loader, relocating loader and direct linking loader respectively for the above four functions


Allocation - Programmer, Programmer, Programmer
Linking - Programmer, Programmer, Loader
Relocation - Assembler, Loader, Assembler
Loading - Loader, Loader, Loader

Let's take a look into the linkers tommorrow and from the next monday, you will be starting to learn to build system softwares

Thursday, June 16, 2011

Loader

Let's start with the definetion of loader.

"A loader is software or program that loads the compiled or assembled program into main memory and initiates the execution"

If you are a computer science student, you must have already come across Von Neumann's architecture, if not, here's the def

"The von Neumann architecture is a design model for a stored-program digital computer that uses a central processing unit (CPU) and a single separate storage structure ("memory") to hold both instructions and data " (source:Wikipedia)

For those of you who couldn't grasp it, it simply states that a program must be stored in primary memory or RAM, that is seperate from secondary memory or harddisk, inorder to be executed.



This thought revolutionarised the computer industry, and to this date, computers are built based on this architecture.Also this is an important interview question often tossed by interviewers, but the candidates are always strike out for this.So keep this thing in your memory.

Although today's computers made more complex architectures for their own purpose, the base of all these is the Von Neumann architecture.

I think you already grasped the need of a loader by now.Since the program originally is stored on hard disk and need to be transferred to RAM as per our architecture, loader helps in doing so.

Is my desk calculator a computer ?
Yes, definitely, but the important contrast between it and your computer is the architecture.Your computer uses Von Neumann architecture, while your calculator uses fixed program architecture (a program can be run from with in hard disk)

If a program can be run directly from harddisk, then you may ask, why this Von Neumann architecture, what is the need for loaders and why are you trying to teach us all these..

Well,  the answer comes from history.The first computer ever that was built is ENIAC in 1949. It used fixed program concept.Fixed program in the sense, it's harddisk is prepared in such a way, that it can run only one type of program.If you want to run a different program, you need to rewire, restructure and change the design.It took atleast three weeks gap to run two different programs in ENIAC.

That is the reason, why your computer can be both calculator and wordprocessor or browser or anything, but a calculator can only be a calculator.

Tommorrow, let's go some what deep into the loaders and learn about different types of loaders and their uses.

Tuesday, June 14, 2011

Operating Systems - A win or loss of mankind

Operating systems play an important role in our day to day life.Although our primary topic is systems programming, let's discuss the operating systems for every two posts, so that it can be on par with other system softwares.

Let's go back into the history.In 1950's, there were only few computers available and that too for defense or scientific purposes.Many people including big companies, thought that computers were meant for that.But the invent of machines like Altair in the late 1970's revolutionized the computer industry.It showed that a computer can be personal, and could serve the needs of common people.The invent of personal computer and Mac, both in early 1980's completely took the industry by storm and with in five to six years, they have shown a new way for industries.In the olden days, to establish an industry, it would require generations of wealth or should be influential to get bank loans.But, Bill Gates and Steve Jobs have shown."Oh, we don't think so".For the story of Steve Jobs and Bill Gates watch the "Pirates of Silicon valley" movie.Below is the link for it.


And lo, the operating systems were born.And they started growing like anything, giving huge profits to their creators and creating a new kind of jobs called software engineers and finally they became a brand themselves.But it's needless to say, because of these so called WONDERFUL things, many people in colleges started enrolling in computer courses.I am also one of them :)

But you know what, there is also the other side of the coin, not many people mention or dare to talk about.Before computers came, majority of the people used to take sciences, physics, chemistry, mechanics as the preferred courses, and so during the time between 1900 and 1980's a lot of good scientists were born and NASA also got quality people who could send man to moon.Do you know when the last manned mission to moon happen ?

It happened in 1972 (Apollo 17)

Looking at the other side of coin, I always fear what will happen to this world, with the lessening of scientists and the people pursuing research as their goal of life like the kinds of Einstein, Edison, Ford, Wright brothers and lot more.

You may say that many people are taking courses other than software engineering, but my say is that most of them are ending as software engineers.Also I am trying to say, other courses also should be given equal preference

Monday, June 13, 2011

Assembler - 2

In the end, we will be making an assembler for IBM - 360.It took me a week to study about it and make it in pure C language, of you are really interested or taking an under graduate course in the coming semesters, I recommend you to buy this book.Here's the Amazon link for it

Systems Programming

IBM 360 is one of those machines that came in 60's and was a very popular machine at that time, because it  provided interoperability between different machines.Also it is one of the main reasons for the development of assemblers, compilers and so on.






Saturday, June 11, 2011

Assembler

This is a very big topic to discuss and hence in this post and the next we discuss about it.This is the def of assembler

"An assembler is a program that converts an assembly level language code (also called as mnemonic code) into machine language code and provides necessary information for the loader to load the programme."

In your day to day life of programming and all, you never come across using this system software anytime.This is because of the compiler which does the same thing, but can convert high level languages to machine languages unlike assembler which can only convert middle level (mnemonic) code to low level (machine) code.

If you are using micro processor and have done some coding, the coding you did is in assembly language.After the invention of compiler, even though assembler became obselete, for device like micro processor which require frequent compiling or assembling, assemblers are still used.Remember compiling is costlier than assembling.


Let's go into the history part of assembler.In the earlier days, people used to write the code in machine language involving 0's and 1's or in hexadecimal format, the only language that a computer can understand till date (seriously).The coding was very tedious and people need to constantly refer the documentation or need to remember a lot of code.

Machine code



The remedy came in early 1960's in the form of assembly language, that contain the parts of code that could be easily remembered in a native language like english.To convert that assembly code into machine code assembler was used.Later on high level languages were invented that were very much close to the native languages (C, C++, Java) and compilers to compile them, that's a whole different story

An example of C-language code with assembly code below (Courtesy : CISE.UFL)

That's all for today, let's talk more about assembler with some code segments as examples.If you have any queries or suggestions for improvising the content, post them in the comments section

Friday, June 10, 2011

Macro Processor

Macro Processor is a program that lets you define the code that is reused many times giving it a specific Macro name and reuse the code by just writing the Macro name only.

Generally it doesn't come as a separate program but as a bundle to either assembler or compiler

Note : Please don't confuse Macro Processor with Micro Processor, remember Micro Processor is a hardware device and it's a completely different area of study

There are three main steps of using a macro

1.Define the macro name
2.Give it's definetion
3.Use the macro name from with in the program anywhere to use it's definetion (this step is called macro call)

And the most important thing is that, macro processing is done before the compilation replacing the code in place of macro calls and deleting macro definetions.If you are on an open source OS, this can easily be tested.For others, this is how it happens.This is my helloworld programme


#include<stdio.h>
#define hell printf("\nHello world\n");printf("I am a good boy\n\n");


int main()
{
hell;
}

Now there is are a lot of options in gcc compiler and if you use gcc helloworld.c -E , it gives you the code that is processed before it is passed to the compiler.It includes a lot of things along with the code.But since our main discussion is about Macro processing, let's see how the macro processed code looks like

# 916 "/usr/include/stdio.h" 3 4

# 2 "helloworld.c" 2


int main()
{
printf("\nHello world\n");printf("I am a good boy\n\n");;
}




You can clearly see that macro processing is already done replacing hell with the corresponding macro definition.This is passed onto the compiler which does the remaining job. This is the compiled output


Hello world
I am a good boy



Note : There are a lot of interesting things gcc command does apart from compiling type gcc --help for more info
Gcc logo

There are a lot more uses for macro and don't confuse functions with macros even though both are used for same purpose and if any one asks you the difference tell them, the things I showed you above, function gets compiled but a macro gets macro processed

One important use of these macros is for booting.During the boot time, the system uses a lot of macros to get itself started since they need not be compiled to use, but just macro processing is enough which is a small task

So, for today, alvida guys, thanks for baring with me, and if you have suggestions pass the comments as you like and hit the +1, button below this post, if you want you can post this one to your friend, since I have enabled posting, see the social buttons for all the things you need.

Wednesday, June 8, 2011

Text editor

Let's speak of the text editor, the most basic of the System Software, what's the need for it and what's the GAG

The basic aim of the text editor's is that of processing the text, so in your every day life, the notepad you see is a text editor, Gedit is a text editor, Emacs is a text editor, Vim, MS Word, Open office word processsor ... any software or programme that can be used to edit or process the text is called text editor.

Mostly from the olden days to till date, these are used to write programmes by devs, which also became the basic tool for constructing different kinds of documents, that you come across in your day to day life.And mostly these come bundled with compilers and various word processing programmes.Consider the below cases as examples


  1. Visual Studio's text editor is the most robust one and user friendly built till date, since it incorporates every other system software ( except OS) in it.The best thing about it is, you need not bother about syntax errors, just like the spell checker in MS Word, it underlines when ever you do a mistake ( This is done by a special system software called interpreter that is normally absent in other editors )
  2. Open source has a small yet powerful competitor in this arena, the Vim editor, it has syntax highlighting (This is done with the help of different colours ), but no suggestions are shown as VS.And the best thing about this is it is the most powerful and fastest one, if you know the commands (Yup, faster than VS in this aspect).But it doesn't have any built in compiler
  3. Other programmes like Codeblocks, Dev CPP, Free C have the compiler functionality inbuilt into them


If you want to learn about the cool things that you can do with Vi editor (normally available in open Source OS), follow this link

http://flylib.com/books/en/1.533.1.24/1/

Inside that there is a link for Emacs editor also

And about Visual Studio, there is a hell lot of people out there, and basically it's not a text editor, but a software to build microsoft software with ease and it has the coolest IDE on earth. If you want to learn more about it, there are official Microsoft videos available  to get you started and keep going.You can even download them, if you wish

http://msdn.microsoft.com/en-us/vstudio/ff459609

And I presume you already know how to use a notepad :)

Let's talk about the Macro Processor in the next post

System softwares - their actual definetions


Well, let me give the exact definetions of the so called systems softwares

1.Text editor : This is the software that can be used to process the text
eg : Notepad, MS Word, Gedit etc.,

2.Macro Processor : This is the software or just a program that lets the user define macros and use them in the remaining part of code.
eg : The #define you use in C-language

3.Assembler : This is the software, that converts the code, written in Assembly language to machine language.
eg : BASIC-LT, Boreland C

4.Loader : This helps in loading the assembled machine code into main memory for processing
eg : Windows MBR/Boot loader that loads the OS into main memory when you start your system

5.Linker : This is useful for linking of various seperately assembled machine codes and generally done before loading
eg : Linkage Editor of IBM 360

6.Compiler : It converts the high level language code ( C, C++, Java ) into an assembled code or it generally performs assembling part also and provides necessary information for the loader to load the program and linker about the external references with in the program
eg : GCC

In the general sense or in the real world examples, none of this comes seperately, but mostly you will se bundled applications. Take for the example, codeblocks or devcpp or Turbo C

You can write the code in the editor, can define macros, compiling can be done and the program can be loaded in place.

And regarding Operating System, we will discuss it at the end of all the postings, since it is as significant as all of these above programs (softwares) combined. And in the next post, let's discuss of the theoritical aspects of each of these softwares in detail

System Software

I am not gonna say any definition for it, since I personally don't know much about it.Here's the simple def, that came to me by experience

A System software is any software, that acts as a mediator between the kernel (Hardware part) and the user and makes their interaction easier.

Def is ok, but what in the real world does this word relate to

In the real world, it relates to the following important softwares

  1. Text editor (Notepad, Gedit, MS Word etc.,)
  2. Assembler
  3. Macro Processor
  4. Loader
  5. Linker
  6. Compiler
  7. Operating System

Most of the words except OS and Text editor, may be trivial
to you.They were trivial to me also, six months ago, but now I am a lot more confident on what each term implies and had even built the first three of the above said softwares.I want you also to do it ...

In the next post, let's discuss of the definetions of thes
e softwares and start dissecting Systems ( I mean your discriminating knowledge about them :))

Just a small exercise for you, till I post the next one, see the below picture, and keep guessing what it implies and fill the comments..

Systems Programming - Foreword for this blog

Well, this is kind of joke, living in the web world talking of systems programming.Yeah, I agree with you, since most of the programs and features that are available today are being exported to the cloud and there is nothing to lose or gain from your system and for a simple PC enthusiast it is of no importance. Yes, this is true.

All services are moving towards cloud.But what's the gag ???

The gag is that it is not for simple PC ENTHUSIASTS any more.How ever, the programs need to run some where, even in the cloud.This means, this topic is not going to be any more with regard to systems but should be renamed as server programming. Well, since our academic courses are not going to be changed so suddenly like the web 2.0 or 3.0 or facebook or twitter, it will take a gradual time of minimum 10 years for it.So till then we can have a cook of systems programming.

I will give small, but enough details to get you started with systems programming and at the end will give you enough details about systems software, so that finally you will create atleast two systems software in the end.