Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
2011-12-Monsoon Semester
Announcements
Section E11 will have a lab on Fridays. Section E15 will have a lab on Wednesdays. Monday lab and grading policy is on moodle. Tuesday/Wednesday labs will be on moodle today.
Lec-04
Recap
Algorithm Converting binary to decimal
Flow chart is on moodle
Lec-04
Recap: Memory
Bit: Having a value of 0 or 1 Byte: Having 8 bits Kilobyte (KB): 1024 bytes Megabyte (MB): 1024 KB Gigabyte (GB): 1024 MB Is generally byte addressable
32 bit addresses would mean a maximum memory of 4 GB.
Any byte can be read at any time random access Programs and Data are stored in memory.
Lec-04 Dheeraj Sanghi, CSE Dept., IIT Kanpur ESc101, 2011-12-Monsoon 4
Recap: ALU
Can execute arithmetic and logical operations
Add, Subtract, Multiply, Divide (for integers) Right shift, Left shift Comparison of two bytes or two numbers What operations needs to be done next on what inputs is controlled by the program
Lec-04
Lec-04
Lec-04
Program
The Control Unit can only understand a sequence of binary bits. So the program has to be in binary format, also known as machine language. Program is a sequence of instructions in machine language. The execution happens as follows: Control unit fetches an instruction If operands are in memory locations, fetch them as well. Ask ALU to execute the instruction on the operands The result needs to be stored in the memory location. Next instruction is fetched, unless the previous instruction asked the Control Unit to fetch a difference instruction.
Dheeraj Sanghi, CSE Dept., IIT Kanpur ESc101, 2011-12-Monsoon 8
Lec-04
A Small Program
0000010010011001 read memory location 001 0000010010011010 read memory location 010 0000011011001000 add two numbers read 0000010011010001 store the result in memory location 001
Lec-04
Assembly Language
Extremely difficult to write program in machine language. Even more difficult to understand machine language. Hence the designers of CPU also design a higher level language called, Assembly Language. This has mnemonics for both operations and the operands.
Hence somewhat easier to follow
Lec-04
10
Example Program
MOV MOV ADD MOV NUM1, R1 NUM2, R2 R1, R2 R1, NUM1
Move contents of memory location NUM1 to location R1 Move contents of memory location NUM2 to location R2 Add contents of R1 and R2 and store the result in R1 Move the contents of location R1 to Memory location NUM1
Dheeraj Sanghi, CSE Dept., IIT Kanpur ESc101, 2011-12-Monsoon 11
Lec-04
Assembler
Assembler translates the assembly language program to a machine language program.
Lec-04
12
Lec-04
13
Compiler
Compiler is a program that translates a higher level language to machine language There are many C Compilers available.
We will be using gcc.
Lec-04
14
Input/Output
To solve problems, we need to provide input to the program, and the program needs to give output. The program should be able to read from keyboard, understand mouse clicks, etc. The program should be able to write on the monitor or display unit. The programs should be stored on permanent storage, e.g., disks. All this is done with the help of Operating System.
Lec-04 Dheeraj Sanghi, CSE Dept., IIT Kanpur ESc101, 2011-12-Monsoon 15
Operating System
Manages all resources of the computer.
Allocates space on disk for files. Allocates memory for your programs Allows multiple programs to be running in parallel. Reads what you type on keyboard. Maintains access control
Files of one user cannot be read by another user, unless allowed.
Lec-04
16
Lec-04
17
Points to Note
#include Comments main () int float printf %f, \n scanf %d, %f, & Variable names Arithmetic expressions Assignment Types Integer versus Floating point operations
Lec-04
18
Any Questions?
Lec-04
19
10