assign

24
National Institute of Technology, Durgapur Computer Organization and Architecture (MCA 2003) Assignments File Submitted By: Vipin Saharia (10/MCA/11) Submitted To: Prof. P. Chaudhary

Upload: rahul-raushan

Post on 25-Nov-2014

183 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Assign

National Institute of Technology, Durgapur

Computer Organization and Architecture

(MCA 2003)

Assignments File

Submitted By:

Vipin Saharia

(10/MCA/11)

Submitted To:

Prof. P. Chaudhary

Page 2: Assign

Assignment 1. State differences between computer architecture and computer organization.

Computer architecture:

Computer architecture is the conceptual design and fundamental operational structure of a computer system. It's a blueprint and functional description of requirements and design implementations for the various parts of a computer, focusing largely on the way by which the central processing unit (CPU) performs internally and accesses addresses in memory.

It may also be defined as the science and art of selecting and interconnecting hardware components to create computers that meet functional, performance and cost goals.

Computer architecture comprises at least three main subcategories:

Instruction set architecture, is the abstract image of a computing system that is seen by a machine language (or assembly language) programmer, including the instruction set, word size, memory address modes, processor registers, and address and data formats.

Micro-architecture, also known as Computer organization is a lower level, more concrete and detailed, description of the system that involves how the constituent parts of the system are interconnected and how they interoperate in order to implement the ISA. The size of a computer's cache for instance, is an organizational issue that generally has nothing to do with the ISA.

System Design which includes all of the other hardware components within a computing system such as:

1. System interconnects such as computer buses and switches2. Memory controllers and hierarchies3. CPU off-load mechanisms such as direct memory access (DMA)4. Issues like multiprocessing.

Page 3: Assign

Computer organization:

Computer organization helps optimize performance-based products. For example, software engineers need to know the processing ability of processors. They may need to optimize software in order to gain the most performance at the least expense. This can require quite detailed analysis of the computer organization.

For example, in a multimedia decoder, the designers might need to arrange for most data to be processed in the fastest data path and the various components are assumed to be in place and task is to investigate the organizational structure to verify the computer parts operates.

Computer organization also helps plan the selection of a processor for a particular project. Multimedia projects may need very rapid data access, while supervisory software may need fast interrupts.

Sometimes certain tasks need additional components as well. For example, a computer capable of virtualization needs virtual memory hardware so that the memory of different simulated computers can be kept separated.

The computer organization and features also affect the power consumption and the cost of the processor.

Page 4: Assign

Assignment 2. How to overcome the drawbacks of Direct Mapping. Discuss other mapping techniques also.

The drawbacks of direct mapping can be overcome by using other mapping technique i.e. Set Associative Mapping

First we discuss Associative Mapping as under:

Associative mapping stores both content (data) and address of the memory word.

The address is stored in argument register and memory searches for matching address, if found we call it a HIT else MISS.

If MISS occurs, then it accesses the content from main memory and one copy of address-data pair is transferred to associative cache memory.

If cache is found to be full, then through replacement policy i.e. FIFO, a removal occurs and stores there.

It is an expensive mapping technique as logic is associated with each cell for matching address-data pair.

Set Associative mapping

As an advantage over Direct mapping technique, here can reside two or more words of memory under the same index address. Each data word is stored together with its tag and the number of tag-word items in one word of the cache is said to form a set.

A set associative cache of set size ‘k’ will accommodate k-words of main memory in each word of cache.

Here if a MISS occurs, then if cache set is full then it replaces one of tag data items with new value else put a copy of memory word in the vacant place.

Replacement happens on basis of FIFO, LRU or random replacement.

Assignment 3. What is Content Addressable Memory (CAM)?

Page 5: Assign

Content Addressable Memory (CAM) :

A memory unit accessed by content is called associative memory or Content Addressable memory. It is used to reduce the time required to find an item stored in memory by identified for access by the content of the data itself rather than by an address.

This type of memory is accessed simultaneously and in parallel on the basis of the data content rather than by specific address or location. When a word is written in CAM, no address is given. The memory is capable of finding an empty unused space or location to store a word.

While searching for the data, the memory locates all words which match the specified content and marks them for reading.

In a system that utilizes a dynamic memory map, CAM can be used to store memory addresses for quicker access.

