for Robot Artificial Inteligence

20. CPU - Registers

|

CPU - Registers

  • in computer architecture, a computer system memory is organized in a hierarchial oder by using of different levels of memories.

  • these memories can be classified depending upon the proximity to the CPU, access speed, memory size and cost of the memory.

  • A CPU register is a high speed memory area built right inside the processor chip and a very imporatant component of the CPU design.

  • the CPU memory unit consist of different types of registers and each of these register perform a specific function during process execution.

  • the CPU register are closest and the fastest memory areas as a part of CPU’s internal memory. the CPU has different types of registers and each of these register perform a specific function.

  • the CPU registers are placed at the top of the memory hierachy and closest to the CPU. Register provide CPU, the fastest way to access data for a processor.

  • Register are normally measured by the number of bits they can hold. For example, a 8-bit register means it can store 8 bits of data or 32-bit register means it can store 32 bits of data.

  • the number of register that a CPU has and the size of each register (number of bits) help determnine the power and speed of a CPU. for example a 32-bit CPU is one in which each register is 32 bits wide. therefore, each CPU instruction can manipulate 32 bits of data.

  • these registers are used to store the data temporarily during the program execution.

  • different processors can have different register size(16,32,64 bits) depending upon CPU architecture.

why register need?

  • the computer system memory unit consist of different types of memory arranged in hierarchical order depending upon the data access speed, distance from the CPU and size of the memory.

  • in computer system, a CPU register is a very high speed memory used to increase the execution speed of computer programs by providing quick access to the CPU to the frequecny used values.

  • every processor has this high speed local storage area known as a register that is used to holds the data which can be accessed by the ALU(arithmetic Logic Unit) which actually operates on this data as per the program instruction decoded by the CPU.

  • For ALU to perform any operation, the data must be first stored in a designated register where it can be manipulated by the processor.

  • For Example, to add two numbers in a arithmetic operation, the numbers are first stored in the registers as inputs where ALU performs arithmetic addtions and the results is sotred in another register.

  • the CPU register are divided in fi ve major categories depending upon the function assigned it and the visibility to the programmer:

    • General Purpose Registers
    • Pointer Registers
    • Index Registers
    • Segment Registers
    • Flag Registers

  • A modern CPU consist of number of registers. each of these register has specific purpose and function associated with it.

  • there are number of general purpose registers that the programmer can use to hold intermediate results while executing the program instructions.

  • 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 manufactures of CPU chip call them by different names depending upon their function.

  • User visible and modifiable
    • General Purpose Register(GPR)
    • Data Registers(Accumulator)
    • Address Register(e.g base addressing, index addressing)
  • Control Register(Not visible to the User)
    • Program Conunter Register(PC )
    • Current Instruction Register(CIR/IR)
    • Memory Address Register (MAR)
    • Memory Buffer Register(MBR/Memory data Register)
  • state register(visible to user but not directly modifiable)
    • Program status word register(PSW)

Functions of CPU Registers

  • all the data first must be represented in a corresponding CPU registers before it can be processed by the CPU. the CPU contains different types of memory register to handle different type of data and program instruction

  • User visible and modifiable
    • General Purpose Register(GPR)
    • Data Registers(Accumulator)
    • Address Register(e.g base addressing, index addressing)
  • Control Register(Not visible to the User)
    • Program Conunter Register(PC )
    • Current Instruction Register(CIR/IR)
    • Memory Address Register (MAR)
    • Memory Buffer Register(MBR/Memory data Register)
  • state register(visible to user but not directly modifiable)
    • Program status word register(PSW)

  • the MAR - Memory Address Register holds the address of memory where CPU wants to read or wirte the data. when CPU wants to store some data in the memory or reads the data from the memory, it places the address of the required memory loacation in the MAR register.

  • MBR - Memory Buffer Register OR MDR -Memory Data Register
    • when CPU performs instruction cycle the data or program instruction is fetched from memory and it is temporarily held in the MBR sometimes also called the Memory Data Register(MDR)
    • A “buffer” is a commonly used computer term to describe memory designed to hold data that is on its way to somewhere else.

  • the MBR/MDR contains the instruction and data retrived from the main memory which is than copied to the instruction register(IR) where the instruction is split inth the OpCode and Operand. the fetch part of the instruction cycle ends here. the Opcode is then decoded by the CPU decoder to perform the operation as program instruction.

  • insturction register : the contents MBR/MDR is transferred to a instruction register in CPU which holds the instruction to be executed by the CPU.

  • the instruction register breaks down the instrucion in two parts OPCODE and Operand. the OPCODE is interpreted by the CPU decoder as per the procssor’s instrucion set and the ALU - Arithmetic Logic Unit perform the operation on the operand (data/address). the result of this operation is temporarily stored in accumulator register.

  • Accumulator Registor

    • in CPU, an accumulator is a register in which intermediate arithmetic and logic results are stored during execution of instruction cycel and subsequently transferred to main memory RAM.
    • the result of this operation performed by the ALU is temporarily stored in accumulator register. without a register like an accumulator, it would be necessary to write the result of each calculation(such as addition, multiplication) to the main memory RAM.

