cse1132.files.wordpress.com  · web view2014-02-01 · as we have seen earlier, computer programs...

30
What is Computer Architecture? Computer architecture involves the design of computers. Processor design involves the instruction set design and the organisation of the processor. Instruction set architecture (ISA) describes the processor in terms of what the assembly language programmer sees, i.e. the instructions and registers. Organisation is concerned with the internal design of the processor, the design of the bus system and its interfaces, the design of memory and so on. Two machines may have the same ISA, but different organisations. The organisation is implemented in hardware and in turn, two machines with the same organisation may have different hardware implementations, for example, a faster form of silicon technology may be used in the fabrication of the processor. Introduction The first point that must be made about computer architecture is that there is no standard computer architecture, in the same way as there is no such thing as a standard house architecture or standard motor car design However, just as all cars have some basic features in common, so too do computers. In this section, we take a high level look at the components of computer architecture that are common to all computers, noting that any particular computer will differ in various details from the general model presented. As we have seen earlier, computer programs are translated to machine code for execution by the CPU. Once a program has been loaded into the computer’s memory (carried out by the operating system on our behalf), the program may then be executed. This means that the CPU obeys the instructions making up the program and carries them out one at a time.

Upload: others

Post on 26-Jul-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: cse1132.files.wordpress.com  · Web view2014-02-01 · As we have seen earlier, computer programs are translated to machine code for execution by the CPU. Once a program has been

What is Computer Architecture?

Computer architecture involves the design of computers.

Processor design involves the instruction set design and the organisation of the processor.

Instruction set architecture (ISA) describes the processor in terms of what the assembly language programmer sees, i.e. the instructions and registers.

Organisation is concerned with the internal design of the processor, the design of the bus system and its interfaces, the design of memory and so on. Two machines may have the same ISA, but different organisations.

The organisation is implemented in hardware and in turn, two machines with the same organisation may have different hardware implementations, for example, a faster form of silicon technology may be used in the fabrication of the processor.

Introduction

The first point that must be made about computer architecture is that there is no standard computer architecture, in the same way as there is no such thing as a standard house architecture or standard motor car design

However, just as all cars have some basic features in common, so too do computers. In this section, we take a high level look at the components of computer architecture that are common to all computers, noting that any particular computer will differ in various details from the general model presented.  

As we have seen earlier, computer programs are translated to machine code for execution by the CPU. Once a program has been loaded into the computer’s memory (carried out by the operating system on our behalf), the program may then be executed.

This means that the CPU obeys the instructions making up the program and carries them out one at a time.

It is worth noting, at this point, the primitive nature of the CPU. The CPU does not understand programs, rather it obeys individual instructions.

 

Instruction Set

Page 2: cse1132.files.wordpress.com  · Web view2014-02-01 · As we have seen earlier, computer programs are translated to machine code for execution by the CPU. Once a program has been

One of the crucial features of any processor is its instruction set, i.e. the set of machine code instructions that the processor can carry out. Each processor has its own unique instruction set specifically designed to make best use of the capabilities of that processor. The actual number of instructions provided ranges from a few dozen for a simple 8-bit microprocessor to several hundred for a 32-bit VAX processor. However, it should be pointed out that a large instruction set does not necessarily imply a more powerful processor.

Many modern processor designs are so called RISC (Reduced Instruction Set Computer) designs which use relatively small instruction sets, in contrast to so called CISC (Complex Instruction Set Computer) designs such as the VAX and machines based on the Intel 8086 and Motorola 68000 microprocessor families.

Classification of Instructions

The actual instructions provided by any processor can be broadly classified into the following groups:

• Data movement instructions: These allow the processor move data between registers and between memory and registers (e.g. 8086 mov, push, pop instructions). A ‘move’ instruction and its variants is among the most frequently used instructions in an instruction set. 

• Transfer of control instructions: These are concerned with branching for loops and conditional control structures as well as for handling subprograms (e.g. 8086 je, jg, jmp, call, ret instructions). These are also commonly used instructions.

• Arithmetic/logical instructions: These carry out the usual arithmetic and logical operations (e.g. 8086 cmp, add, sub, inc, and, or, xor instructions). Surprisingly, these are not frequently used instructions, and when used, it is often in conjunction with a conditional jump instruction rather than for general arithmetic purposes. Note that we have included the cmp instruction with the arithmetic/logical instructions because it actually behaves like a sub instruction except it does not modify its destination register.

• Input/output instructions: These are used for carrying out I/O (e.g. 8086 in, out instructions) but a very common form of I/O called memory mapped I/O uses ‘move’ instructions for I/O.

