experiment no: 01 problem statement - be...

22
EXPERIMENT NO: 01 PROBLEM STATEMENT: Write a program to convert decimal number to binary and vice versa. THEORY: A number system is a systematic way to represent numbers with symbolic characters and uses a base value to conveniently group numbers in compact form. The most common number system is decimal, which has a base value of 10, and a symbolic character set of 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. However, there are other number systems, and they can be more efficient to use for a specific purpose. For example, following table shows different number systems: NUMBER SYSTEM BASE VALUE SYMBOLIC CHARACTER SET Binary 2 0,1 Octal 8 0, 1, 2, 3, 4, 5, 6, 7 Decimal 10 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 Hexadecimal 16 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F ALGORITHM: Conversion of Decimal to Binary- Step 1 - Divide the decimal number by 2 Step 2 - Get the remainder from Step 1 as the rightmost digit (least significant digit) of binary number. Step 3 - Divide the new quotient by 2. Step 4 - Record the remainder from Step 3 as the next digit (to the left) of the binary number. Step 5: Repeat Steps 3 and 4, until the quotient becomes zero in Step 3. EXAMPLE Decimal Number: 29 10 Calculating Binary Equivalent: Step Operation Result Remainder Step 1 29 / 2 14 1 Step 2 14 / 2 7 0 Step 3 7 / 2 3 1 Step 4 3 / 2 1 1 Step 5 1 / 2 0 1

Upload: tranque

Post on 16-Mar-2018

214 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: EXPERIMENT NO: 01 PROBLEM STATEMENT - BE …cebdiv.weebly.com/uploads/3/8/1/6/38163583/lab_manual_coa_(1).pdf · EXPERIMENT NO: 01 PROBLEM STATEMENT: ... Conversion of binary to Decimal-

EXPERIMENT NO: 01

PROBLEM STATEMENT:

Write a program to convert decimal number to binary and vice versa.

THEORY:

A number system is a systematic way to represent numbers with symbolic characters

and uses a base value to conveniently group numbers in compact form. The most

common number system is decimal, which has a base value of 10, and a symbolic

character set of 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. However, there are other number

systems, and they can be more efficient to use for a specific purpose. For example,

following table shows different number systems:

NUMBER SYSTEM BASE VALUE SYMBOLIC CHARACTER SET

Binary 2 0,1

Octal 8 0, 1, 2, 3, 4, 5, 6, 7

Decimal 10 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9

Hexadecimal 16 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F

ALGORITHM:

Conversion of Decimal to Binary-

Step 1 - Divide the decimal number by 2

Step 2 - Get the remainder from Step 1 as the rightmost digit (least significant digit)

of binary number.

Step 3 - Divide the new quotient by 2.

Step 4 - Record the remainder from Step 3 as the next digit (to the left) of the binary

number.

Step 5: Repeat Steps 3 and 4, until the quotient becomes zero in Step 3.

EXAMPLE

Decimal Number: 2910

Calculating Binary Equivalent:

Step Operation Result Remainder

Step 1 29 / 2 14 1

Step 2 14 / 2 7 0

Step 3 7 / 2 3 1

Step 4 3 / 2 1 1

Step 5 1 / 2 0 1

Page 2: EXPERIMENT NO: 01 PROBLEM STATEMENT - BE …cebdiv.weebly.com/uploads/3/8/1/6/38163583/lab_manual_coa_(1).pdf · EXPERIMENT NO: 01 PROBLEM STATEMENT: ... Conversion of binary to Decimal-

As mentioned in Steps 2 and 4, the remainders have to be arranged in the reverse

order so that the first remainder becomes the least significant digit (LSD) and the last

remainder becomes the most significant digit (MSD).

Decimal Number: 2910 = Binary Number: 111012.

Conversion of binary to Decimal-

Step 1 - Determine the positional value of each digit (this depends on the position of

the digit and the base of the number system).

Step 2 - Multiply the obtained positional values (in Step 1) by the digits in the