Comment  Read more

19. CPU - types, speed, performance

|

CPU - types, speed, performance

  • the CPU understands only binary code that is 0 & 1. the CPU has two primary measures of speed :
    • integer Rate
    • Clock Rate
  • Computer commands are essentially just on and off commands, represented by one and zero, respectively which is binary code.

  • the integer rate describes how many on and off commands a CPU can handle at one ime.

  • Interger Rate Example
    • An 8-bit CPU can handle eight on and off commands at a time, whereas a 64-bit CPU can handle 64 on and off commands at a time.

  • Clock RATE : the Clock rate simply refers to how many times the integer rate can repeat in a second. the higher the clock rate, the faster the CPU.

  • the CPU performance:
    • there are four key facotrs about CPU architecture that affect the CPU performance
      • No or Cores(CORE = ALU + CU + Registers)
      • CLock speed
      • Cache Memory Size
      • Processor type.

  • CORES(CORE = ALU + CU + Registers)
    • First generation CPUs had a single core. that means the CPU had only one core inbuilt in to the processor chip
    • to increase the CPU performance, the manufactures added additional “cores” or central processing units. A dual-core CPU has two central processing units, so it appears to the operating system as two CPUs.
    • A different process can use each core at the same time. this speeds up our system considerably, because computer now process multiple programs simultaneously.
    • it is coomon for computers to have two(dual), four(quad) or even more cores. CPUs with multiple cores have more power to run multiple programs at the same time.
    • the clock spped is imporatant measure of speed of processor. the clock speed of a processor is how fast the processor can do the tasks while executing a program. the clock speed is measured in megahertz(MHz) or GigaHertz(Ghz).
      • 1 MHz - One Million clock ticks every second
      • 1 GHz - One billion clock ticks every second
    • this means that if one instruction was carried out every clock tick, a 3 GHz processor could execute three billion instructions for three billion clock ticks every second.

  • A CPU can contain more than one core. however, by simply doubling the number of cores will not double a computer’s processing speed. the CPU cores have to communicate with each other through channels and this uses some processing time of the CPU cores.
  • Multi-Channel memory architecture is a technology that increases the data transfer rate between the DRAM memory and the memory controller by adding more channels of communicatation between them. theoretically this multiplies the data rate by exactly the number of channels present.

  • processor types:
    • there are two main types of CPU
      • CISC - Complex instruction set computing
      • RISC - Reduced instruction set computing
    • Most desktop or laptop computer use CISC(Complex Instruction Set Computing) architecture made by Intel or AMD.
    • whereas Smartphones and tablet use RISC by ARM architecture

Comment  Read more

18. CPU-instruction Cycle step by step

|