Actually, Content-addressable memory (CAM) is a special type of computer memory used in certain very high speed searching applications.

Because a CAM is designed to search its entire memory in a single operation, it is much faster than RAM in virtually all search applications. There are cost disadvantages to CAM however. Unlike a RAM chip, which has simple storage cells, each individual memory bit in a fully parallel CAM must have its own associated comparison circuit to detect a match between the stored bit and the input bit.

Additionally, match outputs from each cell in the data word must be combined to yield a complete data word match signal. The additional circuitry increases the physical size of the CAM chip which increases manufacturing cost. The extra circuitry also increases power dissipation since every comparison circuit is active on every clock cycle. Consequently, CAM is only used in specialized applications where searching speed cannot be accomplished using a less costly method.

Assignment 4. How page size influences the performance of Virtual Memory System. Also discuss problems related to virtual memory.

Page 6: Assign

Virtual memory is simulated RAM. When you have used up your entire RAM, your computer will shift data to an empty space on the hard drive. The computer swaps data to the hard disk and back to your RAM as needed. When you increase your virtual memory you are increasing the empty space that is reserved for your RAM overflow.

Paging is one of the memory-management schemes by which a computer can store and retrieve data from secondary storage for use in main memory. In the paging memory-management scheme, the operating system retrieves data from secondary storage in same-size blocks called pages. The main advantage of paging is that it allows the physical address space of a process to be noncontiguous.

Paging is an important part of virtual memory implementation in most contemporary general-purpose operating systems, allowing them to use disk storage for data that does not fit into physical random-access memory.

When a program tries to access pages that are not currently mapped to physical memory (RAM). This situation is known as a page fault.

Consider a computer with an address space of 8K and a memory space of 4K. If we split each into groups of 1K words we obtain 8 pages and 4 blocks. So at a given time, upto 4 pages can reside in main memory in any of the four blocks and other four will not be in use.

Secondly, consider an address space of 1024K words and memory space of 32K words. If each page contains 1K words then the number of pages is 1024 and the number of blocks 32. The capacity of page table must be 1024 words and only 32 locations may have a presence bit equal to 1. At a given time, at least 992 locations will be empty and not in use.

Problems related to Virtual Memory:

Page 7: Assign

Thrashing:

A program that works with huge data structures will sometimes require a working set that is too large to be efficiently managed by the page system resulting in constant page faults that drastically slow down the system. This condition is referred to as thrashing: pages are swapped out and then accessed causing frequent faults.In virtual memory systems, thrashing may be caused by programs or workloads that present insufficient locality of reference: if the working set of a program or a workload cannot be effectively held within physical memory, then constant data swapping, i.e., thrashing, may occur. Many older low-end computers have insufficient RAM for modern usage patterns and increasing the amount of memory can often cause the computer to run noticeably faster. This speed increase is due to the reduced amount of swapping necessary.

To resolve thrashing due to excessive paging, a user can do any of the following.

1. Increase the amount of RAM in the computer.2. Decrease the number of programs being run on the computer.3. Replace programs that are memory-heavy with equivalents that use less

memory.

Locality of reference:

Locality of reference, also known as the principle of locality, is the phenomenon of the same value or related storage locations being frequently accessed. There are two basic types of reference locality. Temporal locality refers to the reuse of specific data and resources within relatively small time durations. Spatial locality refers to the use of data elements within relatively close storage locations. Sequential locality, a special case of spatial locality, occurs when data elements are arranged and accessed linearly, e.g., traversing the elements in a one-dimensional array.

Assignment 5. Why pointers are used in spite they use two memory cycles.

Page 8: Assign

In Multi-tasking environment, there are multiple programs running in memory and there is a possibility of conflict if two programs simultaneously access the machine resources. To prevent this, Windows does not permit any application direct access to any machine resource. To channelize the access without resulting into conflict between applications several new mechanisms were created in the Microprocessor & OS. This had a direct bearing on the way the application programs are created using pointers.