• Miscellaneous instructions (e.g. 8086 int, sti, cti, hlt, nop) for handling interrupts and such activities. The hlt instruction halts the processor and the nop instruction does nothing at all! These instructions are again not that frequently used relative to data movement and transfer of control

Page 3: cse1132.files.wordpress.com  · Web view2014-02-01 · As we have seen earlier, computer programs are translated to machine code for execution by the CPU. Once a program has been

instructions. The int instruction could also be classified as a transfer of control instruction and interrupts are described in more detail below.

This is not the only way to classify instructions. For example, the arithmetic/logical instructions mentioned above may be classified as operate instructions. Operate instructions also include instructions that move data between registers and manipulate stacks. Memory-access instructions refer to those that transfer data between registers and memory. 

Fixed and Variable length Instructions

Instructions are translated to machine code. In some architecture all machine code instructions are the same length i.e. fixed length. In other architectures, different instructions may be translated into variable lengths in machine code.

This is the situation with 8086 instructions which range from one byte to a maximum of 6 bytes in length. Such instructions are called variable length instructions and are commonly used on CISC machines.

The advantage of using such instructions is that each instruction can use exactly the amount of space it requires, so that variable length instructions reduce the amount of memory space required for a program.

On the other hand, it is possible to have fixed length instructions, whereas the name suggests, each instruction has the same length. Fixed length instructions are commonly used with RISC processors such as the PowerPC and Alpha processors.

Since each instruction occupies the same amount of space, every instruction must be long enough to specify a memory operand, even if the instruction does not use one. Hence, memory space is wasted by this form of instruction. The advantage of fixed length instructions, it is argued, is that they make the job of fetching and decoding instructions easier and more efficient, which means that they can be executed in less time than the corresponding variable length instructions.

Thus the comparison between fixed and variable length instructions comes down to the classic computing trade off of memory usage versus execution time.

In general, computer programs that execute very quickly tend to use larger amounts of storage, while programs to carry out the same tasks, that do not use so much storage, tend to take longer to execute.

Fetch-Execute Cycle

Page 4: cse1132.files.wordpress.com  · Web view2014-02-01 · As we have seen earlier, computer programs are translated to machine code for execution by the CPU. Once a program has been

This is the fundamental operation of the processor. The CPU executes the instructions that it finds in the computer’s memory. In order to execute an instruction, the CPU must first fetch (transfer) the instruction from memory into one of its registers.

This is a non-trivial task requiring several steps and is described later.

The CPU then decodes the instruction, i.e. it decides which instruction has been fetched and finally it executes (carries out) the instruction.

The CPU then repeats this procedure, i.e. it fetches an instruction, decodes and executes it. This process is repeated continuously and is known as the fetch-execute cycle.

This cycle begins when the processor is switched on and continues until the CPU is halted (via a halt instruction, e.g. 8086 hlt instruction or the machine is switched off).

Instead of looking at the details of a particular microprocessor's architecture at this point, we will use a simple hypothetical microprocessor to explain the basic concepts of computer architecture.

We call the machine SAM (Simple Architecture Machine). Figure 1 illustrates the major components of SAM. It is a 16-bit microprocessor with 4 general purpose registers r0 to r3, a program counter register PC, a stack pointer register SP and status register SR. The status register is made up of similar flags to the 8086 flags register, e.g. a zero flag, an overflow flag, a carry flag and so on.

The fetch-execute cycle operates by first fetching an instruction. The program counter register PC always contains the address of the next instruction to be executed.

Let us assume that a particular program has been loaded into memory and is currently being executed. Program execution has reached a certain point (the move instruction is being executed) and the three instructions of the program are listed in Example 1.

To illustrate how the fetch execute cycle operates, we will trace the execution of these instructions.

We assume that these instructions are stored in memory beginning at location 3000H.

The instructions and their machine code equivalents (in hexadecimal) are listed below.

Page 5: cse1132.files.wordpress.com  · Web view2014-02-01 · As we have seen earlier, computer programs are translated to machine code for execution by the CPU. Once a program has been

We use hexadecimal instead of binary as it is easier to work with but you must remember that it is the binary form of the instructions that are actually stored in memory.

Use of MAR and MDR

MAR stands for memory address register:

MAR is connected to the address bus.

MDR Stands for memory data register.

MDR is connected to the data bus

Page 6: cse1132.files.wordpress.com  · Web view2014-02-01 · As we have seen earlier, computer programs are translated to machine code for execution by the CPU. Once a program has been

Fig: Use of MDR and MAR

Accessing Memory

In order to execute programs, a microprocessor fetches instructions from memory and executes them, fetching data from memory if it is required.  

