Articles with Tags '68000 '

Development languages

I "resurrected" my article written a few 'years ago. I've slightly revised, updating a little bit here and there, but I think it is still relevant and interesting.

INTRODUCTION

What is a development language? A computer, alias PC (Personal Computer), has its own personal language. This language is called machine code, to mean that every machine, so any computer (PC compatible, Apple, Unix, etc ...), it has one exclusive owner. The programs that we see "turn" on our PC are mainly carried out by the mysterious object called a microprocessor. This is the heart, the intelligent unit, of each electronic processor. In reality, an application is not executed only by the microprocessor but leans, so to say, in what is called the operating system: a layer software provided by the manufacturer of the machine (see, for example, the Apple Macintosh).

Continued ...

Constants and variables: what is the real difference?

It seems obvious, but some escapes the subtle difference between constants and variables in a programming language. The constants, from the name itself, do not change their value during the cycle of a program, while variables can do it! Often, however, happen to use variables instead of constants without realizing it, also because this does not impact the logic of an application. Despite this, the difference between constants and variables in there and it shows all compile-time, where the constant plays a role you certainly more efficient.

Coming from the Assembly programming or C knows the difference between constants and variables, especially because, both in Assembly and C, constants play a role by MACRO. For MACRO indendo a "piece of code" that is labeled and replaced within the code at compile time. The compiler, in short, performs a sort of find .. replace (and is sostituitsci) in the code every time it encounters a constant.

Imagine you write in C the following simple piece of code:

1
2
3
4
5 ; int a = 5;
3 ; int b = 3;
int c;
b ; c = a + b;

sono indicate come variabili in questo caso. Both a that b are indicated as variables in this case. In C, in fact, constants are defined with the keyword #define . sono state definite come int . We note immediately that it is a that b were defined as int . Already here you can operate a first optimization. If we know that our variable a never exceed a certain value, it is good to declare it properly and do not use data types at random. Some developers do not bother to declare the correct types, thinking that this does not affect performace! Wrong! Alternatively, it is acceptable that the first draft of the code does not involve this level of detail. However, it is a good rule, during the development process, review the code and verify the data types.
However, in an assembly of the Motorola family, for example, as the mythical 68000, our code would seize compiled (no optimizations) in a kind of:

1
2
3
4
, d0 ; int a move. l # 5, d0; int
, d1 ; int b move. l # 3, d1, int b
d2 ; int c - foo move. l d1, d2, int c - foo
l d0 , d2 ; risultato in d2 ovvero c add. l d0, d2, d2 or result in c

or:

1
2
3
, d0 ; int a move. l # 5, d0; int
, d1 ; int b move. l # 3, d1, int b
d1 ; risultato in d1... move. l d0, d1, d1 result in ...

The compiler, however clever, fatigue in optimizations, then write the code with the right keywords can only help to improve the compiled output. In our case, if the value is a constant 5 is not convenient to use an integer variable, since the compiler, appropriately, whereas the variable variable, precisely, predisponde a whole to contain the simple value of 5, which in binary is 101, ie takes 3 simple bit (if anything int is a 32bit or a 53bit worse double-precision floating-point!). If we had written the code like this:

1
2
3
4
5
# Define MIA_COSTANTE 5

3 ; int b = 3;
int c;
b ; MIA_COSTANTE + c = b;

The compiler would have known from the beginning that MIA_COSTANTE , being constant, the value will not change so I can reserve less space to treat it. In practice the Assembly code diverebbe:

1
2
3
d0 ; la "q" indica una istruzione "quick", cioè che tratta valori compresi tra -128 e +127 moveq # 3, d0, the "q" indicates an instruction "quick", that is values ​​between -128 and +127
, An instruction "quick" takes less CPU time (4 clock cycles in this case)
d0 ; anche qui uso una istruzione "quick" addq # 5, d0; here also use an instruction "quick"

This code is extremely faster and takes up less bytes. What you have to keep in mind is that when you declare a variable environment is ready to treat it as such, even though today's compilers are able to do miracles, performing a series of steps in the code before compiling (some compilers even perform a sort of program simulation to optimize the compilation into machine code).

A good rule, therefore, is to declare the right kind for our variables, whether these are. Alternatively use the constants, especially if the programming language that we are using the expected (as in the case of the new Flash CS3).

Continued ...