Since users have become more demanding, modern day applications have to contend with these demands and provide several features in them. To add to this, under Windows several such applications run in memory simultaneously. The maximum allowable memory—1 MB—that was used in 16-bit environment was just too small for this. Hence Windows had to evolve a new memory management model. Since Windows runs on 32-bit microprocessors each CPU register is 32-bit long. Whenever we store a value at a memory location the address of this memory location has to be stored in the CPU register at some point in time. Thus a 32-bit address can be stored in these registers. This means that we can store 232 unique addresses in the registers at different times. As a result, we can access 4 GB of memory locations using 32-bit registers. As pointers store addresses, every pointer under 32-bit environment also became a 4-byte entity.

Suppose we have a pointer pointing to some data present in a page. If this page gets paged out and is later paged in to a different physical location then the pointer would obviously have a wrong address. Hence under Windows the pointer never holds the physical address of any memory location. It always holds a virtual address of that location.

Advantages of Pointers:

Page 9: Assign

Optimization : Pointers provide a performance advantage by allowing you to access computer memory directly. This technique is commonly used to optimize algorithms requiring frequent or repetitive access to large amounts of data.

Memory Management : Managing memory usage in an application using pointers offers flexibility. Allocating and deallocating memory as needed during run time allows you to create large objects, such as arrays, quickly and immediately free the memory when it is no longer required. However, it is also easy to create memory leaks by reassigning a pointer without freeing the memory it was pointing to first.

Function Parameters : Functions can return only one value, but they can take multiple parameters. By passing in pointers to variables as parameters, a function can be used to set the values of those variables, and the new values will persist after the function returns. Being able to set the value of several variables at once with a single function call is clean and efficient. However, it can be a little confusing to read because you can't tell if the variables passed in will be modified or not simply by looking at the function call.

Function Pointers : Pointers are not just for objects in memory; they can also be used for functions, thus allowing a function to be passed as a parameter to another function. A function pointer can be assigned the address of one of a choice of functions so that the pointer acts as a kind of alias. Object-oriented programming languages have eliminated the need for function pointers with inheritance and polymorphism.

These advantages are so essential and powerful tool for computer memory management and programming thus hides its disadvantage of using two memory cycles.

Assignment 6. Write some assembly programs.

Page 10: Assign

These programs inherently use Accumulator based and General Purpose Register Set machine cycles.

Program 1: To add two numbers

MVI D, 8BHMVI C, 6FHMOV A, CADD DHLT

Program 2: To place content of memory location FC30H (11H) in register B and that of FC31H (12H) in register C

LXI H, FC30HMOV B, MINX HMOV C, MHLT

DATAFC30 – 11H (Contained in B)FC31 – 12H (Contained in C)

Program 3: Place 05 in Accumulator. Increment it by one and store the result in memory location FC50H.

MVI A, 05HINR, ASTA FC50HHLT

DATAFC50H – 06H

Program 4: Program for 8 bit subtraction.

LXI H, 2501H

Page 11: Assign

MOV A, MINX HSUB MINX HMOV M, AHLT

DATA2501H – F8H2502H – 9BH

RESULT2503H – 5DH

Program 5: Program for 8 bit decimal subtraction.

LXI H, 2502HMVI A, 99SUB MINR ADCX HADD MDDASTA 2503HHLT

DATA2501H – 96D2502H – 38D

RESULT2503H – 58D

Program 6: Program for 16 bit Addition.

Page 12: Assign

LXI D, 2301HLXI B, 7314HMOV A, EADD CMOV L, AMOV A, DADC BMOV H, ASHLD 5051HMVI A 00HACI 00HSTA 4080HHLT

DATA2301H7314H

RESULT5051H – 9615H4080H – CARRY (If Any)

How Page Size influence in Virtual memory System?

Page size has a greater impact on space utilization and effective memory data-transfer rate.

Page 13: Assign

Amongst all implementation of virtual memory divides the virtual address space of an application program into pages. With each page at least 4KB. Page tables are used to translate the virtual address seen by the application program into physical address.

Page size is usually determined by processor architecture. There are several advantages of having a larger page size in virtual memory system in comparison of having a smaller page since. These are

1. A System with smaller page size uses more pages requiring a page table that occupies more space.

2. Since every access of memory must be mapped from virtual to physical address, reading the page table every time can be quite costly.

3. When transferring from disk much of the delay is caused by seek time. Because of this large sequential transfers are more efficient than several small transfers. Thus transferring the same amount of data from disk to memory often requires less time with larger pages than with smaller pages.