In Figure 1 we introduced two registers that we have not mentioned before namely the memory address register, MAR and the memory data register, MDR. There are a number of such CPU registers that do not appear in the programming model of a CPU. We shall refer to these registers as hidden CPU registers to distinguish them from the programming model registers R0 to R4, PC, SR and SP registers.

The MAR and MDR registers are used to communicate with memory (and other devices attached to the system bus).

In addition, Figure 1 shows the buses that allow the devices making up a SAM computer system communicate with each other.

The MAR register is used to store the address of the location in memory that is to be accessed for reading or writing.

When we retrieve information from memory we refer to the process as reading from memory.

When we store an item in memory, we refer to the process as writing to memory.

Page 7: cse1132.files.wordpress.com  · Web view2014-02-01 · As we have seen earlier, computer programs are translated to machine code for execution by the CPU. Once a program has been

In either case, before we can access memory, we must specify the location we wish to access, i.e. the address of the location in memory. This address must be stored in the MAR register.

The MAR register is connected to memory via the address bus whose function is to transfer the address in the MAR register to memory. In this way the memory unit is informed as to which location is to be accessed.

The address bus is a uni-directional bus, i.e. information can only travel along it in a single direction, from the CPU to memory and other devices.

The MAR register is a 16-bit register like all the other SAM registers. This means that the maximum address it can contain is 216 - 1 (65,535) bytes, i.e. it can address up to 64Kb of memory.

The MDR register is used either to store information that is to be written to memory or to store information that has been read from memory. The MDR register is connected to memory via the data bus whose function is to transfer information, to or from memory and other devices.

The data bus is a bi-directional bus, i.e. information can travel along it, both, to and from the CPU.

The control bus plays a crucial role in I/O. It carries control signals specifying what operation is to be carried out and to synchronise the transfer of information.

For example, one line of the control bus is the read/write (R/W) line which used to specify whether a read or write operation is to be carried out.

Another line is the valid memory address (VMA) line which indicates that the address bus now carries a valid memory address. This tells the memory unit when to look at the address bus to find the address of the location to be accessed. A third line is the memory operation complete (MOC) line which signals that the read/write operation has now completed. We should note at this point, that the other devices attached to the computer, such as I/O and storage devices, usually communicate with the CPU in a similar fashion to that described for communicating with memory

Reading from Memory

The following steps are carried out by the SAM microprocessor to read an item from memory. The item may be an instruction or a data operand.

1. The address of the item in memory is stored in the MAR register.

Page 8: cse1132.files.wordpress.com  · Web view2014-02-01 · As we have seen earlier, computer programs are translated to machine code for execution by the CPU. Once a program has been

2. This address is transferred to the address bus.

3. The VMA line and R/W line of the control bus are used to indicate to memory that there is a valid address on the address bus and that a read operation is to be carried out.

4. Memory responds by placing the contents of the desired address on the data bus.

5. Memory enables the MOC line to indicate that the memory operation is complete, i.e. the data bus contains the required data.

6. The information on the data bus is transferred to the MDR register.

7. The information is transferred from the MDR register to the specified CPU register.

Writing to Memory

This procedure is similar to that for reading from memory:

1. The address of the item in memory is stored in the MAR register.

2. This address is transferred to the address bus.

3. The item to be written to memory is transferred to the MDR register.

4. This information is transferred to the data bus.

5. The VMA line and R/W line of the control bus are used to indicate to memory that there is a valid address on the address bus and that a write operation is to be carried out.

6. Memory responds by placing the contents of the data bus in the desired memory location.

7. Memory uses the MOC line to indicate that the memory operation is complete, i.e. the data has been written to memory.

 

We can see from the above descriptions (which have been simplified!) that accessing memory or any device is quite complicated from an implementation viewpoint. So, when an instruction such as

Page 9: cse1132.files.wordpress.com  · Web view2014-02-01 · As we have seen earlier, computer programs are translated to machine code for execution by the CPU. Once a program has been

load r1, i

to load a register with the contents of a memory variable is to be executed, a lot of work has to be carried out.

Firstly the instruction must be fetched from RAM, then the value of i must be fetched from RAM and finally the transfer of the value of i to register r1 is carried out.

It is important to realise that every operation concerning memory involves either reading or writing memory.

Memory is a passive device. It can only store information. No processing can be carried out on information in memory. The information, stored in memory, must be transferred to a CPU register for processing and the result written back to memory.

So, for example, when an instruction such as the 8086 inc instruction is carried out to increment a memory variable (as in inc memvar ), its execution involves both a memory read operation and a memory write operation.