corresponding position.

Step 3 - Sum the products calculated in Step 2. The total is the equivalent value in

decimal.

EXAMPLE

(11101001)2

1×27+1×2

6+1×2

5+0×2

4+1×2

3+0×2

2+0×2

1+1×2

0

= (233)10

CONCLUSION:

Implementation of Binary to Decimal and Decimal to Binary conversion performed

successfully.

Page 3: EXPERIMENT NO: 01 PROBLEM STATEMENT - BE …cebdiv.weebly.com/uploads/3/8/1/6/38163583/lab_manual_coa_(1).pdf · EXPERIMENT NO: 01 PROBLEM STATEMENT: ... Conversion of binary to Decimal-

EXPERIMENT NO: 02

PROBLEM STATEMENT:

Write a program to implement multiplication of two unsigned binary numbers.

THEORY:

Compared with addition and subtraction, multiplication is a complex operation,

whether performed in hardware or software. Multiplication of two unsigned number is

done as follows:

1. The partial products are easily defined. When the multiplier bit is 0, the partial

product is 0.When the multiplier is 1, the partial product is the multiplicand.

2. Multiplication involves the generation of partial products, one for each digit in

the multiplier. These partial products are then summed to produce the final

product.

3. The total product is produced by summing the partial products. For this

operation, each successive partial product is shifted one position to the left

relative the preceding partial product.

4. The multiplication of two n-bit binary integers results in a product of up to 2n

bits in length.

Example :

Figure shows a possible implementation employing these measures. The multiplier

and multiplicand are loaded into two registers (Q and M). A third register, the A

register, is also needed and is initially set to 0. There is also a 1-bit C register,

initialized to 0, which holds a potential carry bit resulting from addition. The

operation of the multiplier is as follows. Control logic reads the bits of the multiplier

one at a time. If Q0 is 1, then the multiplicand is added to the A register and the result

is stored in the A register, with the C bit used for overflow. Then all of the bits of the

C, A, and Q registers are shifted to the right one bit, so that the C bit goes into A n-1

and A0 goes into Qn-1 goes into and is lost. If Q0 is 0, then no addition is performed,

just the shift. This process is repeated for each bit of the original multiplier. The

resulting -bit product is contained in the A and Q registers.

Page 4: EXPERIMENT NO: 01 PROBLEM STATEMENT - BE …cebdiv.weebly.com/uploads/3/8/1/6/38163583/lab_manual_coa_(1).pdf · EXPERIMENT NO: 01 PROBLEM STATEMENT: ... Conversion of binary to Decimal-

The flowchart for unsigned binary multiplication is as follows:

CONCLUSION:

The program to perform multiplication of two binary numbers was performed and

output obtained.

Page 5: EXPERIMENT NO: 01 PROBLEM STATEMENT - BE …cebdiv.weebly.com/uploads/3/8/1/6/38163583/lab_manual_coa_(1).pdf · EXPERIMENT NO: 01 PROBLEM STATEMENT: ... Conversion of binary to Decimal-

EXPERIMENT NO: 03

PROBLEM STATEMENT:

Write a program to implement multiplication of 2, two’s complement numbers using

Booth’s algorithm.

THEORY:

Booth's multiplication algorithm is a multiplication algorithm that multiplies two

signed binary numbers in two's complement notation. The algorithm was invented

by Andrew Donald Booth in 1950 while doing research

on crystallography at Birkbeck College in Bloomsbury, London. Booth used desk

calculators that were faster at shifting than adding and created the algorithm to

increase their speed.

Booth's algorithm examines adjacent pairs of bits of the N-bit multiplier Y in

signed two's complement representation, including an implicit bit below the least

significant bit, y-1 = 0. For each bit yi, for i running from 0 to N-1, the bits yi and yi-

1 are considered. Where these two bits are equal, the product accumulator P is left

unchanged. Where yi = 0 and yi-1 = 1, the multiplicand times 2i is added toP; and

