Академический Документы
Профессиональный Документы
Культура Документы
INTRODUCTION
This chapter discusses the computer hardware, software and their interconnection, and it also discusses concepts like Computer types Functional Units Bus Structures Performance Multiprocessor, RISC and CISC systems.
pesse computer organization unit-1 2
COMPUTER TYPES
Computers are classified based on the parameters like
Speed of operation
Cost Computational power Type of application
pesse
computer organization
unit-1
NOTEBOOK COMPUTER
Compact form of personal computer (laptop) Advantage is portability
pesse
computer organization
unit-1
WORK STATIONS
More computational power
Costlier Used to solve complex problems which arises in engineering application (graphics, CAD/CAM etc)
pesse
computer organization
unit-1
SERVER SYSTEM
Supports large volumes of data which frequently need to be accessed or to be modified Supports request response operation
SUPER COMPUTERS
Faster than mainframes
Helps in calculating large scale numerical and algorithm calculation in short span of time
Used for aircraft design and testing, military application and weather forecasting
pesse
computer organization
unit-1
Functional Units
Functional Units
Input
Memory Output Control Arithmetic and logic
I/O
Processor
Data
Used as operands by the instructions
INPUT UNIT:
Converts the external world data to a binary format, which can be understand by CPU Eg: Keyboard, Mouse, Joystick etc
OUTPUT UNIT:
Converts the binary format data to a format that a common man can understand Eg: Monitor, Printer, LCD, LED etc
pesse
computer organization
unit-1
10
Memory Unit
Store programs and data Two classes of storage
Primary storage
Fast Programs must be stored in memory while they are being executed Large number of semiconductor storage cells Processed in words Distinct Address associated with each location
Control Unit
All computer operations are controlled by the control unit. The timing signals that govern the I/O or data or any transfers are also generated by the control unit.
Operations of a computer:
Accept information in the form of programs and data through an input unit and store it in the memory
Fetch the information stored in the memory, under program control, into an ALU, where the information is processed Output the processed information through an output unit Control all activities inside the machine through a control unit
Review
Activity in a computer is governed by instructions. To perform a task, an appropriate program consisting of a list of instructions is stored in the memory. Individual instructions are brought from the memory into the processor, which executes the specified operations. Data to be used as operands are also stored in the memory.
A Typical Instruction
Add LOCA, R0 Add the operand at memory location LOCA to the operand in a register R0 in the processor. Place the sum into register R0. The original contents of LOCA are preserved. The original contents of R0 is overwritten. Instruction is fetched from the memory into the processor the operand at LOCA is fetched and added to the contents of R0 the resulting sum is stored in register R0.
Prev example combines a memory access operation with an ALU operation This can be realized as Load LOCA,R1 Add R1,R0 Transfers b/w the memory and the cpu are started by sending the address of the location to memory unit and issuing the appropriate control signals
MAR
MDR Control
PC
R0 R1 Processor
Registers
Instruction register (IR)
instruction register holds the instruction that is currently being executed. Instruction present in IR will be decoded by which processor understand what operation it has to perform
General-purpose register (R0 Rn-1) Memory address register (MAR) holds the address of the location to be accessed. Memory data register (MDR) contains the data to be written into or read out of the addressed location.
Interrupt
Execution may preempted if some device needs urgent servicing. Device raises an interrupt signal. Interrupt: request from an I/O device for service by the processor. Processor provides requested service by executing an appropriate interrupt service routine. Before servicing the interrupt the contents of PC, generalpurpose registers, and some control information are saved in memory After completion of interrupt service routine, state of the processor is restored and interrupted program may continue.
Bus Structures
There are many ways to connect different parts inside a computer together. A group of lines that serves as a connecting path for several devices is called a bus. Address/data/control
Input
Output
Memory
Processor
Bus Structure
Figure 1.3.
Single-bus structure.
Single-bus
Single-bus
Simplest way of interconnecting functional units All units are connected to this bus Can be used for only one transfer at a time, thereby only 2 units can actively use the bus at a time Low Cost and flexibility for attaching peripheral devices
Multiple Buses
To improve performance multibus structure can be used In two bus structure : One bus can be used to fetch instruction other can be used to fetch data, required for execution. Thus improving the performance
Also buffer registers can be used with the devices to hold the information during transfers smoothes out the timing difference between the cpu,memory and i/o devices
Performance
Performance
The most important measure of a computer is how quickly it can execute programs. Three factors affect performance:
Hardware design Instruction set Compiler
Performance
Processor time to execute a program depends on the hardware involved in the execution of individual machine instructions.
Main memory
Cache memory
Processor
Bus
Processor Clock
Processor circuits are controlled by a timing signal clock Clock defines regular time intervals clock cycles Each instruction is divided into several basic steps, each of which completes in one clock cycle.
P length of one clock cycle is an important parameter that affects processor performance. The inverse of P is the clock rate R = 1/P which is measured in cycles per second (frequency or clock frequency) Clock rates ranges from few hundred million to over a billion cycles per second The term cycles per second used to measrue clock rate is termed as Hertz (Hz). MillionMega(M), billion Giga (G) 500 million/second500 MHz 1250 million per second is 1.25 GHs
N S T R
The execution time T has to be minimized for better performance. For which values of N and S must be minimized and value of R must be enhanced at the same time.
Clock Rate
Increase clock rate
Improve the integrated-circuit (IC) technology to make the circuits faster
Reduce the amount of processing done in one basic step.This will reduce clock period P and enhances R the clock rate.
Performance Measurement
Measure computer performance using benchmark programs. System Performance Evaluation Corporation (SPEC) selects and publishes representative application programs for different application domains, together with test results for many commercially available computers. A benchmark program from a suite of benchmark program will be selected and compiled for test computer. The same benchmark program will be compiled and executed on one of the typical computer which be selected as a Reference Computer SPEC95- reference comp- sun sparc station SPEC2000- reference comp- Ultra sparc10 workstation with a 300MHz UltraSparc Processor
Performance Measurement
Running time on a Reference Computer SPEC Rating = Running time on a test Computer
pesse
computer organization
unit-1
37
EVOLUTION OF COMPUTERS
FIRST GENERATION (1945 1955)
Program and data reside in the same memory (stored program concepts John von Neumann) ALP was made used to write programs
Vacuum tubes were used to implement the functions (ALU & CU design)
Magnetic core and magnetic tape storage devices are used
pesse
computer organization
unit-1
38
pesse
computer organization
unit-1
39
pesse
computer organization
unit-1
40
pesse
computer organization
unit-1
41
pesse
computer organization
unit-1
42
Objectives
Machine instructions and program execution, including branching and subroutine call and return operations. Number representation and addition/subtraction in the 2s-complement system. Addressing methods for accessing register and memory operands. Assembly language for representing machine instructions, data, and programs. Program-controlled Input/Output operations.
Signed Integer
3 major representations:
Sign and magnitude Ones complement Twos complement In all three systems, the leftmost bit is 0 for positive and 1 for negative Positive numbers have identical representations in all systems, but negative values have different representations
Signed Integer
Assumptions:
4-bit machine word 16 different values can be represented Roughly half are positive, half are negative
+0
00 00 +1 00 01 00 10
11 01
+2 +3 +4
+ 0 10 0 = + 4 1 10 0 = - 4 -
00 11 01 00 01 01 01 10 10 00 01 11
+5
-1
+6
-0
+7
High order bit is sign: 0 = positive (or zero), 1 = negative Three low order bits is the magnitude: 0 (000) thru 7 (111) Range = -(2n-1 )-1 to +2n-1 -1 Two representations for 0
+0
00 00 +1 00 01 00 10
11 01
+2 +3 +4
+ 0 10 0 = + 4 1 01 1 = - 4 -
00 11 01 00 01 01 01 10 10 00 01 11
+5
-6
+6
-7
+7
In 1s complement -ve value is obtained by complementing each bit of the corresponding +ve value The operation of forming 1s complementing is equivalent to subtracting that no. from 2n -1 Still two representations of 0! This causes some problems
+0
00 00 +1 00 01 00 10
+2 +3 +4
+ 0 10 0 = + 4 1 10 0 = - 4 -
00 11 01 00 01 01 01 10 10 00 01 11
-6
10 10 10 01
+5
-7
+6
-8
+7
The operation of forming 2s complementing is equivalent to subtracting that no. from 2n 2s complement of a no. can be obtained by adding 1 to the 1s complement of that no. Only one representation for 0 One more negative number than positive number
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1
1 1 0 0 1 1 0 0 0 0 1 1 0 0 1 1
1 0 1 0 1 0 1 0 0 1 0 1 0 1 0 1
SIGNED 2S COMPLEMENT: Negative number is obtained by taking 2s complement of positive number i.e 2n-N Range: - (2n-1) to + (2n-1-1)
For signed arithmetic operation sign and magnitude and 1s complement format is not suitable
Rules for addition and subtraction of n bit signed numbers using 2s complement representation
If
Example of addition of n bit signed numbers using 2s complement representation +2 +3 + ---+5 ----0010 0011 ---------0101 --------+4 -6 -2 0100 + 1010 ------------1110 --------------6 +3 ----3 ---1010 + 0011 -------1101 ---------
Example of addition and subtraction of n bit signed numbers using 2s complement representation leading to overflow
+ -------
Overflow can occur only if two numbers having same signs are added
The carry out signal from the sign bit position is not a sufficient indicator of overflow when adding signed numbers A simple way to detect the overflow is to examine the signs of the two numbers X and Y and the sign of the result. When both the operands X and Y have the same sign, an over flow occurs when the sign of S is not the same as the signs of X and Y
Memory consists of millions of storage cells each capable of storing a bit of information Memory organized in a way such that a group of n bits can be stored or retrieved in a single basic operation n is the word length k-bit address computer generates an address space of 2k locations 24-bit address computer generates an address space of 224
locations i.e 16777216 locations
MEMORY ADDRESSING
MEMORY ADDRESSING
There are two ways of assigning byte addresses across words
BYTE ADDRESSABILITY
MEMORY ASSIGNMENT
LITTLE ENDIAN
BIG ENDIAN
k k k k k k k k
k k
2 -4
2 -4
2 -3
2- 2
2 - 1
2 - 4
2- 1
2 - 2
2 -3
2 -4
MEMORY OPERATION
STORE (WRITE)
LOAD(READ OR FETCH )
Transfers a copy of the contents of a specific memory location to the processor
Processor sends address of the desired location to memory and requests that its contents be read(Issues read signal) Memory reads the data and sends it to the processor Memory contents remains unchanged
STORE OR WRITE
Transfers an item of info from the cpu to a specific memory location, destroying the former contents of that location
Processor sends the address of the desired location to the memory, together with the data to be written
Issues write signal Sends the data via data bus and write into the selected particular memory location
locations, registers and I/O register names are identified by a symbolic name in uppercase alphabets
SUM,
LOOK_UP, are memory location which indicates the address of memory location
R1, R2 are register names DATAIN, OUTSTATUS are I/O register names
Contents of a location are denoted by placing square brackets around the name of the location ex:R1[LOC], R3 [R1]+[R2] RHS of RTN always denotes a values, and is called Source LHS of RTN always denotes a symbolic name where value is to be stored and is called destination Source contents are not modified Destination contents are overwritten
1. R2
[LOCN]
2. R4
[R3] +[R2]
TYPES OF INSTRUCTION
TYPES OF INSTRUCTION
Syntax: Operation source 1, source 2, destination Eg: ADD A,B,C Advantage: Single instruction can perform the complete operation
Disadvantage : Instruction code will be too large to fit in one word location in memory
Eg:
i.e
Add A,B
B[A]+[B]
MOVE B,C
Add A,C Disadvantage: Single instruction is not sufficient to perform the entire operation. Will not normally fit into one word
If processor supports ALU operations only with registers then the task C=A+B can be performed by the instruction sequence
Move A, Ri
Move
Add Move
B, Rj
Ri, Rj Rj, C
If processor supports ALU operations where one data may be in memory and other in register then the instruction sequence is for ADD A,B,C :
MOVE A, Ri ADD B, Ri MOVE Ri,C
i i+4 i+8
Move R0,C
Assumptions: - One memory operand per instruction - 32-bit word length - Memory is byte addressable - Full memory address can be directly specified in a single-word instruction Two-phase procedure -Instruction fetch -Instruction execute
Straight line sequencing: If fetching and executing of instructions is carried out one by one from successive addresses of memory, it is called straight line sequencing.
Major two phase of instruction execution
Instruction fetch phase: Instruction is fetched form memory and is placed in instruction register IR Instruction execute phase: Contents of IR is decoded and processor carries out the operation either by reading data from memory or registers.
Branching
i
i+4 i+8
Move NUM1,R0
Add Add NUM2,R0 NUM3,R0
i + 4n - 4 i + 4n Add NUMn,R0
Move R0,SUM
SUM NUM1 NUM2
NUMn
Move
N,R1 R0
Branching
LOOP
Program loop
Clear
Branch target
Conditional branch
Branch>0 Move
LOOP R0,SUM
SUM N NUM1 n
NUM2
NUM n
Branch instruction are those which changes the normal sequence of execution. Sequence can unconditionally. be changed either conditionally or
CONDITION CODES
Results of various instructions are stored for subsequent use by conditional instructions
This is done by recording the required info in individual bits, called as condition code flags grouped together in special processor register called as condition code register or status register
CONDITIONAL CODE FLAGS: 1 if results are Negative 0 if results are Positive Z Zero 1 if results are Zero 0 if results are Non zero V Overflow 1 if arithmetic overflow occurs 0 no overflow occurs C Carry 1 if carry and from MSB bit 0 if there is no carry from MSB bit N Negative
Addressing Modes
The different ways in which the location of an operand is specified in an instruction are referred to as addressing modes
Addressing Modes:
Immediate mode Absolute (Direct) mode
Register mode
Indirect mode Indexed mode Relative mode Auto increment mode
R2
R1 50 R0
A common convention say, a pound symbol # has to precede the value of an immediate operand Move #50, R0
Direct addressing scheme is simple to use and easy to implement without the requirement for additional hardware.
Examples
Move LOC,R0 Load P
Store S
The effective address of the operand is the contents of a register or memory location whose address appears in the instruction
Address Contents Move Move Clear LOOP Add Add Decrement Branch > 0 Move
It uses one less memory reference (memory read operation) Address field of the instruction uses a fewer bits to specify a register Register indirect addressing can be specified with Effective Address EA = (R) i.e. B Advantages of Indirect addressing: a wider address range to refer to a large number of memory locations. Disadvantage of Indirect addressing: 2 or more memory references (memory read operations) required to fetch the desired operand in memory.
Add 2000(R3),R4
Assume that a list of scores of the student beginning at location LIST as shown in the following diagram A 4 word memory comprises a record that stores relevant info for each student Compute the sum of all scores obtained on each of the test and store these sums in memory locations SUM1,SUM2,SUM3
LOOP
Move Clear Clear Clear Move Add Add Add Add Decrement Branch>0 Move Move Move
#LIST, R0 R1 R2 R3 N, R4 4(R0), R1 8(R0), R2 12(R0), R3 #16, R0 R4 LOOP R1, SUM1 R2, SUM2 R3, SUM3
Another version of the Index mode uses two registers plus a constant, which can be denoted as X(Ri, Rj) In this case, the effective address is the sum of the constant X and the contents of registers Ri and Rj. This added flexibility is useful in accessing multiple components inside each item in a record, where the beginning of an item is specified by the (Ri, Rj) part of the addressing mode.
instruction
Relative Mode specify Effective Address by a notation: X(PC) Effective address is EA = [ PC ] + X
Assembly Language
Here, symbolic codes are used to represent binary pattern of machine instructions. These symbolic codes are called as mnemonics. Mnemonics are abbreviations that represent operation code of an instruction in a compact and meaningful symbolic form. For instance mnemonics for few operation codes include:
INC / INR ADDI ADD LOAD STORE MOVE - Increment - To add immediate operand - To add - To load operand from memory - To store operand to memory - To transfer data from one location to another location/Register.
Assembly Language
A complete set of such mnemonics, symbolic names for register & memory locations and a list of rules for their use forms a programming language called an Assembly Language. The basic unit of assembly language program is a line of code. Here every line of code has symbolic code called mnemonic opcode and symbolic name to represent address of memory location / register as the operand field. The translator program is called an Assembler.
move instruction to appear as follows: MOVE R0, SUM The opcode mnemonic MOVE is followed by at least one blank space. The source operand is in register R0 (register operand). The destination operand is in the memory location SUM For instance symbolic name of operand memory location SUM suggest absolute mode or direct addressing mode is used in the instruction.
Assembler Directives
Assembler Directives are the assembler commands to the assembler concerning the program being assembled. These commands are neither translated into machine opcode nor assigned any memory location in the object program. Thus an assembly language program is said to be a complete one and acceptable to an assembler for translation and for further assignment of memory locations if it is associated with necessary assembler directives. Examples of Assembler Directives: S EQU 150 The assembler command EQU directs the assembler during translation that the symbolic name S must be replaced by value 150,
. . . NUMn 604
LOOP
Assembler Directives
ORIGIN 204 Instruct assembler to place data block at main memory locations starting from 204 N DATAWORD 100 Inform the assembler that value of N i.e. data value 100 is to be placed in the memory location 204. ORIGIN 100 The second ORIGIN directive states that assembler directive must load machine instructions of the object program in the main memory starting from location 100.
NUM1 RESERVE 400 This directive declares that a memory block of 400 bytes is to be reserved for data, and that the name NUM1 is to be associated with address 208
RETURN This is an assembler directive that identifies the point at which execution of the program should be terminated. It causes the assembler to insert an appropriate machine instruction that returns control to the operating system of the computer.
END START The last statement in the source program is the assembler directive END, which tells the assembler that this is the end of the source program text. The END directive includes the label START, which is the address of the location at which execution of the program is to begin.
When a name appears a second time, it is replaced with its value from the table A problem arises when a name appears as an operand before it is given a value. For example, this happens if a forward branch is required A simple solution to this problem is to have the assembler scan through the source program twice During the first pass, it creates a complete symbol table. At the end of this pass, all names will have been assigned numerical values The assembler then goes through the source program a second time and substitutes values for all names from the symbol table. Such an assembler is called a two-pass assembler.
The assembler stores the object program on a magnetic disk The object program must be loaded into the memory of the computer before it is executed. This task is performed by an utility program called a loader
NUMBER NOTATION
ADD #93, R1 or ADD #%01011101, R1 or ADD #$5D, R1
Mechanism of I/O transfer between Processor and Keyboard & Video monitor
A similar set of events take place while transferring a character data from processor to the display screen. Here a DATAOUT register that holds a characters code to be displayed when synchronization control flag SOUT is set to 1. When SOUT equals 1, the display device is ready to receive a character from processor. The transfer of a character to DATAOUT resets SOUT to 0. I/O driver program instructions control the status of SOUT flag.
SOUT is set to 1 when display terminal is free to display next character. The wait loop is executed repeatedly until the control flag SOUT is set to 1 by the display terminal. Initial state of SIN is 0 and SOUT is 1
Memory mapped i/o some memory addresses refer to peripheral device buffer registers, such as DATAIN,DATAOUT Data can be transferred b/w the cpu and these registers using same set of instructions and same status flags Ex: MoveByte DATAIN,R0 MoveByte R0,DATAOUT Status flags SIN and SOUT can be included device status register Assume that the bit b3 of the status registers INSTATUS,OUTSTATUS corresponds to SIN and SOUT
MoveByte DATAIN,R0
WRITEWAIT
TestBit
#3,OUTSTATUS
Branch=0 WRITEWAIT
MoveByte R0,DATAOUT
READ
ECHO
TestBit #3,INSTATUS Branch=0 READ MoveByte DATAIN,(R0) TestBit #3,OUTSTATUS Branch=0 ECHO MoveByte (R0),DATAOUT Compare #CR,(R0)+
branch!=0 READ
SP->
BOTTOM
. . 12 -98 . . 55 . .
2k-1
If the processor has the autoincr and autodecr addressing modes, then push and pop operation can be performed by single operations:
To prevent either the pushing an item on a full stack or popping an item off an empty stack, the single push and pop operation can be replaced by the following instructions: SAFEPOP Compare #2000,SP Branch>0 EMPTYERROR Move (SP)+,ITEM SAFEPUSH Compare #1500,SP Branch<=0 FULLERROR Move NEWITEM,-(SP)
Needs only one pointer register SP Insertions & Deletions are made from only one end i.e., Top of stack Stack operations are PUSH & POP
Needs two pointer registers QF & QE Insertion from back end and Deletion from front end of a Queue Queue operations are QINSERT & QDELETE
Subroutines
A subroutine is a self contained sub-program designed to be used by other larger programs or main programs. A task which is required to be carried out frequently, is usually implemented as a subroutine. Subroutine mechanisms make use of two kinds of branch instructions: First, a call instruction that branches from the present location in calling program or main program to the location in main memory at which subroutine begins. Second, a return instruction that returns from the subroutine to the location in calling program or main program from which it was called.
The common places for storing the return addresses: Link register
Call-is a special branch instruction which performs the following sequence of operations: 1. Copy the contents of PC (i.e. address of next instruction in sequence following a call instruction in a main program) to link register 2. Transfer control to the beginning of subroutine (the starting address of subroutine is specified in the Call instruction itself)
Return is a special branch instruction which performs : Transfer control to the return address contained in link register.
The way in which a computer makes it possible to call and return from subroutines is referred to as its subroutine linkage method.
These return addresses are popped up inturn in a manner that suites subroutines return address behaviour for resuming calling program execution. For example : Execution of main program (MAIN) take place in the following sequence of program segments:
Parameter Passing
When a program calls a subroutine, it must supply the necessary operands or data to be operated upon by the instructions of called subroutine. These operands are referred to as parameters or arguments. There are many ways of parameter passing such as pass by value, pass by reference etc. Parameters can be placed in register, memory location or processor stack from where they can be accessed by subroutine
Example
Move N,R1 Move #NUM1,R2 Call LISTADD Move R0,SUM LISTADD LOOP Clear R0 Add (R2)+,R0 Decrement R1 Branch>0 LOOP Return
Example
Move #NUM1,-(SP) Move N,-(SP) Call LISTADD Move 4(SP),SUM Add #8,SP
LISTADD
LOOP
MoveMultiple R0-R2,-(SP) Move 16(SP),R1 Move 20(SP),R2 Clear R0 Add (R2)+,R0 Decrement R1 Branch>0 LOOP Move R0,20(SP) MoveMultiple (SP)+,R0-R2 Return
level 2
Return Address N
NUM1
level 1
Stack Frame
The consecutive location on stack that hold list of parameter including local variables and return address pertaining to a subroutine call & return, constitute a private work space called stack frame of the subroutine. The stack frame locations get filled as and when each subroutine is called for execution. Also, stack frame space is vacated soon after the completion of execution of subroutine it is useful to have another pointer register, called the frame pointer (FP), for convenient access to the parameters passed to the subroutine and to the local memory variables used by the subroutine The pointers SP and FP are manipulated as the stack frame is built, used, and dismantled for a particular of the subroutine.
Assume that SP point to the old top-of-stack (TOS) element Assume that four parameters are passed to the subroutine, three local variables are used within the subroutine, and registers R0 and R1 need to be saved because they will also be used within the subroutine. Before the subroutine is called, the calling program pushes the four parameters onto the stack The call instruction is then executed, resulting in the return address being pushed onto the stack.
Now, SP points to this return address, and the first instruction of the subroutine is about to be executed. This is the point at which the frame pointer FP is set to contain the proper memory address. Since FP is usually a general-purpose register, it may contain information of use to the Calling program. Therefore, its contents are saved by pushing them onto the stack Since the SP now points to this position, its contents are copied into FP
Thus, the first two instructions executed in the subroutine are Move FP, -(SP) Move SP, FP After these instructions are executed, both SP and FP point to the saved FP contents Space for the three local variables is now allocated on the stack by executing the instruction Subtract #12, SP Finally, the contents of processor registers R0 and R1 are saved by pushing them onto the stack. At this point, the stack frame has been set up as shown in the fig.
SP
FP
Saved [R1] Saved [R0] Localvar3 Localvar2 Localvar1 Saved [FP] Return address Param1 Param2 Param3 Param4
Old TOS
The subroutine now executes its task. When the task is completed, the subroutine pops the saved values of R1 and R0 back into those registers, removes the local variables from the stack frame by executing the instruction. Add #12, SP And pops the saved old value of FP back into FP. At this point, SP points to the return address, so the Return instruction can be executed, transferring control back to the calling program.
Calling program is responsible for removing the parameters from the stack frame, some which may be the results passed back by the subroutine The SP now points to the old TOS
The flow of execution is as follows. The main program pushes the two parameters param2 and param1 onto the stack in that order and then calls SUB1. This first subroutine is responsible for computing a single answer and passing it back to the main program on the stack. During the course of its computations, SUB1 calls the second subroutine, SUB2, in order to perform some subtask. SUB1 passes a single parameter param3 to SUB2 and gets a result passed back to it.
After SUB2 executes its Return instruction, this result is stored in register R2 by SUB1. SUB1 then continues its computations and eventually passes the required answer back to the main program on the stack. When SUB1 executes its return to the main program, the main program stores this answer in memory location RESULT and continues with its computations at next instruction.
flow of execution The first actions performed by each subroutine are to set the frame pointer, after saving its previous contents on the stack, and to save any other registers required. SUB1 uses four registers, R0 to R3, and SUB2 uses two registers, R0 and R1. These registers and the frame pointer are restored just before the returns are executed.
The Index addressing mode involving the frame pointer register FP is used to load parameters from the stack and place answers back on the stack. The byte offsets used in these operations are always 8, 12, . . . , as discussed for the general stack frame Finally, note that the calling routines are responsible for removing parameters from the stack. This is done by the Add instruction in the main program, and by the Move instruction at location 2164 in SUB1.
LOGIC INSTRUCTIONS
Logic operations are applied to individual bits, are the basic building blocks of digital circuits
AND OR NOT
Not dst
Logical shifts
Two logical shift instructions shifting left (LShiftL) shifting right (LShiftR) These instructions shift an operand over a number of bit positions specified in a count operand contained in the instruction. The general form of a logical left shift instruction is LShiftL count, dst
Before:
0 0 1 1 1 0 . . . 0 1 1
After:
1 1 0 . . . 0 1 1 00
R0
0 1 1 1 0 . . . 0 1 1
After:
0 0 0 1 1 1 0 . . . 0
Digit-Packing Example
Suppose that two decimal digits represented in ASCII code are located in memory at byte locations LOC and LOC + 1. Each of these digits should be represented in the 4-bit BCD code and store both of them in a single byte location PACKED. This result is said to be in packed-BCD format. The rightmost four bits of the ASCII code for a decimal digit correspond to the BCD code for the digit.
Hence, the required task is to extract the loworder four bits in LOC and LOC + 1 and concatenate them into the single byte at PACKED. The instruction sequence accomplishes the task using register R0 as a pointer to the ASCII characters in memory, and using registers R1 and R2 to develop the BCD digit codes.
When a MoveByte instruction transfers a byte between memory and a 32-bit processor register, the byte is located in the rightmost eight bit positions of the register. The And instruction is used to mask out all but the four rightmost bits in R2.
Arithmetic shifts
Arithmetic shift right AShiftR #2, R0
R0
Before:
1 0 0 1 1 . . . 0 10 0
After:
1 1 1 0 0 1 1 . . . 0
Rotate Operations
In the shift operations, the bits shifted out of the operand are lost, except for the last bit shifted out which is retained in the Carry flag C. To preserve all bits, a set of rotate instructions can be used. They move the bits that are shifted out of one end of the operand back into the other end Two versions of both the left and right rotate instructions are usually provided. In one version, the bits of the operand are simply rotated. In the other version, the rotation includes the C flag.
Before:
0 0 1 1 1 0 . . . 0 1 1
After:
1 1 0 . . . 0 1 1 0 1
Before:
0 0 1 1 1 0 . . . 0 1 1
After:
1 1 0 . . . 0 1 1 00
R0 C
Before:
0 1 1 1 0 . . . 0 1 1 0
After:
1 1 0 1 1 1 0 . . . 0
R0 C
Before:
0 1 1 1 0 . . . 0 1 1 0
After:
1 0 0 1 1 1 0 . . . 0
MULTIPLY Ri, Rj
DIVIDE Ri, Rj
8
Opcode
7
Source
7
Dest
10
Other info
one-word instruction
Opcode Source Dest Other info
Two approaches: CISC & RISC CISC: A computer or a processor with a large number of instructions and incorporating variable length instruction formats (i.e. using multiple words for instructions) is termed a Complex Instruction Set Computer abbreviated as CISC
Salient feature of RISC architecture : A computer or processor with relatively small set of instruction and incorporating fixed length instruction format most of them being a register to register operations, is termed as Reduced Instructions Set Computer abbreviated as RISC Features of RISC architecture include: Support relatively few instructions and are less complex Support few addressing modes Comprises fixed length instructions that can be easily decoded A restriction to perform all operations in processor registers only.
instructions
Ability to execute one instruction per clock cycle Examples of RISC processors
End of unit 2