ECE 374: Computer Organization
Intro to Computer Organization
We will be using MIPS assembly language for this course.
General purpose systems Embedded systems
CPU - Center or heart of the system
CPUs are made up of control units, registers, and arithmetic logic units (ALU). All that processors can execute is the machine code, which is in binary. As an abstraction, you can create machine code from assembly language, which is made from high-level languages. To do these translations, we use a compiler. The assembly is converted to machine code using an assembler.
Arithmetic Operations
All operations are done by the ALU, as the name implies. Registers are used to store the data that is being operated on. Finally, the control units control the whole process and tie everything together.
Assume you have the C code a = b + c
. To execute this, you have to first transform the high level C
to an assembly language. This would convert to something like add a, b, c
.
Assume you have the C code a = b - c
. To execute this, you have to first transform the high level C
to an assembly language. This would convert to something like sub a, b, c
.
Now, assume you have the C code f = a + b + c + d + e + f
. To execute this, you have to first
transform the high level C to an assembly language. However, you can only add two numbers at a time.
So, to convert this, it would look like:
add r1, a, b
add r2, c, d
add r3, e, f
add r4, r2, r3
add f, r1, r4
Notice how most operations follow the format of <operation> <destination>, <source1>, <source2>
.
Register
Registers are stored in a register file, which is just a collection of a bunch of registers. Usually there is $n$ registers on a $n$-bit machine. Since we are using MIPS, there are 32 registers in the register file.
Example
C code:
f = (g + h) - (i + j);
We first have to break down the C code:
$s0 â g
$s1 â h
$s1 â h
$s2 â i
$s3 â j
$s4 â f
$t0 â $s0 + $s1
$t1 â $s2 + $s3
$s4 â $t0 - $t1
ASM Language:
add $t0, $s0, $s1
add $t1, $s2, $s3
sub $s4, $t0, $t1
Memory
This is where data needed to run programs is stored. It is more long-term than registers. It is much larger than the register file. On a 32-bit system, there can be up to $2^{32}$ different locations.
This MIPS ISA is big endian and uses 1 byte addressing. (Each memory location stores 1 byte (8 bits)).
To transfer data from memory to the register is called loading and to transfer from the register to the memory is called storing.
An example usage of memory is when storing an array. An array of non-byte types is stored as an array of $nm$ where $n$ is the size of each element and $m$ is the size of the array. The address of each element can be calculated by doing $a+(ni)$ where $a$ is the address of the array and $i$ is the index of the element.
Example
C code:
g = h + A[8];
First, we break down the C code. Assume 8 + A = 32
:
$s0 â g
$s1 â h
$s2 â load 32
$s0 â $s1 + $s2
ASM code:
lwto 32, $s3
add $s0, 32 ($s3)
add $s0, $s1, $s0