Week 2 - Data Representation & Computer Architecture

Week 2 - Data Representation & Computer Architecture

Welcome again. In this article I will be discussing two broad yet very important topics for computers. Data representation and computer architecture.

Data Representation

Data representation is essentially how we represent data in computers. Computers use a binary representation (Base 2) of data and not what we as humans are familiar with (base 10). I’ll explain more what each of these are.

Base 10

Base 10 is the numbering system we use. We are used to counting from 0 - 9. Now you might be wondering, how did this come about? Look at your hands, you have 10 fingers! Naturally, we just developed this way due to our anatomy.

Base 2 - Binary

Base 2 is the numbering system used by computers. It only uses two values 0 and 1. This system is very simple and perfect for electrical systems because each value represents on and off. 0 meaning off and 1 means on.

How to calculate binary?

Converting binary to a number representation can be seen as difficult first, but once you get the hang of it, its quite straightforward. Note: it does require some form of math.

Each value of a binary number is 2 to the power of n, where n is the digit placement starting from 0.

For example, the binary number 0010 can be broken down as follows.

  • 0 = 0 * 2^0

  • 1 = 1 * 2^1

  • 0 = 0 × 2²

  • 0 = 0 × 2³

0010 is equivalent to 2. Pretty simple right.

Computer Architecture

Now I will go into the world of computer architecture. In this section, I will discuss what is computer architecture, what is microarchitecture, the different compiler options we have, the commands within a commonly used compiler, the stages of compilation, features and optimizations, and dumps (within the compiler context, of course).

What is computer architecture?

Computer architecture is the design of the computer. Also when we use this term we mainly talk about the CPU, we don’t care about the peripherals.

Microarchitecture

In simple terms, this is the model of the CPU we are dealing with. For example, we might have the 6502 processor and a 6502C prorcessor. These are different because of its microarchitecture. In addition, the instructions that exist on the newer 6502C processor may not be available on the old 6502 processor.

Compiler Options

A compiler converts high level programming into machine readable code. An example of a commonly known compiler is the GCC compiler.

When it comes to the 6502 processor, we have several commands for the compiler.

  • -o → Specifies output file

  • -g → Enables debugging information

The compilation process is a series of 5 stages. These are explained more below.

Compilation Stages

  1. Preprocessing → Done by gcc

  2. Compilation → done by cc1

  3. Optimization

  4. Assembly →done by as

  5. Linking → done by ld

Note: There are commands we can use that can alter the stages of compilation.

  • -E → Stop after preprocessing

  • -S → Stops after compilation but does not assemble

  • -c → Compiles but does not link

Features in a compiler

Did you know that the compiler also has many features we can turn on/off? This can be done using the -f flag followed by the feature.

  • -f [feature] → Turns feature on

  • -fno [feature] → Turns feature off

Optimization Levels

The compiler can make optimizations on your code to improve speed and efficiency. There are several levels of optimization which are as follows:

  • 00 → Very little optimization

  • 01 → Basic optimization

  • 02 → Default optimization

  • 03 → Aggressive optimization

Dumps

Dumps are files that tells us what our compiler has been doing with our code.

References

Cover Image was taken from: Image by freepik