Here we have a simple CPU. The CPU looks a bit like the Z80 CPU on which I used to work some time ago, but it is more simple. It has 7 registers A,B,C,D,H,L. The registers are internal CPU memory locations used in arithmetical/logical operations and as temporary data storage space. Each register stores a byte (8 bits). Registers (B and C), (D and E), (H and L) can be treated like 16 bit registers in which case they are called BC, DE, HL. B,D,H hold the most significant 8 bits of the 16.
  PC is the Program Counter. At the beginning it has a value of 0 (zero). Each step, the CPU reads the instruction in the memory at the address [PC] and executes it. The PC register is then automatically incremented to point to the next instruction. The value of the PC register can be changed by a JuMP or CALL instruction.
  SP means Stack Pointer. The Stack is a data storage structure that works like a stack of normal objects, let's say plates. Possible operations on the stack are to add a plate on the top of the stack or to take the topmost plate out of the stack. The CPU stack is the same but it works with data instead of plates. The stack data is held in memory but the pointer that shows what is the memory address where top of the stack is, is in the CPU. The CPU stack is upside-down, which means that first data written on the stack will be at higher addresses, and the value of SP gets smaller as the stack is filling up. To write data on the stack you use the PUSH instruction (like PUSH BC: puts the value of the BC register on the stack). To extract data from the stack you use the POP instruction (like POP BC: extracts the last value from the stack and puts it into the BC register).
  The Decode unit decodes the instructions to be executed.
  ALU means Arithmetical/Logical Unit. It is used to perform mathematical operations.
  The FLAGS are used to store extra information about the result of the last mathematical operation. There are only 3 flags defined for this processor: Z,Cy,O. "Z" is the zero flag; it is set if the result of the last operation was zero. "Cy" is the carry flag. It is set if after an addition or substraction, from the most significant bit appeared transport which cannot be stored in the result register. "O" is the overflow flag. It is set if the result taken as a signed integer does not fit in the result register.
  The flags are used for conditional jumps. For example the instruction JMP Z,100 means "if the result of the last operation was zero, jump to the address 100"
Here you can see a CPU emulation. You will need JavaScript to run it. It is pretty nice but it will take some time to load

previous home next
Hosted by www.Geocities.ws

1