The second part of the course will familiarise you with assembly language programming especially for the Texas Instrument MSP430 launchpad.
Week 1 Summary:
Computer architecture is defined as the computer as seen by assembly language programmers.So, here we will discuss which registers, among the many registers available inside a central processing unit (CPU), are accessible to assembly language programmers.
Computer organisation is defined as the computer as seen by hardware engineers. Here, we discuss the component of a computer from the perspective of hardware engineers.
There are two types of computer architectures:
1. The von Neumann architecture. It is the most popular, and used by personal computers. It is characterised by the fact that data and instructions are not separated in the memory. It is not possible to tell which one is data and which one is memory just by looking at the content of a memory location. It is the task of the instruction register and the instruction decoder inside the CPU to differentiate between data and instructions. It is worth mentioning that some instruction do contain data, which is called immediate data.
2. The Harvard architecture. It is mostly used in special-purpose processors such as the DSPs (Digital Signal Processors). It is characterised by the fact that it has separate memories for data and instruction. So, we can tell straightaway, if something is in data memory, then it must be data. If something is in instruction memory, then it must be an instruction.
Question : does this imply that the CPU of the Harvard architecture is simpler than the CPU of the von Neumann architecture?
The CPU and the memory communicates via three separate bussses
a. the data bus. It is bidirectional i.e data can move in both ways. During write : data moves from CPU to memory. During read : data moves from memory to CPU.
b. address bus. It is unidirectional from CPU to memory and contains the address in memory which CPU neeeds to access.
c. the control bus. It is bidirectional. Control moves from CPU to memory. Status moves from memory to CPU.
There are two type of instruction sets:
1. CISC (Complex instruction set computer) : a large number of instructions, and a small number of registers.
2. RISC (Reduced Instruction Set Computer) : a small number of instructions, and a large number of registers.
As a comparison, imagine you have CPU1 which has a multiply (*) instruction and CPU2 which does not have a multiply instruction, but instead has an addition (+).
To do 5*7 = 35 on CPU1, you need only one instruction
To do 5*7 = 35 on CPU2, you need 6 instruction (5+5+5+5+5+5+5), or 4 instructions (7+7+7+7+7)
- which one is better RISC or CISC?
- which one is faster RISC or CISC?
- does CPU2 need to compare the two numbers, and then add repeatedly the bigger number, instead of the smaller number to get speed up?
- DSP is dominated by multiply (*) and accumulate (+) instructions. Is it the reason why RISC has been used?
Week 2 Summary :
Computers run programs. Programs implement algorithms. Algorithm is a sequence of instructions. Instruction tells the computer to move data from one place to another (memory to register, register to memory, register to register), to process data (add, sub, mul, shl, shr etc).
ALU (Arithmetic and Logic Unit) is that part of the CPU that does data processing and conversion. ALU is a multi-function unit. ALU, based on the command from processor, does different things at different times. ALU has two data inputs, one control input, and one result output. Do we need other output?
A comparison is done by a subtraction. For example, COMP A, B , is done by A-B gives D. D can be 0, <0, or > 0. D = 0 means A = B. D < 0 means A < B. D > 0 means A > B. From the value of D, there is no way the computer knows the comparison result just by looking at D. So, other things are required. They are the flags. Flags can be
- N (Negative) : If N = 0, then D must be positive. If N = 1, then D must be negative
- Z (Zero) : If Z = 0, then D must be non-zero (positive or negative). If Z = 1, then D must be zero
- V (overflow) : If V = 0, then there must be no overflow. If V = 1, then an overflow happens. An overflow happens when adding two positive numbers gives a negative number or adding two negative numbers give a positive number. How negative numbers are represented will be discussed later.
- C (Carry) : If C = 0, there is no carry. If C = , there is carry. A carry happens when adding two numbers of n bits give a result in n+1 bits.
- X (eXtended Carry) : like Carry, but for BDC (Binary Coded Decimal) numbers
So, to know the result of a comparison, we look at the flags.
- When N = 0 and Z = 0, the result is positive (A > B)
- When N = 0 and Z = 1, the result is zero ( A = B)
- When N = 1 and Z = 0, the result is negative (A < B)
- The case in which N = 1 and Z = 1 should never happen (you can not have negative zero. It is just zero!
An instruction (in C language) such as i := i + 1; means the number 1 is stored in the same area as the instruction. Number one is carried by the instruction. Adding 1 to a number needs no ALU. It can be done by incrementation. An instruction that carries data is in an immediate addressing mode.
An instruction (in C language) such as const x = 12; means that the number will be stored in an area separate from the instruction. An instruction may refere this number using many ways such as an absolute addressing mode, indirect addressing mode, relative addressing mode, etc. More on addressing modes later ! .