Unit 1 - Computer Architecture (PDF)

Summary

This document covers the fundamentals of computer architecture, including the von Neumann architecture. It explains the basic components and concepts. The structure, the fetch-decode-execute cycle, and the role of registers and buses are all explored. The notes also contain discussion about C programming, which is a middle-level language.

Full Transcript

Unit -1 14 January 2025 14:06 Computer Topics Electronic device Understanding a basic Von Neumann Machine Architecture...

Unit -1 14 January 2025 14:06 Computer Topics Electronic device Understanding a basic Von Neumann Machine Architecture Performs operation with speed and accuracy Interpreter vs Compiler Processing Unit Classification of computers ALU Control Memory Why C is a middle-level language? It binds the gap between machine level language and high-level language. It can be used for both, system programming (like as operating system) As well as application programming (like as spreadsheet). C language merges the best element of high-level language with the rule and flexibility of assembly language. C allows the manipulation of bits and addresses and bytes. # turns text into Hyper text (it shifts pages basically) Understanding a basic Von Neumann Machine Architecture 1945 -Von Neumann Architecture founded (also known as princeton architecture) by - John Von Neumann Consists - Control Unit , Arthimetic and Logical Unit , Registers , Input , Output Based on Stored-Program Computer Concept Instruction and Program Data in same memory Most Used Model Computer Based on :- Uses single Processor Uses 1 memory for both instruction and data Executes program using - Fetch-decode-execute cycle Components of Von-Neumann Model: Central Processing Unit Buses Memory Unit 1. CPU - CPU performs variety of functions dictated by instructions incorporated Components of cpu Arrow on Input points opposite than shown a. ALU - performs micro operations (basically arthimetic and logical operations b. CU - controls Operations of components like ALU , Memory and Input/Output Device Contains a program counter that contains the address of the instruction to be fetched and an instruction register into which instruction are fetched from the memory of execution c. Variety of Registers - Registers refer to high-speed storage areas in the CPU. The data processed by the CPU are fetched from the registers. Diff registers used fo data data processing are given Registers Description MAR (Memory Address Register) This register holds the memory location of the data that needs to be accessed. MDR (Memory Data Register) This register holds the data that is being transferred to or from memory. AC (Accumulator) This register holds the intermediate arithmetic and logic results. PC (Program Counter) This register contains the address of the next instruction to be executed. CIR (Current Instruction Register) This register contains the current instruction during processing. 2. Buses - Buses are the means by which information is shared between the registers in a multiple-register configuration system. Consists set of common lines , one for each bit of register , binary info is transferred one at a time. Control signals determine selection of register by bus Von-Neumann Architecture comprised of three major bus systems for data transfer. Bus Description Address Bus Address Bus carries the address of data (but not the data) between the processor and the memory. Data Bus Data Bus carries data between the processor, the memory unit and the input/output devices. Control Bus Control Bus carries signals/commands from the CPU. 3. Memory Unit - A memory unit is a collection of storage cells together with associated circuits needed to transfer information in and out of the storage. The memory stores binary information in groups of bits called words. The internal structure of a memory unit is specified by the number of words it contains and the number of bits in each word. Two major types of memories are used in computer systems: 1. RAM (Random Access Memory) 2. ROM (Read-Only Memory)++ Instruction Cycle An instruction cycle (sometimes called fetch-and-execute cycle, fetch-decode-execute cycle, or FDX) is the basic operation cycle of a computer. It is the process by which a computer retrieves a program instruction from its memory, determines what actions the instruction requires, and carries out those actions. This cycle is repeated continuously by the central processing unit (CPU), from boot up to when the computer is shut down. The circuits used in the CPU during the cycle are: Program Counter (PC) - an incrementing counter that keeps track of the memory address of which instruction is to be executed next. Memory Address Register (MAR) - holds the address in memory of the next instruction to be executed. New Section 1 Page 1 Memory Address Register (MAR) - holds the address in memory of the next instruction to be executed. Memory Data Register (MDR) - a two-way register that holds data fetched from memory (and ready for the CPU to process) or data waiting to be stored in memory. Instruction register (IR) - a temporary holding ground for the instruction that has just been fetched from memory. Control Unit (CU) - decodes the program instruction in the CIR, selecting machine resources such as a data source register and a particular arithmetic operation, and coordinates activation of those resources. Arithmetic logic unit (ALU) - performs mathematical and logical operations. Each computer's CPU can have different cycles based on different instruction sets, but will be similar to the following cycle: 1. Fetch the instruction The next instruction is fetched from the memory address that is currently stored in the Program Counter (PC), and stored in the Instruction register (IR). At the end of the fetch operation, the PC points to the next instruction that will be read at the next cycle. 2. Decode the instruction The decoder interprets the instruction. During this cycle the instruction inside the IR (instruction register) gets decoded. 3. Read the effective address In case of a memory instruction (direct or indirect) the execution phase will be in the next clock pulse. If the instruction has an indirect address, the effective address is read from main memory, and any required data is fetched from main memory to be processed and then placed into data registers. 4. Execute the instruction The CU passes the decoded information as a sequence of control signals to the relevant function units of the CPU to perform the actions required by the instruction such as reading values from registers, passing them to the ALU to perform mathematical or logic functions on them, and writing the result back to a register. If the ALU is involved, it sends a condition signal back to the CU. The result generated by the operation is stored in the main memory, or sent to an output device. Based on the condition of any feedback from the ALU, Program Counter may be updated to a different address from which the next instruction will be fetched. The cycle is then repeated. Fetch-Decode-Execute cycle(Instruction cycle) 1. The processor checks the program counter to see which instruction to run next. 2. The program counter gives an address value in the memory of where the next instruction is. 3. The processor fetches the instruction value from this memory location. 4. Once the instruction has been fetched, it needs to be decoded and then executed. Example- this could involve taking one value, putting into ALU then taking a different value from a register and adding the 2 together. 5. Once this is complete, the processor goes back to the program counter to find the next instruction. 6. This cycle is repeated till the program ends. Instruction Cycle :- 1. Program checks program counter to see which instruction to run next 2. Program counter gives an address value in the memory of where the next instruction is 3. The processor fetches the instruction value from this memory 4. Once the instruction has been fetched, it needs to be decoded and executed. For example , this could involve taking one value putting it into ALU , then taking a different value from a register and adding two together 5. Once this is complete, the processor goes back to the program counter to find the next instruction 6. This cycle is repeated until the program ends Memory Layout in C When we create a C program and run the program, its executable file is stored in the RAM of the computer in an organized manner. As we can observe in the above figure, the C program consists of the following sections in the program: Text segment Initialized data segment Uninitialized data segment Stack Heap 1. Text segment The text segment is also known as the code segment. When we compile any program, it creates an executable file like a.out,.exe, etc., that gets stored in the text or code section of the RAM memory. If we store the instructions in the hard disk, then the speed for accessing the instructions from the hard disk becomes slower as hard disk works on the serial communication so taking the data from the hard disk will be slower, whereas the RAM is directly connected to the data and address bus so accessing the data from the RAM is faster. 2. Data section The data which we use in our program will be stored in the data section. Since the variables declared inside the main() function are stored in the stack, but the variables declared outside the main() method will be stored in the data section. The variables declared in the data section could be stored in the form of initialized, uninitialized, and it could be local or global. Therefore, the data section is divided into four categories, i.e., initialized, uninitialized, global, or local. 1. #include 2. int var1; In the code, var1 and var2 3. int var2 = 10; variables are declared outside the 4. void function1() main() function where var1 is the 5. { uninitialized variable, whereas 6. printf("I am function1"); the var2 is an initialized variable. 7. } These variables can be accessed 8. int main() anywhere in the program 9. { because these variables are not a 10. function1(); part of the main() in the stack. 11. return 0; 12. } New Section 1 Page 2 The data section consists of two segments: Uninitialized data segment Initialized data segment Uninitialized data segment Advertisement The uninitialized data segment is also known as a.bss segment that stores all the uninitialized global, local and external variables. If the global, static and external variables are not initialized, they are assigned with zero value by default. The.bss segment stands for Block Started by symbol. The bss segment contains the object file where all the statically allocated variables are stored. Initialized data segment An initialized data segment is also known as the data segment. A data segment is a virtual address space of a program that contains all the global and static variables which are explicitly initialized by the programmer. The values of variables in a data segment are not read-one, i.e., they can be modified at run time. This data segment can be further classified into categories: Initialized read-only area: It is an area where the values of variables cannot be modified. Initialized read-write area: It is an area where the values of variables can also be altered. For example: the global variables like char str[] = "javatpoint" and int a=45; will be stored in the initialized read-write area. If we create the global variable like const char* string = "javatpoint"; the literal "javatpoint" would be stored in the initialized read area, whereas the char pointer variable would be stored in the initialized write area. 3. Stack (LIFO) When we define a function and call that function then we use the stack frame. The variables which are declared inside the function are stored in the stack. The function arguments are also stored in the function as the arguments are also a part of the function. Such a type of memory allocation is known as static memory allocation because all the variables are defined in the function, and the size of the variables is also defined at the compile time. The stack section plays a very important role in the memory because whenever the function is called, a new stack frame is created. Stack is also used for recursive functions. When the function is called itself again and again inside the same function which causes the stack overflow condition and it leads to the segmentation fault error in the program. 4. Heap Heap memory is used for the dynamic memory allocation. This is unused Memory of the program and can be used to allocate the memory dynamically when program runs Heap memory begins from the end of the uninitialized data segment and grows upwards to the higher addresses. The malloc() and calloc() functions are used to allocate the memory in the heap. The heap memory can be used by all the shared libraries and dynamically loaded modules. The free() function is used to deallocate the memory from the heap. You can allocate memory at the run time within the heap for the variable of a given type using a special operator in C++ which returns the address of the space allocated. This operator is called new operator (in C++). If you are not in need of dynamically allocated memory anymore , you can use the delete operator (in c++) , which de-allocates the memory. New-Delete Operator : There is the following generic syntax to use the new opertaor to allocate memory dynamically for any data type. New data-type; Here, the pointer variable is the pointer of type data-type. Data type could be any built-in data type including array or any user- defined data type including structure and class. Double*pvalue=NULL Pvalue= new double; The memory may not have been allocated successfully if the free store had been used up. So it is good practice to check if the new operator is returning NULL pointer Double*pvalue=NULL; If(!(pvalue=new double)){ Cout

Use Quizgecko on...
Browser
Browser