where yi = 1 and yi-1 = 0, the multiplicand times 2i is subtracted from P. The final

value of P is the signed product.

The representation of the multiplicand and product are not specified; typically, these

are both also in two's complement representation, like the multiplier, but any number

system that supports addition and subtraction will work as well. As stated here, the

order of the steps is not determined. Typically, it proceeds from LSB to MSB, starting

at i = 0; the multiplication by 2i is then typically replaced by incremental shifting of

the P accumulator to the right between steps; low bits can be shifted out, and

subsequent additions and subtractions can then be done just on the highest N bits

of P.[1]

There are many variations and optimizations on these details.

The algorithm is often described as converting strings of 1's in the multiplier to a

high-order +1 and a low-order –1 at the ends of the string. When a string runs through

the MSB, there is no high-order +1, and the net effect is interpretation as a negative of

the appropriate value.

Page 6: EXPERIMENT NO: 01 PROBLEM STATEMENT - BE …cebdiv.weebly.com/uploads/3/8/1/6/38163583/lab_manual_coa_(1).pdf · EXPERIMENT NO: 01 PROBLEM STATEMENT: ... Conversion of binary to Decimal-

Flow Chart/Diagram of Booth's Algorithm of Multiplication:-

Example of Booth's Multiplication Algorithm:-Multiply 7 with 3 with the help of

Booth's Algorithm.

Result= AQ = (0001 0101)2 = (21)10

CONCLUSION:

The program to perform multiplication of two signed numbers using Booth’s

Algorithm was performed and output obtained.

Page 7: EXPERIMENT NO: 01 PROBLEM STATEMENT - BE …cebdiv.weebly.com/uploads/3/8/1/6/38163583/lab_manual_coa_(1).pdf · EXPERIMENT NO: 01 PROBLEM STATEMENT: ... Conversion of binary to Decimal-

EXPERIMENT NO: 04

PROBLEM STATEMENT:

Write a program to implement division of two unsigned numbers using Restoring

algorithm.

THEORY:

The division operation consists of a series of subtractions of the divisor from the

partial remainder, which are only executed if the divisor is smaller than the partial

remainder, when the digit of the quotient is 1; otherwise, the corresponding digit of

the quotient is 0. Consider the division of two numbers: 147 / 11

Flow chart for Restoring division algorithm

Page 8: EXPERIMENT NO: 01 PROBLEM STATEMENT - BE …cebdiv.weebly.com/uploads/3/8/1/6/38163583/lab_manual_coa_(1).pdf · EXPERIMENT NO: 01 PROBLEM STATEMENT: ... Conversion of binary to Decimal-

Restoring Division Example: 14/3

Result is

Remainder in A= (0010)2 = (2)10

Quotient in Q= (0100)2 = (4)10

CONCLUSION:

Implementation of multiplication using restoring Algorithm was performed

successfully and output obtained.

Page 9: EXPERIMENT NO: 01 PROBLEM STATEMENT - BE …cebdiv.weebly.com/uploads/3/8/1/6/38163583/lab_manual_coa_(1).pdf · EXPERIMENT NO: 01 PROBLEM STATEMENT: ... Conversion of binary to Decimal-

EXPERIMENT NO: 05

PROBLEM STATEMENT:

Write a program to implement division of 2, two’s complement numbers using non

restoring algorithm.

THEORY:

This algorithm works for both positive and negative number division. In this, we have

to represent dividend and divisor in two’s complement number.

Example

Dividend (A) = 1001, i.e. 7, and Divisor (B) = 0011, i.e. 3.

Initialization:

Set Register A = Dividend = 1111

Set Register Q = Dividend = 1001 (So AQ =1111 1001)

Set M = Divisor = 0011, M' = 2's complement of M = 1101

Set Count =4, since 4 digits operation is being done here.

After this we start the algorithm, which is shown below:

A Q Action

1111 1001 Initial state

