Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer organization & Assembly Language Programming

Similar presentations


Presentation on theme: "Computer organization & Assembly Language Programming"— Presentation transcript:

1 Computer organization & Assembly Language Programming
Rabie A. Ramadan

2 Class Style Do not think of the exam Feel free to stop me at any time
Just think of the class materials and how much you learn from it Feel free to stop me at any time I do not care how much I teach in class as long as you understand what I am saying There will be an interactive sessions in class you solve some of the problems with my help Chapter 2 — Instructions: Language of the Computer — 2

3 When the time is up , just let me know….
Chapter 2 — Instructions: Language of the Computer — 3

4 Textbook S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer, 2005.

5 Grading

6 Course Objectives To introduce basic concepts of computer organization. To illustrate the computer organization concepts by Assembly Language programming. To teach Assembly language of most recent processor such as Intel Pentium processor.

7 Outline Why program in assembly language?
Time-efficiency Space-efficiency Accessibility to hardware Typical applications Why learn assembly language? Performance: C versus assembly language Multiplication example A user’s view of computer systems What is assembly language? Relationship to machine language Advantages of high-level languages Faster program development Easier maintenance Portability

8 What is a Machine ? Process Directives Raw Material Final Product Machine In General: Device that processes a series of raw materials into the desired product following a well-defined process

9 Types of Machines Device Raw Material Products Computer Data
Food Processing Factory Natural Fruits, Vegetables, Meats, Dairy and Spices Manufactured (Packaged) Food Products Airport Planes, Travelers, Goods Administrative Office Application Files Decisions Computer Data

10 Computer Machine Model
Machine = Computer Process = Program Directives Program = Suite of Instructions Instruction = Simple Operation

11 Basic Computer Organization (1)
Central Processing Unit (CPU) Need a Unit to Execute Instructions Need a Unit to Contain Programs Need a Unit to Contain Input Data Need a Unit to Contain Intermediate Stage Data Need a Unit to Input Data Need a Unit to Output Data Memory IO

12 Basic Computer Organization (3)
Memory Cpu I/O Buses Buses: Groups of Electrical Signals or Wires That Establish The Communication Between The Different Computer System Components

13 Memory Similar to a set of Storage Bins Data 1 Data 2 1
1 2 Data 1 Data 2 Each Bin is Called: A Memory Location Each Location has a Content And an Index The Content is The Data and the Index is The Address Data is Written in Memory And Read from The MEmory The CPU Reads Data From Memory And Writes Data Into Memory

14 Basic Computer Organization (3)
Memory Cpu Address Bus Data Bus I/O Control Bus Address Bus: Specifies the Address of the Data being Accessed Data Bus: Carries the Data to be Transferred Control Bus: Specifies the Nature of the Transfer: (Memory Read/Write or I/O)

15 Memory 2n Storage Device
Stores Programs and Data coded in binary format. Technically “similar” to a two-dimensional array of “switches” A “switch” called a bit (abbr. for binary digit) n Address lines means 2n words of m bits each 2n n Address m 1 Data

16 Memory 2 Operations: Read: Copy Data stored in word of Address (on Address lines) to Data Bus Write: Store Data on Data Bus into word of Address (on Address lines) n Memory Addr Read Write m Data COE 205

17 Concept of Address It is an index in the memory
It represents a “geographic” location of a word in the memory Number of Address lines and Word size determine Memory Capacity (Size) Most of the time: Memory size = 2n words = 2n * m bits COE 205

18 RAM RAM: Random Access Memory
Although the name is about the way memory is accessed. Historically, volatile memory has been called RAM. Volatile (do not retain information on power off) Used mainly as Central Memory for CPUs Two types of RAM Static: Continuous Retention of Information Dynamic (DRAM): needs refresh cycle to maintain information COE 205