CPU-instruction Cycle step by step

  • the CPU is executes only one part of instruction at a time but CPU can perform all lightening speed and it can execute millions of such part instructions in just one second.

  • therefore, this high speed of execution creates an illusion that all program are running simultaneously on the system, but that is not the case.

  • A CPU is driven by an internal clock that regulates the rate at which instruction are executed by the CPU and synchronizes all other components part of the computer system.

  • Every microprocessor requires a clock(binary square pulse) for its functioning. the CPU requires a fixed number of clock ticks (called as clock sycle/ clock speed) to execute each instruction.

  • the faster the clock cycle, the CPU can execute more part instructions per seconds. And therefore the number of clock cycles per second is known as processor speed. the processor speed is expressed in MHz Or GHz.

  • clocking is required to time and synchronize the various circuits.

  • the number of clock cycles per second is known as frequecny

  • Each CPU contains high speed memory areas registers and Level1 cache memory to store data and instruction during the various stages of execution of the instruction cycle. the CPU can directly access the registers to perform operation on the data.
  1. the CPU first loads the PC(Program Counter) register with the address of the first instruction to be executed.

  2. this address in the PC register is then transferred to the MAR(memory address register) and the CPU simultaneously increments the PC register by 1 so that now it contains the address of the next instructions.

  3. the contents of the MAR are placed on the address bus

  4. the control unit of the CPU sends two clock pulses on the control lines and this has individual effects (a) the low pulse on the CS line switches on the chip. (b) the low pulse on the R/W line reads or writes the conetens at the given memory address.

  5. As a result of the two low clock pulse causes the instruction or data is taken on the data bus to MBR(memory buffer register). this fetched instruction is then placed in the CIR(IR) current instruction register. at this stage the “fetch” part of instruction cycle ends and “Decode” part starts.

  1. the CIR(current instruction Register) breaks down the instruction in two parts(Opcode and Operand). the Opcode is sent to the instruction decoder where the operation to be performed by the ALU is decided based on the instruction set of the processor. the operand may either contain data or address as specified in the addressing mode in the Opcode. At this stage the “decode” part of the instruction cycle ends and “Execution” part starts.

  2. the instruction after being decoded is sent to execution unit ALU(Arithmetic Logic Unit) of the CPU. this is the last part of the instruction cycle where “execution” part starts. the ALU perform the operation on the data as specified in the program instruction. the result of this operation is temporarily stored in another register called “Accumulator” which is placed inside the ALU. the result is then transferred to either output device, storage or displayed.

Comment  Read more

17. CPU-instruction Cycle

|

CPU-instruction Cycle

  • it is the CPU which is mainly responsible to execute the program the operating system allocates the necessary resources to run the program

  • each of these program contains number of program statements which are instructions to the CPU to perform a particular task and a CPU floows machine instruction cycle(Fetch, Decode,Execute & Store) repetitively to execute the program.

  • A instruction cycle, also called a processor cycle of a machine cycle, which is the basic operation performed by a CPU

  • A CPU is the main component which performs all arithmetic calculations and takes logical decisions in a computer system.

  • A CPU can execute the instruction either in a single machine cycle or multiple machine cycles depending upon the complexity of the instruction.

  • A machine cycle consists of a sequence of four steps that are performed continously and at a rate of millions times per second while a program is being executed.

  • During the fourth step, store, in which the result of the processing done by the CPU is stored in main memory for later use Or sent to output device. however, no actual processing is performed during this step.

  • the CPU fecthes and executes program instruction from the main system memory RAM sequentially one by one. each instruction is processed by the CPU before the next one is started.

  • however, in most modern CPU, the instruction cycles are instead executed concurrently, and often in parallel, through an instruction pipeline. the instruction pipeline enable the OS to optimize on the CPU’s processing time.

  • in non-pipelined execution, the next instruction processing start only after processing of the previous instruction has finished, this is possible because the execution cycle is broken up into seperate steps. this is referred as serail processiong
    • non-pipelined execution 은 즉 병렬 프로세싱이아닌 직렬 프로세싱 뜻함
  • in pipelined execution, the next instruction processing starts een before the processing of previous instruction has finished. this processing is referred as parallel processing
    • pipeline execution, 병렬 프로세시싱

  • the CPUs instruction cycle is executed sequentially and each instruction is processed by CPU which consist of following steps:
    • Read an instruction from memory
    • Decode the instruction as per OPCODE
    • Find the address of operand
    • Retrieve an operand
    • perform the desired operation
    • Find the address of destination memory.
    • Store the result into the destination memory.

Comment  Read more

16.How CPU executes a Program

|