1111 0010 Left shift A, Q

+0011

0010 0010 A=A+M (A and M have different signs)

1111 0010 Restore A and Q0=0 ------- cycle 1

1110 0100 Left shift A, Q

+0011 0100

0001 0100 A=A+M (A and M have different signs)

1110 0100 Restore A and Q0=0 ------- cycle 2

1100 1000 Left shift A, Q

+0011

1111 1001 A=A+M (A and M have different signs)

1111 1001 set Q0=1 ------- cycle 3

1111 0010 Left shift A, Q

+0011

0010 0010 A=A+M (A and M have different signs)

1111 0010 Restore A and Q0=0 ------- cycle 4

Result is:

Remainder is in A= (1111)2 = (-1)10

Quotient = Two’s complement of Q = (1110)2 = (-2)10

Page 10: EXPERIMENT NO: 01 PROBLEM STATEMENT - BE …cebdiv.weebly.com/uploads/3/8/1/6/38163583/lab_manual_coa_(1).pdf · EXPERIMENT NO: 01 PROBLEM STATEMENT: ... Conversion of binary to Decimal-

ALGORITHM:

Step 1: Load the divisor into M register and dividend in A, Q registers. The dividend

must be expressed as 2n bit two’s complement number. For ex: 4 bit 0111 becomes

0000 0111 and 1011 becomes 1111 1011.

Step 2: Left shift A, Q by 1 bit.

Step3: If M and A have the same signs, perform A=A-M otherwise A=A+M.

Step 4: The Preceding operation is successful if the sign of A is the same before and

after the operation.

(a) If the operation is successful or A=0 then set Q0=1.

(b) If the operation is unsuccessful and A!=0 then set Q0=0 and restore the

previous value of A.

Step 5: Repeat steps 2 to 4 as many times as there are bit positions in Q.

Step 6: Remainder is in A. If the signs of the divisor and dividend were the same,

then the quotient is in Q; otherwise the correct quotient is the two’s complement of Q.

CONCLUSION:

The program to perform multiplication of two numbers using restoring Algorithm was

performed and output obtained.

Page 11: EXPERIMENT NO: 01 PROBLEM STATEMENT - BE …cebdiv.weebly.com/uploads/3/8/1/6/38163583/lab_manual_coa_(1).pdf · EXPERIMENT NO: 01 PROBLEM STATEMENT: ... Conversion of binary to Decimal-

EXPERIMENT NO: 06

PROBLEM STATEMENT:

Implementation of FIFO page replacement policy of virtual memory.

THEORY:

Regardless of the resident set management strategy, there are certain basic algorithms

that are used for the selection of a page to replace in main memory. General page

replacement algorithms

include-

First-in-first-out (FIFO)

Least recently used (LRU)

Optimal

The first-in-first-out (FIFO) policy:

It treats the page frames allocated to a process as a circular buffer, and pages are

removed in round-robin style. All that is required is a pointer that circles through the

page frames of the process. This is therefore one of the simplest page replacement

policies to implement. The logic behind this choice, other than its simplicity, is that

one is replacing the page that has been in memory the longest: A page fetched into

memory a long time ago may have now fallen out of use. This reasoning will often be

wrong, because there will often be regions of program or data that are heavily used

throughout the life of a program. Those pages will be repeatedly paged in and out by

the FIFO algorithm. In the below example, FIFO policy results in six page faults.

Note that LRU recognizes that pages 2 and 5 are referenced more frequently than

other pages, whereas FIFO does not.

Example:

ALGORITHM:

FIFO – First in first out

1. Accept frame size(fno), Number of pages(count) and sequence of

pages(arr[100]) from user

2. Create circular linked list whose size is equal to frame size

3. Initialize each node’s data = -99

4. Call create function for CLL

5. When inserting data in a frame check whether

a. Page number is already present or not

b. There is empty location or not

6. If page is present then don’t take any action, and read next page

