You are on page 1of 22

Computer Organization and

Assembly Language
Lecture: 2
BS(CS) Part 3 semester 2nd

By: Kashif Dayo


Lecturer Computer Science
The Shaikh Ayaz University, Shikarpur
Email: kashifdayo@Hotmail.com
Department of Computer Science
The Shaikh Ayaz University, Shikarpur 1
Lecture Outline
 Basic Microcomputer Design
 Instruction Execution Cycle
 Multi-Stage Pipeline
 Welcome to Assembly Language
 Why Learn Assembly Language?
 Assembly Language for x86 Processors
 What hardware and software do I need?
 Programmer's View
 A Hierarchy of Languages

Department of Computer Science The Shaikh Ayaz University, Shikarpur 2


Basic Microcomputer Design
 The central processor unit (CPU)
 Calculations and logical operations take place
 It contains:
 Limited number of storage locations named registers
A high-frequency clock (synchronizes the internal operations of the CPU
with other system components)
A control unit (coordinates the sequencing of steps involved in executing
machine instructions)
 An arithmetic logic unit.
 Bus is a group of parallel wires that transfer data from one part of the
computer to another.
 Memory storage unit is where instructions and data are held while a computer
program is running.
Department of Computer Science The Shaikh Ayaz University, Shikarpur 3
Basic Microcomputer Design Cont..
 A computer system usually contains 4 bus types:
 Data
 Data bus transfers instructions and data between the CPU and memory.

 Control
 Control bus uses binary signals to synchronize actions of all devices
attached to the system bus.
 Address.
 Address bus holds the addresses of instructions and data when the
currently executing instruction transfers data between the CPU and
memory.
 The I/O bus
 Transfers data between the CPU and the system input/output devices.
Department of Computer Science The Shaikh Ayaz University, Shikarpur 4
Basic Microcomputer Design

Department of Computer Science The Shaikh Ayaz University, Shikarpur 5


Clock
 Each operation involving the CPU and the system bus is synchronized by an
internal clock.
 It is an electrical signal on the control bus which alternates between zero and
one at a periodic rate.
 Basic unit of time for machine instructions is a machine cycle (or clock cycle).
 Clock cycle = Clock period = 1 / Clock rate
 Clock rate = Clock frequency = Cycles per second
1 Hz = 1 cycle/sec 1 KHz = 103 cycles/sec
1 MHz = 106 cycles/sec 1 GHz = 109 cycles/sec
2 GHz clock has a cycle time = 1/(2×10 9) = 0.5 nanosecond (ns)
 Clock cycles measure the execution of instructions

Department of Computer Science The Shaikh Ayaz University, Shikarpur 6


Memory
 Ordered sequence of bytes
 The sequence number is called the memory address
 Byte addressable memory
 Each byte has a unique address
 Supported by almost all processors
 Physical address space
 Determined by the address bus width
 Pentium has a 32-bit address bus
 Physical address space = 4GB = 232 bytes
 Itanium with a 64-bit address bus can support
 Up to 264 bytes of physical address space

Department of Computer Science The Shaikh Ayaz University, Shikarpur 7


Cache Memory
 Computer memory creates a speed bottleneck.
 Solution to this problem is in storing the most recently used instructions and data in
high-speed memory called cache (cash).
 Program is more likely to want to access the same memory and instructions repeatedly
 Cache memory keeps these values where they can be accessed quickly.
 If there happens to be a loop in that block of code, the same instructions will be in
cache.
 Cache hit
 Cache miss
 Temporal locality of reference
 Program repeatedly accesses the same memory location during a short time period
 Spatial locality of reference
 Program accesses neighboring memory locations.

Department of Computer Science The Shaikh Ayaz University, Shikarpur 8


Cache Memory Cont..
 Cache memory for the x86 family comes in two types.
 Level-1 cache (or primary cache):
 Stored right on the CPU.
 Level-2 cache (or secondary cache):
 Is it a little bit slower, and attached to the CPU by a high-speed data
bus.
 Cache memory is faster than conventional RAM.
 Constructed from a special type of memory chip called static RAM
 Expensive, but it does not have to be constantly refreshed in order to keep
its contents unlike dynamic RAM.

Department of Computer Science The Shaikh Ayaz University, Shikarpur 9


Welcome to Assembly Language

 Assembly language has a pretty bad reputation.


 Hard To learn, to debug, to maintain etc.…
 Time consuming large code
 Not portable

 What’s Right With Assembly Language?


 Speed.

You can speed up many programs by a factor of five or ten over HLL
 Space.

programs are often less than one-half the size of comparable HLL program.
 Capability

Direct access certain I/O devices on the computer.

Department of Computer Science The Shaikh Ayaz University, Shikarpur 10


Assembly language has a one-to-one relationship with machine language.

 instruction corresponds to a single machine-language


