Sunday, March 11, 2007

Interpreter

So what is an interpreter then ? The interpreter is a program that interpret some programing language. The don't translate the language in to binary code they just read a instructions and act according. So every time it you run a program in an an interpretors make the decision every time. This make it slower to run but has some advantage, one of this is that it don't take time to compile the program, so is easy to modify the program a lot of time. Also the best advantage is that it run an every kind of computers. The computers have different languages, so for example a PC use a different language than an Macintosh. So using the same program you can control in the same way all kind of computer that have a interpreter for that language.
One example of interpreted language is BASIC. Probably the most used interpreted language is PHP.

What is a computer.

Maybe some of you are wondering what is a compiler and why computer need to compile programs. Also what other methods to make some software exists.
A compiler is a program that translate translate the code form a programing language to machine code.
So for example the first language I had learn it was Pascal. Pascal language is very simple and straight forward, it was developed for scientific applications so the match teachers that didn't really now to much abut computers to manage to make programs to resolve mathematical problems.

program HelloWord;
begin
WriteLn("Hello Word !");
end.
Also another popular language, the one that all the serious programmers us is C or C++ ( an extension of C, evrything that work in C it work also in C++). So here is an example of simple program in C:

#include <stdio.h>;
int main(int argc,char *argv[])
{
printf("Hello Word !\n");
}


Ok, but the computer can't understand this languages, they only understand very simple instructions made by numbers. The closest thing to machine language is the Assembler language.

title Hello World Program (hello.asm)
; This program displays "Hello, World!"

dosseg
.model small
.stack 100h

.data
hello_message db 'Hello, World!',0dh,0ah,'$'

.code
main proc
mov ax,@data ; specify that we need to use the data segment defined by us
mov ds,ax ; ds - is the data segment

mov ah,9 ; Use the print function
mov dx,offset hello_message ; Specify what is our message.
int 21h ; Call the operating system function to print the message

mov ax,4C00h ; Specify the exit function
int 21h ; Call the exit function
main endp
end main


So this assembler language seem peaty simple also , isn't it ? So let's give some explanations. You know that it say that humans can only store 7 symbols in the short memory. So for exaple chose 7 symbols (animals , words , numbers , whatever) and after that look at a text an try to find the selected symbols in that text. You will have an hard time doing it. This is the psychological test you give for the driver license.
So the computers also have a short memory with with is working, this are registers. The name of this registers are AX,BX,CX,DX,ES,DS,CS,IP and so on. Also a small trick is that for example the registers are divided in two parts one for the important part and one for the small part, so for example the important part of the register AX is called AH and the not so important part is AL (High and low). Not all registers are formed form from tow parts.
So the computers execute instructions like MOV AX,4C00h. This is this means remember the number 4C00 (this is a hex number and it means 19456 in decimal base ... but usually is simple to write hexadecimal umbers because are shorter, and programmers are very lazy ). Also this instructions are translated in some numbers.
So the compilers translate form a readable language for humans in this computer language.