Firstly, the value of memvar must be transferred to the CPU where it can be incremented by the ALU. This transfer is carried out via a memory read operation. Then, once this value has been incremented by the ALU, the new value of memvar must be written out to memvar's address in memory, via a memory write operation.

Encoding Instructions in Machine Code

Instructions are represented in machine code as binary numbers in same way as all other information is represented in a computer system. We noted earlier that assembly language instructions for most processors are broadly similar and have the form:

[label] operation [operand ..] [;comment]

The general form of a machine code instruction is illustrated in Figure 2 with the bits making up the instruction being grouped into opcode and operand fields.

Page 10: cse1132.files.wordpress.com  · Web view2014-02-01 · As we have seen earlier, computer programs are translated to machine code for execution by the CPU. Once a program has been

Figure 2: Machine code instruction format

The opcode field contains a binary code that specifies the operation to be carried out (e.g. add, jmp ). Each operation has its own unique opcode. The operand field specifies the operand or operands that the operation is to be carried out on.. 

It should be emphasized that the instruction encoding for SAM is designed for illustration purposes. The aim is to keep it as simple as possible while remaining basically similar to the encoding of instructions on real processors. The reader is encouraged to look at ways the instructions could be more efficiently encoded.

Table 1 lists the opcodes of the commonly used SAM instructions in binary and hexadecimal.

Instruction Binary Code Hex Codemove 0000 0001 01load 0000 0010 02store 0000 0011 03add 0000 1000 08sub 0000 1001 09cmp 0000 1111 0Fjmp 0001 1111 1Fje 0010 1111 2F

Table 1: SAM opcodes

The operand field of an instruction must be able to specify the registers, memory addresses or constants that the instruction is to operate on. SAM instructions have at most two operands. If there are two operands then one is always a register.

If a memory address is specified (e.g. in the case of a memory variable or label) then the instruction is encoded using 32-bits.

Since SAM has four general purpose registers we can represent them using 2-bit codes as follows:

00 for r0

01 for r1

Page 11: cse1132.files.wordpress.com  · Web view2014-02-01 · As we have seen earlier, computer programs are translated to machine code for execution by the CPU. Once a program has been

10 for r2

11 for r3.

Thus, 4 bits are required to represent the two registers that may be used in an instruction. Bit numbers 0 and 1, represent the source register and bit numbers 2 and 3 represent the destination register.

 

Example: Encoding of load r1, X where X refers to a memory variable stored at location 00FFH (255D) in memory,

Instruction and binary encoding Hex encoding

(1)

load r1, X ; r1 = X

0000 0010 1000 01 00 0000 0000 1111 1111 0284 00ffH

(address of val)

ß B-field> ß W-field à

Explanation

This instruction is encoded using 32-bits. The opcode for load is 0000 0010 (02H), the destination register r1 is encoded as 01, while the source register is encoded as 00, but is not used because the load instruction looks for its source operand in memory, hence bit 7 of the B-field is set to 1, indicating a memory operand. Finally, the address of the memory variable X (00ffH) is stored in the W-field.

Basic Common Architecture of Microcomputer

A microprocessor is a programmable multipurpose-multitasking logic chip .The first microprocessor developed by the INTEL corporation in 1971 (INTEL-4004), which was only a 4 bit microprocessor .A microprocessor can accept input data’s into binary forms, read binary instructions, perform data processing and provide desired output. In a modern computer system, the

Page 12: cse1132.files.wordpress.com  · Web view2014-02-01 · As we have seen earlier, computer programs are translated to machine code for execution by the CPU. Once a program has been

microprocessor is usually referred to as CPU (central processing unit). A microprocessor is basically classified by its word length (word length represented by the number of bits, that is, 4bit, 8bit, 16bit, 32bit, 64bits are normally used for micro processors). The basic block diagram of a microprocessor and a microprocessor based computer system is given below.

Microprocessor-Block-Diagram

Arithmetic and Logic Unit (ALU)

ALU is one of the basic units of a microprocessor. All the computing functions are maintained in this unit. As the name shows, the ALU can perform all the arithmetic operations (+,-,*,/,%,etc) and all logical operations (AND, OR, NOT, XOR, etc).

Control Unit (CU)

Control unit is another important part of a microprocessor. The CPU’s control unit coordinates and times the CPU’s functions, and it uses the program counter to locate and retrieve the next instruction from memory. Another purpose of control unit is, controlling the data flow between microprocessor and peripheral devices/peripheral chips.

Registers

Page 13: cse1132.files.wordpress.com  · Web view2014-02-01 · As we have seen earlier, computer programs are translated to machine code for execution by the CPU. Once a program has been