19 ROM Non Volatile Used to store data (programs) that do not change often (fixed) Many types Mask ROM: Values set at fabrication stage. Values cannot be changed Fuse PROM: Values set at burning phase. Values cannot be changed EPROM: Can be erased (UV) EEPROM: Electrically erased Flash EEPROM: Easily reprogrammable. New: NVRAM (Non Volatile RAM): Fast access time.

20 Disk Drives Hard Drive: suite of magnetic disks. Mechanically read and write data by moving a set of magnetic head over the disks CD-ROM, DVD-ROM: Suite of optical disks read by measuring the time of laser reflexion between “1” and “0” N S “1” “0”

21 Program Execution A Program is a suite of instructions
Program Execution is Sequential Program is stored in Memory Program is executed by CPU Instruction 1 Instruction 2 Instruction 3 Instruction n COE 205

22 CPU Executes Programs Stored in Memory
Executes Instructions ONE by ONE Only “knows” instructions: Instruction Set DO NOT know any notion of Program as a single entity. Everything is a suite of instructions COE 205

23 CPU Structure (1) Is Mainly a Data Processing Unit Controlled
by a Control Unit. Data Processing Unit: Datapath Registers (Scratch pad working space or temporary data storage) ALU: Arithmetic and Logic Unit Internal Buses Control Unit: Generates Commands to “drive” Datapath operations COE 205

24 CPU Structure (2) Control Unit Datapath ALU Register Register
Data Path is Similar to a Pipe Structure where valves are controlled by the Control Unit Control Unit Datapath ALU Register Register COE 205

25 Master Clock Instructions Executed step by step
Need a “Rhythm” Generator to move forward in the steps: Time Clock Cycle Clock Frequency = 1/Clock Cycle Period : MHz Every CPU needs a Clock to control the transition from one execution step to the next COE 205

26 Instruction Set Instruction Set is the Catalog of the CPU
Defines what are ALL the possible operations that the CPU can execute Only Instructions are recognized by CPU. CPU does NOT “understand” High Level Language (text). CPU understands instructions coded in numbers called machine code. COE 205

27 Instruction parameters
Each Instruction specifies an action or a suite of actions: Action(s) “identifier” or Operation Code or Opcode Action arguments or operands Methods specifying how to access the operands, called addressing modes Instruction specified as: <Opcode> <Operand 1, addr_mode1> <Operand 2, addr_mode2> …. COE 205

28 Number of Operands Many types of Instruction Sets
Instruction Set with One Operand: Implicit Register Called Accumulator. Everything goes to and from the accumulator: Instruction Set with Two Operands: Many registers can be used as accumulators Instruction Set with Three Operands: Mainly Register Based. COE 205

29 Fetch – Decode - Execute
Address of next Instruction Cpu Memory Fetch Fetch Instruction Read Command Opcode Reg Immediate Decode Instruction Decoder Decode Execute Execute COE 205

30 Address of Programs Where the Address of next instruction is Stored ?
Need for an Instruction Pointer Called: “Program Counter” PC Critical Component of CPU Conveniently useful for changing program sequence (Branch instructions)

31 Instruction Register Where is the current instruction going to be stored during its execution ? Need for a Register Called: “Instruction Register” Data Bus Critical Component of CPU Internal Register. Cannot be used (accessed) by instructions Holds the current instruction until its execution is completed Tightly Coupled to the decoding portion of the control unit Connected to the datapath (to transfer operand fields) Opcode Op1 Op2 Instruction Decoder

32 Program in Memory Binary code (machine code). Memory (8-bit) B8 00
MOV AX,5 05 03 ADD AX,BX C3 EB JMP Next E7

33 High Level Languages Machine independent.
Cannot be run directly on the target machine Need to be translated to machine language Compiler: program that translates a HLL program to a machine language program of a specific platform The Machine language program produced by the compiler is the executable program. Translating HLL programs to machine language programs is not a one-to-one mapping A HLL statement translated to one or more machine language instructions Usually, machine language programs produced by compilers are not efficient Deals with Data types (integer, real, complex, user-defined) vs. machine language: no data types only binary words. COE 205