instruction.
Assembly Code Machine Code
mov ax, 5 B80500

mov bx, 10 BB0A00

add ax, bx 01D8

mov bx, 15 BB0F00

add ax, bx 01D8

Department of Computer Science The Shaikh Ayaz University, Shikarpur 11


Why Learn Assembly Language?

 Write embedded programs.


 Short programs stored in a small amount of memory in single-purpose devices.
 telephones, air-conditioning control systems, security systems, video or sound
cards, hard drives, modems, printers etc.
 Real-time applications
 simulation and hardware monitoring require precise timing and responses.
 Computer game consoles
 highly optimized for small code size and fast execution.
 Hardware/device drivers
 Device drivers are programs that translate general operating system commands
into specific references to hardware details.

Department of Computer Science The Shaikh Ayaz University, Shikarpur 12


Assembly and Machine Language
 Machine language
 Native to a processor: executed directly by hardware
 Instructions consist of binary code: 1s and 0s
 Assembly language
 Slightly higher-level language
 Readability of instructions is better than machine language
 One-to-one correspondence with machine language instructions
 Assemblers translate assembly to machine code
 Compilers translate high-level programs to machine code
 Either directly, or Indirectly via an assembler

Department of Computer Science The Shaikh Ayaz University, Shikarpur 13


Assembly vs High-Level Languages
Comparison of Assembly Language to High-Level Languages.

Department of Computer Science The Shaikh Ayaz University, Shikarpur 14


Assembly Language for x86 Processors

 Programming microprocessors compatible with Intel and AMD processors.


 Microsoft Macro Assembler (known as MASM)
 TASM (Turbo Assembler)
 NASM (Netwide Assembler)
 GAS (GNU assembler)

Department of Computer Science The Shaikh Ayaz University, Shikarpur 15


What hardware and software do I need?
 Microprocessors: compatible with Intel and AMD processors running under
32-bit and 64-bit versions of Microsoft Windows.
 Editor: Microsoft Visual Studio editor (used with Visual C++ ).
 Assembler: You need Microsoft Assembler (MASM).
 Linker: You need a linker utility to produce executable files.
 Debugger: Microsoft Visual Studio (msdev.exe), part of Microsoft Visual C+
+.

 Web site (asmirvine.com) for the latest details about support for MASM in
Visual Studio.

Department of Computer Science The Shaikh Ayaz University, Shikarpur 16


Debugger
 Allows you to trace the execution of a program
 Allows you to view code, memory, registers, etc.
 You will use the 32-bit Windows debugger

Department of Computer Science The Shaikh Ayaz University, Shikarpur 17


Linker and Link Libraries
 You need a linker program to produce executable files
 It combines your program's object file created by the assembler with other
object files and link libraries, and produces a single executable program
 LINK32.EXE is the linker program provided with the MASM distribution for
linking 32-bit programs

Department of Computer Science The Shaikh Ayaz University, Shikarpur 18


What types of programs will I create?
 16-bit Real-Address Mode:
 Running either pure MS-DOS or a DOS emulator
 16-bit programs can also run under 32-bit versions of Windows and on
embedded systems.
 32-Bit Protected Mode:
 Using Microsoft Windows
 You can create 32-bit Protected mode programs
 Can display both text and graphics.

Department of Computer Science The Shaikh Ayaz University, Shikarpur 19


Programmer's View/Specific Machine Levels
 Digital Logic (Level 0)
 Implements the microarchitecture
 Programs consist of binary numbers.
 Uses digital logic gates
 Logic gates are implemented using transistors
 Microarchitecture (Level 1)
 Controls the execution of machine instructions (Level 2)
 Average users/programmers are not allowed to write microinstructions .
 Specific microarchitecture commands are often a proprietary secret.
 Implemented by digital logic (Level 0)
 Instruction Set Architecture (Level 2)
 Specifies how a processor functions, Machine instructions, registers, and memory are exposed
 Instruction set (machine language) to carry out basic operations, such as move, add, or multiply
 This set of instructions is also referred to as machine language.
 Machine-language instruction is executed by several microinstructions .

Department of Computer Science The Shaikh Ayaz University, Shikarpur 20


Programmer's View/Specific Machine Levels
 Operating System (Level 3)
 Provides services to level 4 and 5 programs
 Translated to run at the machine instruction level
(Level 2)
 Assembly Language (Level 4)
 Instruction mnemonics are used
 Have one-to-one correspondence to machine language
 Calls functions written at the operating system level
(Level 3)
 Programs are translated to ISA or machine (Level 2)
 Application Programs (Level 5)
 Written in high-level programming languages
 Such as Java, C++, Pascal, Visual Basic . . .
 Programs compile into assembly language level (Level
4)

Department of Computer Science The Shaikh Ayaz University, Shikarpur 21


THE END

Department of Computer Science The Shaikh Ayaz University, Shikarpur 22

You might also like