Page 12: EXPERIMENT NO: 01 PROBLEM STATEMENT - BE …cebdiv.weebly.com/uploads/3/8/1/6/38163583/lab_manual_coa_(1).pdf · EXPERIMENT NO: 01 PROBLEM STATEMENT: ... Conversion of binary to Decimal-

7. But if page is not present then we have to insert page in LL

8. If Linked List have empty node then goto step 7

9. If Linked List doesn’t have empty node then overwrite on the oldest node

10. stop

CONCLUSION:

We studied FIFO page replacement algorithm and implemented successfully.

Page 13: EXPERIMENT NO: 01 PROBLEM STATEMENT - BE …cebdiv.weebly.com/uploads/3/8/1/6/38163583/lab_manual_coa_(1).pdf · EXPERIMENT NO: 01 PROBLEM STATEMENT: ... Conversion of binary to Decimal-

EXPERIMENT NO: 07

PROBLEM STATEMENT:

Implementation of LRU page replacement policy of virtual memory.

THEORY:

Regardless of the resident set management strategy, there are certain basic algorithms

that are used for the selection of a page to replace in main memory. General page

replacement algorithms

include-

First-in-first-out (FIFO)

Least recently used (LRU)

Optimal

The least recently used (LRU) policy:

It replaces the page in memory that has not been referenced for the longest time. By

the principle of locality, this should be the page least likely to be referenced in the

near future. And, in fact, the LRU policy does nearly as well as the optimal policy.

The problem with this approach is the difficulty in implementation. One approach

would be to tag each page with the time of its last reference; this would have to be

done at each memory reference, both instruction and data. Even

if the hardware would support such a scheme, the overhead would be tremendous.

Alternatively, one could maintain a stack of page references, again an expensive

prospect.

Figure shows an example of the behavior of LRU, using the same page address stream

as

for the optimal policy example. In this example, there are four page faults.

Example:

ALGORITHM:

LRU - Least Recently Used

1. Start

2. Declare the size of frame

3. Get the number of pages to be inserted

4. Get the sequence of pages

5. Declare counter and stack

6. Select the least recently used page by counter value

7. Stack them according the selection.

8. Display the values

9. Stop

Page 14: EXPERIMENT NO: 01 PROBLEM STATEMENT - BE …cebdiv.weebly.com/uploads/3/8/1/6/38163583/lab_manual_coa_(1).pdf · EXPERIMENT NO: 01 PROBLEM STATEMENT: ... Conversion of binary to Decimal-

CONCLUSION:

We studied LRU page replacement algorithm and implemented successfully.

Page 15: EXPERIMENT NO: 01 PROBLEM STATEMENT - BE …cebdiv.weebly.com/uploads/3/8/1/6/38163583/lab_manual_coa_(1).pdf · EXPERIMENT NO: 01 PROBLEM STATEMENT: ... Conversion of binary to Decimal-

EXPERIMENT NO: 08

PROBLEM STATEMENT:

Implementation of memory allocation algorithms.

1. First – Fit

2. Best – Fit

3. Worst Fit

Theory:

Memory compaction is time consuming; the operating system designer must be clever

in deciding how to assign processes to memory (how to plug the holes). When it is

time to load or swap a process into main memory, and if there is more than one free

block of memory of sufficient size, then the operating system must decide which free

block to allocate.

Four placement algorithms that might be considered are best-fit, first-fit, worst-fit and

next-fit. All are limited to choosing among free blocks of main memory that are equal

to or larger than the process to be brought in. Best-fit chooses the block that is closest

in size to the request. First-fit begins to scan memory from the beginning and chooses

the first available block that is large enough. Next-fit begins to scan memory from the

location of the last placement, and chooses the next available block that is large

enough. Worst-fit chooses largest empty block of all. Figure (a) below shows an

example memory configuration after a number of placement and swapping-out

operations. The last block that was used was a 22-Mbyte block from which a 14-