34 Assembly Language Text version of machine language
Human friendly representation of machine language Based on mnemonics (easy to memorize abbreviations of actions) instead of dealing with opcode numbers. Complicated format simplified with some conventions Text file translated into machine code by the Assembler COE 205

35 Assembler Program that assemble the programs written in assembly language into machine language Because there is a ONE to ONE mapping between instructions written in assembly language and machine language instructions, the process is called: assembly rather than translation. Disassembly (reverse process) is also easy because of the ONE to ONE relation between the assembly language instructions and the machine language instructions MOV DX, 1 MOV AX, BX MOV AX, CX MOV AX, DX ADD AX, 1 ADD AX, 2 ADD AX, BX ADD AX, CX ADD AX, i SUB AX, 1 SUB AX, BX ADD AX, 1234h BA 0001 8B C3 8B C1 8B C2 83 C0 01 83 C0 02 03 C3 03 C1 83 E8 01 2B C3 COE 205

36 Linker Program used to link together separately assembled/compiled programs into a single executable code Allows the programmers to develop different parts of a large program separately, test them separately and ‘freeze’ them for future use. Allows the programmer to develop store portions of programs that have been intensively tested and used into a “program library” for anyone to re-use them. Produces modular programs and greatly enables the management of large programming projects

37 Debugger/Monitor These are tools that allow the assembly programmers to: Display and alter the contents of memory and registers while running their code, Perform disassembly of their machine code (show the assembly language equivalent), Permit them to run their programs, stop (or halt) them, run them step-by-step or insert break points. Break points: Positions in the program that if are encountered during run time, the program will be halted so the programmer can examine the memory and registers contents and determine what went wrong.

38 A User’s View of Computer Systems

39 What Is Assembly Language?
Some example assembly language instructions: inc result mov class_size,45 and mask1,128 add marks,10 Some points to note: Assembly language instructions are cryptic Mnemonics are used for operations inc for increment, mov for move (i.e., copy) Assembly language instructions are low level Cannot write instructions such as mov marks, value MIPS Examples andi $t2,$t1,15 addu $t3,$t1,$t2 move $t2,$t1

40 What Is Assembly Language? (Cont’d)
Some simple high-level language instructions can be expressed by a single assembly instruction Assembly Language C inc result result++; mov class_size,45 class_size = 45; and mask1,128 mask1 &= 128; add marks,10 marks += 10;

41 What Is Assembly Language? (Cont’d)
Most high-level language instructions need more than one assembly instruction C Assembly Language size = value; mov AX,value mov size,AX sum += x + y + z; mov AX,sum add AX,x add AX,y add AX,z mov sum,AX

42 What Is Assembly Language? (Cont’d)
Readability of assembly language instructions is much better than the machine language instructions Machine language instructions are a sequence of 1s and 0s Assembly Language Machine Language (in Hex) inc result FF060A00 mov class_size,45 C7060C002D00 and mask, E0080 add marks, F000A

43 What Is Assembly Language? (Cont’d)
MIPS examples Assembly Language Machine Language (in Hex) nop move $t2,$t A2021 andi $t2,$t1, A000F addu $t3,$t1,$t A5821

44 Why Program in Assembly Language?
Two main reasons: Efficiency Space-efficiency Time-efficiency Accessibility to system hardware Assembly code tends to be compact Assembly language programs tend to run faster Only a well-written assembly language program runs faster Easy to write an assembly program that runs slower than its high-level language equivalent

45 Typical Applications Application that need one of the three advantages of the assembly language Time-efficiency Time-convenience Good to have but not required for functional correctness Graphics Time-critical Necessary to satisfy functionality Real-time applications Aircraft navigational systems Process control systems Robot control software Missile control software

46 Performance: C versus Assembly Language
C version AL version Last slide


Download ppt "Computer organization & Assembly Language Programming"

Similar presentations


Ads by Google