program compilation

  • A computer understands only machine language instruction (low level) that is a code written in binary code and execute the operation as per its instruction set.

  • A compiler is a special program which translate human readable code written in any high level programming launguage into a equivalent machine readable machine code in binary code.

  • A computer Program source code is generally written in a human readable high level language such as C, C++, python and many more. the high level program is then converted to machine readable binary code by using a special program called compiler.

  • An executable copy(machine Code) of the program consist of set of low level binary code instructions that can be direcly decoded and then executed by the computer’s processor.

  • the operating system allocates the required memory and processor time to initiate the program execution. the computer program(set of machine/ binary code instructions) is first loaded by the operating system from computer hard disk(secondary memory) to the RAM(main memory)

  • the CPU retrieves these instructions one by one from the main memory RAM and initiates the program execution process.

  • the program exectuion starts with the program instructions in binary machine code is copied from permanent disk memory to the volatile man Memory RAM. thses program instruction consist of binary machine code instructions directly executable by the CPU.

  • the constrol unit inside the CPU initiates the process of program execution by loading these instructions one by one from RAM to the CPU’s internal memory unit which consist of high speed memory(Registers and CACHE L1 memory).

  • the CPU makes use of differnt types of high speed internal memory registers during the various stages of program execution.

  • The CPU’s decode unit interprets these program instruction as per the processor’s instruction set architecture and performs the required operations on the data. the result is then sent to the main memory for further action.

  • the processed data(result) from the main memory RAM can be either sent to the output device(printer) OR could be sent to the permanent storage device

what is a program instruction?

  • A computer program is basically a list of instruction or statements that directs the computer hardware to perform a specific task as specified in the program instructions.

  • there are many programming languages available to a programmer but the computer basically understands only a program in machine code binary. therefore all the computer programs are eventually must be translated to machine code instructions which computer CPU can interprets and execute.

  • Machine code(binary code) is only form of program instruction that the computer hardware can understand and execute directly. all other forms of computer program written in different language must be first translated into machine code in order to be executed by the Hardware(CPU)

  • the Compiler is a special program used to convert high level program to low level machine code. thses machine code instructions are fetched from the memory and executed by the CPU.

  • Each CPU’s internal design is based on some standard micro architecture which is implemented by the CPU manufacuring companies which is knwon as “ISA(instruction Set architecture)”

  • an instruction is a binary pattern designed inside a CPU to perform a specific operation

  • the entire group of instructions that is implemented and supported by the microprocessor is called as “instruction Set”. for Example ISA 8085 has 246 instructions.

  • the program instruction can be classidied in to five broad categories

    • Data transfer Instruction
    • Arithmetic Instructions
    • Logicl instructions
    • branching instructions
    • control instruction

  • an instruction set is a list of all the instructions that a processor can decode and execute. such instructions include arithmetic operations such as add and substract, logical operaions such as AND or OR and NOT, data instruction such as move, input and output and control instructions such as goto, call, and return.

  • the instruction set specifies the opcodes(machine language operation codes) that are used to identify each instruction.

  • ISC generally break down into two main approaches

    1. RISC
    2. CISC

  • A single instruction can take more than one memory location to store. for example as shown in the diagram instruction 1,2,3,4 needs two memory locations each to store a part of the instruction in the main memory (RAM). whereas the instruction 5 will need only one memory location as it has only opcode

  • the computer program loaded by the operating system in to the RAM. the executable file of the program consist of number of instructions and each instruction has unique address in the memory which CPU can refer to while fetching the instructions.

  • Each instruction is represented by 8 bits binary value. this 8 bits binary value is called OPCODE or instruction byte.

  • the Machine instructions to be stored in the RAM must be encoded in binary as a sequence of 0’s and 1’s because all storage devices consist of a set of locations that can have one of two possible states(0,1). these instructions are fetched by the CPU one by one to execute the program.

  • the machine instruction is a binary representation of the instruction for the CPU in machine language (0 and 1) to perform a specific taks such as Add, divide, increment etc

  • Each Machine instruction has tow parts
    1. OPCODE : Operation Code
    2. OPERAND : Address of DATA / DATA
  • the OPCODE portion of the machine instruction specifies the operation to be performed by the ALU on the OPERAND as per instruction set of the CPU.

  • An OPCODE is a single instruction that can be executed by the CPU. in machine language it is a bianry or hexadecimal value such as “B6” loaded into the instruction register.

  • a simple example of a machine instruction ADD# 45 that we can give to a computer. this is called machine code instructions.

  • the machine code allows computers to perform the most basic, but essential tasks. the CPU makes use of the Accumulator Register which is used to stroe the intermediate results of all our calculations

Comment  Read more