Mbyte partition was created. Best-fit will search the entire list of available blocks and

make use of the 18-Mbyte block, leaving a 2-Mbyte fragment. First-fit results in a 6-

Mbyte fragment, and next-fit results in a 20-Mbyte fragment. Which of these

approaches is best will depend on the exact sequence of process swapping that occurs

and the size of those processes.

The first-fit algorithm is not only the simplest but usually the best and fastest as well.

The next-fit algorithm tends to produce slightly worse results than the first-fit. The

next-fit algorithm will more frequently lead to an allocation from a free block at the

end of memory. The result is that the largest block of free memory, which usually

appears at the end of the memory space, is quickly broken up into small fragments.

Thus, compaction may be required more frequently with

next-fit. On the other hand, the first-fit algorithm may litter the front end with small

free partitions that need to be searched over on each subsequent first-fit pass. The

best-fit algorithm,

despite its name, is usually the worst performer. Because this algorithm looks for the

smallest block that will satisfy the requirement, it guarantees that the fragment left

behind is as small as possible. Although each memory request always wastes the

smallest amount of memory, the result is that main memory is quickly littered by

blocks too small to satisfy memory allocation requests. Thus, memory compaction

must be done more frequently than with the other algorithms.

Given memory partitions of 100K, 500K, 200K, 300K, and 600K (in order), how

would each of the First-fit, Best-fit, and Worst-fit algorithms place processes of 212K,

417K, 112K, and 426K (in order)? Which algorithm makes the most efficient use of

memory?

Page 16: EXPERIMENT NO: 01 PROBLEM STATEMENT - BE …cebdiv.weebly.com/uploads/3/8/1/6/38163583/lab_manual_coa_(1).pdf · EXPERIMENT NO: 01 PROBLEM STATEMENT: ... Conversion of binary to Decimal-

First-fit:

212K is put in 500K partition

417K is put in 600K partition

112K is put in 288K partition (new partition 288K = 500K - 212K)

426K must wait

Best-fit:

212K is put in 300K partition

417K is put in 500K partition

112K is put in 200K partition

426K is put in 600K partition

Worst-fit:

212K is put in 600K partition

417K is put in 500K partition

112K is put in 388K partition (600K – 212K)

426K must wait

In this example, Best-fit turns out to be the best.

ALGORITHM:

First Fit Algorithm

1. Start

2. Accept no. of partition(n) and size of each partition(S[i]) and no. of processes(P)

and size of each process(SP[i]) from user.

3. Declare i, j, flag[10]

4. for(i=0;i<n;i++)

5. Initialize flag[i]=0

6. End of for loop

7. for(i=0; i<n; i++)

8. for(j=0;j<p;j++)

9. if( (s[i]>=sp[j]) && (flag[j]==0) ) then

flag[j]=1;

printf("\nP%d",j);

printf(" %d\t\t%d",sp[j],s[i]);

break;

10. End of if

11. End of for loop

12. End of for loop

13. End

Best Fit Algorithm:

Page 17: EXPERIMENT NO: 01 PROBLEM STATEMENT - BE …cebdiv.weebly.com/uploads/3/8/1/6/38163583/lab_manual_coa_(1).pdf · EXPERIMENT NO: 01 PROBLEM STATEMENT: ... Conversion of binary to Decimal-

1. Start

2. Accept no. of partition(n) and size of each partition(S[i]) and no. of processes(P)

and size of each process(SP[i]) from user.

3. Declare i, j, flag[10], temp

4. for(i=0;i<n;i++)

5. for(j=i+1;j<n;j++)

6. if(s[i]>=s[j]) then

temp=s[i]

s[i]=s[j]

s[j]=temp

7. End of if

8. End of for

9. End of for

10. for(i=0;i<n;i++)

11. flag[i]=0

12. for(i=0;i<n;i++)

13. for(j=0;j<p;j++)

14. if( (s[i]>=sp[j]) && (flag[j]==0) ) then