Registers are the important section of microprocessor chip. Registers are primarily used to store the data temporarily during the execution/runtime of the program. A microprocessor contains several kinds of registers that can be classified according to the instructions provided to the processor. These instructions are called instruction sets. The registers are basically 8bit, 16bit or 32 bit according to the type. Registers can easily accessible to the user by using various commands (instructions). Some registers are used to store address of memory locations that can be easily accessed by the microprocessor.

Memory

As in the name shows, memory are used to store the information (data & instructions) as in the binary form. According to this binary information’s, a microprocessor perform its operation during the execution period. A microprocessor can read the information from memory and perform the corresponding operations in its ALU. The result of each operation stored in a memory or given to any output unit associated with the system. The data stored in the memory can be use further use. But some memories used in a computer system are temporary memories or instantaneously fed to the any peripheral units. These type data can’t be store in computer memory for later use. The memory unit of a microprocessor computer system consists of two types of memories. They are Read Only Memory (simply called as ROM) and Random Access Memory (simply called as RAM).

Read Only Memory (ROM)

Read-only memory is one of the computer memories. ROM memory is used to store items that the computer needs to execute when it is first turned on. For example, the ROM memory on a PC contains a basic set of instructions, called the basic input-output system (BIOS). The PC uses BIOS to start up the operating system. BIOS is stored on computer chips in a way that causes the information to remain even when power is turned off.ROM is a non-volatile memory. The program stored in ROM can only read.

Random Access Memory (RAM)

Random access memory is the other type of internal memory .RAM also called main memory because it is the primary memory that the CPU uses when processing information. The electronic circuits used to construct this main internal RAM can be classified as dynamic RAM (DRAM), synchronized dynamic RAM

Page 14: cse1132.files.wordpress.com  · Web view2014-02-01 · As we have seen earlier, computer programs are translated to machine code for execution by the CPU. Once a program has been

(SDRAM), or static RAM (SRAM).This memory is used to store user programs and data’s temporarily. RAM is a volatile memory.

Microcontrollers (MCU) and Microprocessors (MPU)

Difference between microprocessor and microcontrollerMicroprocessor is an IC which has only the CPU inside them i.e. only the processing powers such as Intel’s Pentium 1,2,3,4, core 2 duo, i3, i5 etc. These microprocessors don’t have RAM, ROM, and other peripheral on the chip. A system designer has to add them externally to make them functional. Application of microprocessor includes Desktop PC’s, Laptops, notepads etc.

 But this is not the case with Microcontrollers. Microcontroller has a CPU,

in addition with a fixed amount of RAM, ROM and other peripherals all embedded on a single chip. At times it is also termed as a mini computer or a computer on a single chip. Today different manufacturers produce microcontrollers with a wide range of features available in different versions. Some manufacturers are ATMEL, Microchip, TI, Freescale, Philips, Motorola etc. 

 Microcontrollers are designed to perform specific tasks. Specific means applications where the relationship of input and output is defined. Depending on the input, some processing needs to be done and output is delivered. For example, keyboards, mouse, washing machine, digicam, pendrive, remote, microwave, cars, bikes, telephone, mobiles, watches, etc. Since the applications are very specific, they need small resources like RAM, ROM, I/O ports etc and hence can be embedded on a single chip. This in turn reduces the size and the cost.

 Microprocessor find applications where tasks are unspecific like developing

software, games, websites, photo editing, creating documents etc. In such cases the relationship between input and output is not defined. They need high amount of resources like RAM, ROM, I/O ports etc. 

The clock speed of the Microprocessor is quite high as compared to the microcontroller. Whereas the microcontrollers operate from a few MHz to 30 to 50 MHz, today’s microprocessor operate above 1GHz as they perform complex tasks. Read more about what is microcontroller.

 Comparing microcontroller and microprocessor in terms of cost is not justified. Undoubtedly a microcontroller is far cheaper than a microprocessor. However microcontroller cannot be used in place of microprocessor and using a microprocessor is not advised in place of a microcontroller as it makes the application quite costly. Microprocessor cannot be used stand alone. They need other peripherals like RAM, ROM,

Page 15: cse1132.files.wordpress.com  · Web view2014-02-01 · As we have seen earlier, computer programs are translated to machine code for execution by the CPU. Once a program has been

buffer, I/O ports etc and hence a system designed around a microprocessor is quite costly.

System Bus

A bus is the set of hardware lines or circuit lines which help the communication between the processor and other input/output units. A system bus is a flat cable with numerous parallel wires. Each wire can carry one bit, so the bus can transmit many bits along the cable at the same time. For example, a 16-bit bus, with 16 parallel wires, allows the simultaneous transmission of 16 bits (2 bytes) of information from one component to another. The system bus basically classified into three groups.