Besides this advantage there is also a disadvantage of having larger page size.

Rarely do Processes require the use of exact number of pages. As a result the last page will likely only be partially full wasting some amount of memory. Larger page size clearly increases the potential for wasted memory as more potentially unused portion of memory is loaded into main memory. Smaller page size ensures a closer match to the actual amount of memory required in an allocation.

Q) The logical address space in a computer system consists of 128 segments. Each segment can have up to 32 pages of 4K words each. Physical memory consists of 4K blocks of 4K words in each. Formulate logical and physical address formats.

Page 14: Assign

Sol: - For logical address

There are 128 segments. So 7 bits must be used for segment number.

There are 32 pages. So 5 bits must be used to represent the page number.

There are 4K word in each page i.e. 2^12 words. So 12 bits must be used to represent the word number.

Therefore logical address consists of total of 7+5+12 =24 bits.

For physical address: There are 4K blocks i.e. 2^12 blocks. Therefore 12 bits must be used to represent the block number.

Also there are 4K words in each block. Therefore 12 bits must also be used for word number of each block.

Hence Physical address also consists of 12+12=24 bits.

Q) A virtual memory has page size of 1K words. There are eight pages and four blocks. The associative memory page table contains the following entries.

PAGE BLOCK0 31 1

4 2

6 0

Make a list of all virtual address that will cause a page fault if used by the CPU.

Sol:-

Page 15: Assign

Since there are 8 pages. These 8 pages can be represented by 3 bits(0 to 7). Also there are 1K words in each page that can be represented by 10 bits. There are 18 bits in the logical address.

A page fault occurs when following pages are asked by the CPU.

Page 2. The address range for page 2 will be

010 0000000000 to 010 1111111111.

Page 3. The address range for page 3 will be

011 0000000000 to 011 1111111111.

Page 5. The address range for page 5 will be

101 0000000000 to 101 1111111111.

Page 7. The address range for page 7 will be

111 0000000000 to 111 1111111111.

Q) An address space is specified by 24 bits and corresponding memory space by 16 bit.

a. How many words are there in address space?

b. How many words are there in memory space?

c. If a page consists of 2k words, How many pages and blocks are there in the system?

Sol:-

Page 16: Assign

No. of words in address space is = 2^24=16M.

a. No. of words in memory space is = 2^16=64K.b. No. of pages in system =No. of words in address space/Length of each

word=16M/2K=8K pages.No. of blocks in system = No. of words in address space/Length of each block=64K/2k=32 blocks.

Q) A virtual memory system has an address space of 8K words, a memory space of 4K words and page and block sizes of 1K words. The following page reference changes occur during a given time interval.(only page changes are listed, if the same page is referenced again it is not listed twice).

4 2 0 1 2 6 1 4 0 1 0 2 5 7

Determine the four pages that are resident in main memory after each page reference change if the replacement algorithm used is a. FIFO

b.LRU

Sol:-

FIFO

Page referenced pages in memory

4 4

2 4 2

0 4 2 0

1 4 2 0 1

2 4 2 0 1

Page 17: Assign

6 6 2 0 1

1 6 2 0 1

4 6 4 0 1

0 6 4 0 1

1 6 4 0 1

0 6 4 0 1

2 6 4 2 1

3 6 4 2 3

5 5 4 2 3

7 5 7 2 3

LRU

Page referenced Pages in memory

4 4

2 4 2

0 4 2 0

1 4 2 0 1

2 4 2 0 1

6 6 2 0 1

1 6 2 0 1

4 6 2 4 1

0 6 0 4 1

Page 18: Assign

1 6 0 4 1

0 6 0 4 1

2 2 0 4 1

3 2 0 3 1

5 2 0 3 5

7 2 7 3 5

Q ) Give the binary number of the logical address formulated in problem 7 for segment 36 and word number 2000 in page 15.

Sol:-

The segment no. will be represent by 7 bits which must equal 36. So these 7 bits are 0100100.

The Page no. is represented by 5 bits which must equal to 15.

So these 5 bits are 01111.

The word no. Is represented by 12 bits which must equal to 2000.So these 12 bits are 011111010000.

Hence the logical address is

0100100 01111 011111010000.