flag[j]=1;

printf("\nP%d",j);

printf(" %d\t\t%d",sp[j],s[i]);

break;

15. End of if

16. End of for

17. end of for

18. end

Worst Fit algorithm

1. Start

2. Accept no. of partition(n) and size of each partition(S[i]) and no. of processes(P)

and size of each process(SP[i]) from user.

3. Declare i, j, flag[10], temp

4. for(i=0;i<n;i++)

5. for(j=i+1;j<n;j++)

6. if(s[i]<=s[j]) then

temp=s[i];

s[i]=s[j];

s[j]=temp

7. End of if

8. End of for

9. End of for

10. End

CONCLUSION:

Implementation of memory allocation algorithms performed successfully and

obtained output.

Page 18: EXPERIMENT NO: 01 PROBLEM STATEMENT - BE …cebdiv.weebly.com/uploads/3/8/1/6/38163583/lab_manual_coa_(1).pdf · EXPERIMENT NO: 01 PROBLEM STATEMENT: ... Conversion of binary to Decimal-

EXPERIMENT NO: 09

PROBLEM STATEMENT:

To Study and implementation of Data Hazards

THEORY:

In the domain of central processing unit (CPU) design, hazards are problems with

the instruction pipeline in CPU micro architectures when the next instruction cannot

execute in the following clock cycle,[1]

and can potentially lead to incorrect

computation results. There are typically three types of hazards:

data hazards

structural hazards

control hazards (branching hazards)

Data hazards

Data hazards occur when instructions that exhibit data dependence modify data in

different stages of a pipeline. Ignoring potential data hazards can result in race

conditions (sometimes known as race hazards).

The use of the result of the SUB instruction in the next three instructions causes a data

hazard, since the register $2 is not written until after those instructions read it.

There are three situations in which a data hazard can occur:

1. read after write (RAW), a true dependency

2. write after read (WAR), an anti-dependency

3. write after write (WAW), an output dependency

Consider two instructions i1 and i2, with i1 occurring before i2 in program order.

Page 19: EXPERIMENT NO: 01 PROBLEM STATEMENT - BE …cebdiv.weebly.com/uploads/3/8/1/6/38163583/lab_manual_coa_(1).pdf · EXPERIMENT NO: 01 PROBLEM STATEMENT: ... Conversion of binary to Decimal-

1. Read After Write (RAW)

A read after write (RAW) data hazard refers to a situation where an instruction

refers to a result that has not yet been calculated or retrieved. This can occur

because even though an instruction is executed after a previous instruction, the

previous instruction has not been completely processed through the pipeline.

(i2 tries to read a source before i1 writes to it)

Example

i1. R2 <- R1 + R3

i2. R4 <- R2 + R3

The first instruction is calculating a value to be saved in register R2, and the

second is going to use this value to compute a result for register R4. However,

in a pipeline, when we fetch the operands for the 2nd operation, the results

from the first will not yet have been saved, and hence we have a data

dependency.We say that there is a data dependency with instruction i2, as it is

dependent on the completion of instruction i1.

2. Write After Read (WAR)

A write after read (WAR) data hazard represents a problem with concurrent

execution. (i2 tries to write a destination before it is read by i1).

Example

i1. R4 <- R1 + R5

i2. R5 <- R1 + R2

If we are in a situation that there is a chance that i2 may be completed

before i1 (i.e. with concurrent execution) we must ensure that we do not store

the result of register R5before i1 has had a chance to fetch the operands.

3. Write After Write (WAW)

A write after write (WAW) data hazard may occur in a concurrent

execution environment.

(i2 tries to write an operand before it is written by i1)

Example

i1. R2 <- R4 + R7

i2. R2 <- R1 + R3

We must delay the WB (Write Back) of i2 until the execution of i1.

4. Structural hazards

A structural hazard occurs when a part of the processor's hardware is needed

by two or more instructions at the same time. A canonical example is