1)Control bus2)Data bus3)Address bus.

`

Fig: General Bus Diagram address, data and control Bus

1) Control busA control bus is a bi-directional bus which is used to transfer the control signals (read, write, interrupt) and timing signals (clock pulses) between microprocessor and other peripheral components.

2) Data Bus: Data bus is also a bi-directional bus that used to transmit data bi-directionally between the microprocessor and peripherals devices.

Page 16: cse1132.files.wordpress.com  · Web view2014-02-01 · As we have seen earlier, computer programs are translated to machine code for execution by the CPU. Once a program has been

3) Address BusAddress bus is a unidirectional bus which is used to send the address of a peripheral from microprocessor to the peripheral device.

How a program Execute and save data (Informally);

Click this link to identify animation:

http://www.eastaughs.fsnet.co.uk/cpu/execution-index.htm

Following on from looking at the structure and architecture of the central processing unit itself, we shall now look at how the CPU is used to execute programs and make the computer as a whole run smoothly and efficiently. To do this, we must take a step back from concentrating solely on the processor, and look at the complete computer unit.

A flow diagram illustrating the flow of data within the PC during program execution and the saving of data. Further explanation can be found below.

When software is installed onto a modern day personal computer (most commonly from a CD-ROM, though other media or downloading from the

Page 17: cse1132.files.wordpress.com  · Web view2014-02-01 · As we have seen earlier, computer programs are translated to machine code for execution by the CPU. Once a program has been

internet is also common), code comprising the program and any associated files is stored on the hard drive. This code comprises of a series of instructions for performing designated tasks, and data associated with these instructions. The code remains there until the user chooses to execute the program in question, on which point sections of the code are loaded into the computers memory.

The CPU then executes the program from memory, processing each instruction in turn. Of course, in order to execute the instructions, it is necessary for the CPU to understand what the instruction is telling it to do. Therefore, recognition for instructions that could be encountered needs to be programmed into the processor. The instructions that can be recognized by a processor are referred to as an 'instruction set', and are described in greater detail on the next page of the tutorial.

Once the instruction has been recognized, and the actions that should be carried out are decided upon, the actions are then performed before the CPU proceeds on to the next instruction in memory. This process is called the 'instruction execution cycle', and is also covered later on in this tutorial. Results can then be stored back in the memory, and later saved to the hard drive and possibly backed up onto removal media or in seperate locations. This is the same flow of information as when a program is executed only in reverse, as illustrated in the diagram above.

On the next page of this tutorial is a more in-depth look at instruction sets. Click the next arrow below to proceed.

How a microprocessor Execute an Instruction

Click the link to show fetch execute cycle:

http://www.it.uom.gr/teaching/opsysanimation/animations/IECYCLE.SWF

In a computer, the cycle of execution of an instruction begins in the central processing unit (CPU) with following processes happening step by step: 1.fetching of instruction: 2.decoding of instruction: 3.execution cycle:

Page 18: cse1132.files.wordpress.com  · Web view2014-02-01 · As we have seen earlier, computer programs are translated to machine code for execution by the CPU. Once a program has been

4.storage:.. Machine Instruction CycleThe machine instruction cycle includes the 4 steps: fetch, decode, execute, and storethis is how all function of the processor are carried out.

Fig : Diagram of the Machine Instruction Cycle

1. Fetch the instructiono The in the program counter stored address is the address which

contains next instruction that is to be executed.o Via data bus the content of address contained in the program

counter is fetched from the main memory & stored in the CIR (Current Instruction Register)

o Program counter = incremented by 12. Decode the instruction

o The instruction decoder interprets the instructiono All required data = fetched from main memory & put in data

registers3. Execute the instruction

o CU passes decoded instruction to different parts of CPU to perform the actions that are required.

4. Store resultso Results of calculations in CPU = stored in main memory or sent

to output deviceso Program Counter could be updated to a new address

REPEAT 1. Fetch cycleSteps 1 and 2 of the Instruction Cycle are called the Fetch Cycle. These steps are the same for each instruction. The fetch cycle processes the instruction from the instruction word which contains an opcode and an operand.

Page 19: cse1132.files.wordpress.com  · Web view2014-02-01 · As we have seen earlier, computer programs are translated to machine code for execution by the CPU. Once a program has been

2. Execute cycleSteps 3 and 4 of the Instruction Cycle are part of the Execute Cycle. These steps will change with each instruction.How does a microprocessor differentiate between data and

instruction?

In Processor, how are Data, Address and instructions are differentiated? When a program is executed, how is processor differentiate instructions when everything is in 0s and 1s and register`s load both data, addresses?

