3. Registers

Low level languages make direct use of the hardware within the CPU. This means the programmer needs to know a lot about the the internal structure of the CPU in order to write low level code.

In particular, she needs to know about the registers within the CPU

Registers in a CPU

A register is a discrete memory location within the CPU designed to hold temporary data and instructions

.A modern CPU will hold a number of registers. There are a number of general purpose registers that the programmer can use to hold intermediate results whilst working through a calculation or algorithm.

Then there are special-purpose registers designed to carry out a specific role. Each of these registers are given a name so that the programmer can write their software code to access them. Different manufacturers of CPU chips call them by different names (which makes life interesting for a professional programmer!)

Generally these include

Accumulator

This is one of the general purpose registers but it is specifically used to 'accumulate' the result of the currently running instructions.

For example, a small piece of code needs to fetch a value from main memory and then add 3 to it and finally store the result back into memory. The accumulator will be used

LDA 3001 This instruction will load the data at address 3001 into the accumulator
ADC #3 This instruction adds 3 to the content of the accumulator
STA 3001 This instruction stores the content of the accumulator into main memory at location 3001

Program Counter

This holds the memory address of the next instruction.

For example if the program counter has the address 305 then the next instruction will be at location 305 in main memory (RAM). When a program is running, the program counter will often just be incrementing as it addresses one instruction after the other, e.g. 305, 306, 307. However, the instructions will often modify the next address, for example, 305 becomes 39. What has happened is called a 'jump instruction'. This is how the software programmer will cause different parts of his code to run depending on some condition e.g. a conditional IF statement. It is also how an interrupt routine is serviced. The program counter will be loaded with the starting address of the interrupt routine.

 

Challenge see if you can find out one extra fact on this topic that we haven't already told you

Click on this link: Program Counter

 

Instruction Register

This holds the current instruction to be executed, having been fetched from memory.

 

 

 

 

Copyright © www.teach-ict.com