a single memory unit that is accessed both in the fetch stage where an

instruction is retrieved from memory, and the memory stage where data is

written and/or read from memory.

.

Page 20: EXPERIMENT NO: 01 PROBLEM STATEMENT - BE …cebdiv.weebly.com/uploads/3/8/1/6/38163583/lab_manual_coa_(1).pdf · EXPERIMENT NO: 01 PROBLEM STATEMENT: ... Conversion of binary to Decimal-

5. Control hazards (branch hazards)

Branching hazards (also known as control hazards) occur with branches. On

many instruction pipeline micro architectures, the processor will not know the

outcome of the branch when it needs to insert a new instruction into the

pipeline.

CONCLUSION:

We studied and implemented data hazards successfully.

Page 21: EXPERIMENT NO: 01 PROBLEM STATEMENT - BE …cebdiv.weebly.com/uploads/3/8/1/6/38163583/lab_manual_coa_(1).pdf · EXPERIMENT NO: 01 PROBLEM STATEMENT: ... Conversion of binary to Decimal-

EXPERIMENT No: 10

PROBLEM STATEMENT:

Procedure for execute the Assembly program using TASM

THEORY:

1. Assembly language programs are converted into executable machine code by a

utility program referred to as an assembler, the conversion process being referred to as

assembly or assembling the program.

2. Assembly language (sometimes abbreviated as ASM, usually as the file

extension for a text file which is used as a code for a program written in Assembly

language, or in the names of assemblers, like FASM, MASM, NASM and TASM) is a

low­level programming language for computers, microprocessors, microcontrollers,

and other programmable devices in which each statement corresponds to a single

machine language instruction. An assembly language is specific to a certain computer

architecture, in contrast to most high­level programming languages, which generally

are portable to multiple systems.

What is TASM assembler?

The Turbo Assembler (TASM) is an x86 assembler that uses the Intel syntax for

MS­DOS and Microsoft Windows. Beginning with TASM 8.0 there are two versions

of the assembler ­ one for 16­ bit and 32­bit assembly sources, and another (ML64)

for 64­bit sources only.

Assembling and Running Assembly Language Programs

An assembly language program must be assembled and linked before it can be

executed. The assembler produces an object file (extension .OBJ). This file is taken

by the linker and an executable program (extension .EXE) is produced, assuming

there were no errors in the program. We use the MASM assembler and the LINK

linker. These are available on NAL under Programming:“TASM filesv 5.0”.

When saving the file with Notepad, you MUST save it with the “File Type” set to

“All Files”. You should now select the MS­DOS Prompt (Command PROMPT) from

the Start button menu (sometimes under Programs option)

Following are steps to execute a assembly program in tasm assembler.

1. Save .asm extention file by writing code in text editor.

2. Open dos prompt

3. Go the target file by prompt

4. Write tasm filename.asm and press enter

5. Write tlink filename.obj and press enter

Page 22: EXPERIMENT NO: 01 PROBLEM STATEMENT - BE …cebdiv.weebly.com/uploads/3/8/1/6/38163583/lab_manual_coa_(1).pdf · EXPERIMENT NO: 01 PROBLEM STATEMENT: ... Conversion of binary to Decimal-

6. Write debug filename.exe and press enter

7. Cursor will be displayed. Press –t for single step debugging mode otherwise –g for

direct compilation.

Tasm folder must contains

1. Tasm exe

2. Tlink exe

3. Td.exe

Following are steps to execute a mixed language program in TURBOC.

1. Write a program in turbo c editor and save it as .cpp file

2. Go the compile

3. Run the compile file

Note: GUI based Emulator 8085/ 8086 can also be used to write and execute assembly

programs. In the event of errors, you must edit your program and correct the errors.

Then you repeat the above steps to assemble and link your program, before running it.

Similarly, if you modify your program, you must assemble and link it before running

it again.

CONCLUSION:

We studied the working of TASM software. We also executed some basic programs

on TASM successfully.