When the first m/c code of an instruction is fetched and decoded in the instruction register, the microprocessor recognizes the number of bytes required to fetch the entire instruction. For example MVI A, Data, the second byte is always considered as data. If the data byte is omitted by mistake whatever is in that memory location will be considered as data & the byte after the “data” will be treated as the next instruction.

How does microprocessor differentiate between a positive and negative number?

Follow the web link to get better idea

http://www.wisc-online.com/objects/ViewObject.aspx?ID=IAU3606

Microprocessors use binary, so all they have is ones and zeros (♪♫...and sometimes we ran out of ones...♪♫) Sorry.

The chip notes negative numbers by the leading bit If the chip can handle 8 bits if information, they use the first for the sign (0 is positive, 1 for negative) and the remaining 7 bits for the number from 0 to 127.

What is overflow and underflow?

Overflow flag : in computer processors, the overflow flag (sometimes called V flag) is usually a single bit in a system status register used to indicate when an arithmetic overflow has occurred in an operation, indicating that the signed two's-complement result would not fit in the number of bits used for the operation (the ALU width). Some architectures may be configured to automatically generate an exception on an operation resulting in overflow.

Page 20: cse1132.files.wordpress.com  · Web view2014-02-01 · As we have seen earlier, computer programs are translated to machine code for execution by the CPU. Once a program has been

Underflow:(1) An error condition that occurs when the result of a computation is smaller than the smallest quantity the computer can store.

(2) An error condition that occurs when an item is called from an empty stack.

How Computers Represent Negative Binary Numbers?

Binary is not complicated. Once you learn how number systems work it’s pretty easy to go from decimal to binary, back, to add binary numbers, multiply them and so on (if you are not familiar with the binary system, check out this article on Wikipedia first).

There’s one part of binary numbers that is not as straight-forward, though, and that is the representation of negative binary numbers.

Signed Magnitude

The simplest method to represent negative binary numbers is called Signed Magnitude: you use the leftmost digit as a sign indication, and treat the remaining bits as if they represented an unsigned integer. The convention is that if the leftmost digit (also called the most significant digit or most significant bit) is 0 the number is positive, if it’s 1 the number is negative. So:

00001010 = decimal 1010001010 = decimal -10

That is why the range of positive numbers you can store in unsigned integers is larger than signed ones. For example, most computers use a 32-bit architecture these days, so integers will have 32 bits as well in C.

This means that an unsigned INT can go up to 4,294,967,296 (which is 2^32 – 1). You need to subtract one because the result of 2^32 starts from 1, while the first binary representation is 0.

Now if the INT is signed you won’t be able to use the leftmost bit. This means that your positive range will go up to 2,147,483,647 (which is 2^31 – 1). However you also have the negative values, and they go up to -2,147,483,647.

The main problem with this system is that it doesn’t support binary arithmetic (which is what the computer would naturally do). That is, if you add 10 and -10 binary you won’t get 0 as a result.

Page 21: cse1132.files.wordpress.com  · Web view2014-02-01 · As we have seen earlier, computer programs are translated to machine code for execution by the CPU. Once a program has been

     00001010 (decimal 10)    +10001010 (decimal -10)-----------------------------------------------------     10010100 (decimal -20)

This doesn’t make much sense, and that’s why people came up with representations more suitable for a computer. Nonetheless there were some very early computers that used this system to represent negative numbers.

One’s Complement

The One’s Complement of a binary number is basically another binary number which, when added to the original number, will make the result a binary number with 1s in all bits.

To obtain one’s complement you simply need to flip all the bits. Suppose we are working with unsigned integers.

Decimal 10 is represented as: 00001010

It’s one complement would be: 11110101

Notice that the complement is 245, which is 255 – 10. That is no co-incidence. The complement of a number (again, we talking unsigned) is the largest number represented with the number of bits available minus the number itself. Since we are using 8 bits here the maximum number represented is 255 (2^32 – 1). So the complement of 10 will be 245.

If we add the number and it’s complement the result should be 1s on all bits.

     00001010 (decimal 10)

    +11110101 (decimal 245)

--------------------------------------------------------

     11111111 (decimal 255)

We could now say that the leftmost bit will indicate the signal of the number again. So 11110101 would be a negative number. What number? -10, because the complement of 11110101 is 00001010 (i.e., decimal 10).

Page 22: cse1132.files.wordpress.com  · Web view2014-02-01 · As we have seen earlier, computer programs are translated to machine code for execution by the CPU. Once a program has been

Another example: suppose we want to represent -12 with the one’s complement system. First we need to represent 12 in binary, which is 00001100. Now we find it’s one’s complement, which is 11110011, and that is the -12.

As you can see, using the one’s complement system to represent negative numbers we would have two zeroes: 00000000 (could be seen as +0) and 11111111 (could be seen as -0).

Just as with the signed magnitude method, the range of numbers here goes from -2^(n-1) -1 to +2^(n-1) – 1, where n is the number of bits used to represent the numbers. If we had 8 bits the ranges would be from -127 up to 127.

With this representation the binary arithmetic problem is partially solved. If we add 12 and -12, for example, we’ll get -0 as the result, which makes sense.

     00001100 (decimal 12)    +11110011 (decimal -12)--------------------------------------------------------     11111111 (decimal -0)

I said this system partially solves the binary arithmetic problem because there are some special cases left.

For example, let’s add 3 with -1.

     00000011 (decimal 3)    +11111101 (decimal -2)-------------------------------------    100000000 (decimal 256)

But since we have only 8 bits to represent the numbers, the leftmost 1 will be discarded, and the result would be 00000000 (decimal +0).

This is not the answer we expected.

To fix the problem we just need to place the leftmost 1 (i.e., the carry) into the first bit.

     00000011 (decimal 3)

Page 23: cse1132.files.wordpress.com  · Web view2014-02-01 · As we have seen earlier, computer programs are translated to machine code for execution by the CPU. Once a program has been

    +11111101 (decimal -2)------------------------------------------------     00000000 (decimal +0)    +00000001 (the carry)-------------------------------------------------------     00000001 (decimal 1)

Now it works. Let’s do one more example adding 10 and -5.

     00001010 (decimal 10)    +11111010 (decimal -5)---------------------------------------------------     00000100 (decimal 4)    +00000001 (the carry)-------------------------------------------------------------     00000101 (decimal 5)

Works again!

This system was used by many computers at one point in time. For example, the PDP-1 (DEC’s first computer) used it.

Two’s Complement

The Two’s Complement of a binary number is basically another number which, when added to the original, will make all bits become zeroes. You find a two’s complement by first finding the one’s complement, and then by adding 1 to it. If you think about it it makes perfect sense. The one’s complement, when added to the original number, will produce a binary number with 1s on all the bits. Add 1 to that and you’ll cause an overflow, setting every bit back to 0.

For example, let’s find the two’s complement of 12. The binary representation of 12 is 00001100. It’s one’s complement is 11110011. Add one to that and we have its two’s complement.

     11110011 (one's complement of 12)

Page 24: cse1132.files.wordpress.com  · Web view2014-02-01 · As we have seen earlier, computer programs are translated to machine code for execution by the CPU. Once a program has been

    +00000001 (decimal 1)------------------------------------------------------------     11110100 (two's complement of 12)

Now if we add 12 with its two’s complement we should get all 0s.

     00001100 (decimal 12)    +11110100 (two's complement of 12)--------------------------------------------------------------     00000000 (decimal 0)

Once more we’ll use the most significant bit (i.e., the leftmost one) to represent the sign of the number. Let’s suppose we want to represent -5. First of find its one’s complement, which is 11111010, and then we add 1 to it. So -5 is represented as 11111011 in binary under the two’s complement system.

Now let’s add 12 with -5 to see if we’ll have the same problem that we had when using the one’s complement system:

     00001100 (decimal 12)

    +11111011 (decimal -5)--------------------------------------------------     00000111 (decimal 7)

As you can see the result is correct, without the need to keep track/add the carry in case of overflow. Additionally, the number zero has a single representation now: 0000000.

This means that the two’s complement system pretty much solves all the binary arithmetic problems, and that is why it’s used by most computers these days.

If you have a negative binary number under the two’s complement system and want to convert it to you digital you simply remove 1 from it and then find its one’s complement.

Say we have this number in binary: 10010101

Removing one it becomes 10010100. Its one’s complement then is 01101011, which is 107 in decimal. So the original number represented -107.

Page 25: cse1132.files.wordpress.com  · Web view2014-02-01 · As we have seen earlier, computer programs are translated to machine code for execution by the CPU. Once a program has been

As I mentioned before this method has only one representation for the zero, which is 00000000. 11111111 (which was also zero under the one’s complement system) will now be -1. And 10000000 will now be -128, meaning we gained one more number in the range.

That is, using the two’s complement system the range of numbers will go from -2^(n-1) up to +2^(n-1)-1. If we are using 8 bits this means that numbers will go from -128 up to 127.