Computer Organization and
Assembly Language
Computing Machines
Ubiquitous ( = everywhere)
• General purpose: servers, desktops, laptops, PDAs,
etc.
• Special purpose: cash registers, ATMs, games, Mobile
Phones, etc.
• Embedded: cars, door locks, printers, digital players,
industrial machinery, medical equipment, etc.
Distinguishing Characteristics
• Speed
• Cost
• Ease of use, software support & interface
• Scalability
Computer
Hardware Software
Electronics circuit boards Program consists
that provide of sets of instructions
functionality of the system that control the system
Inside the Computer
• Application software
• Written in high-level language
• System software
• Compiler: translates HLL code to machine code
• Operating System: service code
• Handling input/output
• Managing memory and storage
• Scheduling tasks & sharing resources
• Hardware
• Processor, memory, I/O controllers
Functions of a Computer
Functions of all Computers are:
• Data processing
• Data storage
• Data movement
• Control
A Programmer’s View of a Computer
Application Programs
Machine-independent High-Level Languages High-Level Languages
Machine-Specifi Low-Level Language
Assembly Language
Machine Language
Microprogram Control
Hardware
Levels of Program Code
• High-level language
• Level of abstraction closer to
problem domain
• Provides productivity and
portability
• Assembly language
• Textual representation of
instructions
• Hardware representation
• Binary digits (bits)
• Encoded instructions and data
Computer Organization and Architecture
COMPUTER ORGANIZATION
• How components fit together to create working computer system
• Includes physical aspects of computer systems
• Concerned with how computer hardware works
COMPUTER ARCHITECTURE
• Structure and behavior of computer system
• Logical aspects of system implementation as seen by programmer
• Concerned with how computer is designed
• Combination of hardware components with Instruction Set
Architecture (ISA): ISA is interface between software that runs on
machine & hardware that executes it
Moore’s Law
• In 1965, Intel founder Gordon Moore stated:
“The density of transistors in an integrated circuit
will double every year”
• Current version of Moore’s Law predicts doubling of
density of silicon chips every 18 months
• Moore originally thought this postulate would hold for
10 years; advances in chip manufacturing processes
have allowed the law to hold for 40 years, and it is
expected to last for perhaps another 10
Principle of Equivalence of Hardware and Software
• Anything that can be done with software can also be done with
hardware, and anything that can be done with hardware can also be
done with software
• Modern computers are implementations of algorithms that execute
other algorithms
Semantic Gap
• Open space between the physical components of a computer system
and the high-level instructions of an application
• Semantic gap is bridged at each level of abstraction
Abstraction
Complete definition of abstraction includes the following:
• Suppression of detail
• Outline structure
• Division of responsibility
• Subdivision of system into smaller subsystems
Abstraction and Computer Systems
• Can look at a computer as being a machine composed of
a hierarchy of levels
• Each level has specific function
• Each level exists as a distinct hypothetical machine (or virtual
machine)
• Each level’s virtual machine executes its own particular
set of instructions, calling upon machines at lower levels
to carry out tasks as necessary
Abstraction and Computer Systems
“I really don’t think that you can write a book for serious
computer programmers unless you are able to discuss
low-level details.”
Donald E. Knuth
The Art of Computer Programming
http://en.wikipedia.org/wiki/Donald_Knuth
Abstraction and Computer Systems
Machine-independent
• Text uses the following labels to describe
levels of abstraction in a computer system:
App7
Machine-specific
HOL6
Asmb5
OS4
ISA3
Mc2
LG1
• Each level has its own language to describe
tasks performed by Computer
Abstraction and Computer Systems
Machine-independent
Level : APP7
• The application level is composed of those
programs designed to do specific kinds of
tasks for end users
Machine-specific
• An application may have some sort of
programming language associated with it
(macros or shortcuts, e.g.)
• Ideally, end users need not be concerned
with the actions and language(s)
associated with lower levels in the
abstraction hierarchy
Abstraction and Computer Systems
Machine-independent
Level : HOL6
• The high order language layer is the layer
of abstraction at which most programmers
operate
Machine-specific
• Applications are typically written in high
order languages
• High order languages are characterized by:
• Portability across platforms
• Relative ease of use
• Relatively high level of abstraction, requiring
translation of program code prior to execution
Abstraction and Computer Systems
Machine-independent
Level : ASMB5
• The assembly language level is an
intermediate step between high order
language and the machine language of a
Machine-specific
particular processor
• Programs at the HOL6 level are usually
compiled to level Asmb5, then translated
(assembled) to machine language
• Source code can also be written in
assembly language
Abstraction and Computer Systems
Machine-independent
Level : OS4
• The operating system is responsible tasks
related to multiprogramming, including:
• Memory protection
Machine-specific
• Process synchronization
• Device management
• Operating systems were originally developed
for multiuser systems, but even most single
user systems utilize an operating system
• Compilers and assemblers are also
considered systems software
Abstraction and Computer Systems
Machine-independent
Level : ISA3
• The instruction set architecture, or
machine language level, consists of the
set of instructions recognized by the
Machine-specific
particular hardware platform
• Instructions at this level are directly
executable without any translation
Abstraction and Computer Systems
Machine-independent
Level : MC2
• The microinstruction or control level is the
level at which the computer decodes and
executes instructions and moves data in
Machine-specific
and out of the processor
• The processor’s control unit interprets
machine language instructions, causing
required actions to take place
Abstraction and Computer Systems
Machine-independent
Level : LG1
• The digital logic level consists of the
physical components of the computer
system, the actual electronic gates and
Machine-specific
wires
• Boolean algebra and truth tables can be
used to describe the operations at this
level
Anatomy of a Computer
Historical Development
• To fully appreciate the computers of today, it is
helpful to understand how things got the way they
are.
• The evolution of computing machinery has taken
place over several centuries.
• In modern times computer evolution is usually
classified into four generations according to the
salient technology of the era.
We note that many of the following dates are approximate.
23
Historical Development
• Generation Zero: Mechanical Calculating Machines
(1642 - 1945)
– Calculating Clock - Wilhelm Schickard (1592 - 1635).
– Pascaline - Blaise Pascal (1623 - 1662).
– Difference Engine - Charles Babbage (1791 - 1871),
also designed but never built the Analytical Engine.
– Punched card tabulating machines - Herman Hollerith
(1860 - 1929).
Hollerith cards were commonly used for
computer input well into the 1970s.
24
Historical Development
• The First Generation: Vacuum Tube
Computers (1945 - 1953)
– Atanasoff Berry
Computer (1937 -
1938) solved systems
of linear equations.
– John Atanasoff and
Clifford Berry of Iowa
State University.
25
Historical Development
• The First Generation: Vacuum Tube Computers
(1945 - 1953)
– Electronic Numerical
Integrator and
Computer (ENIAC)
– John Mauchly and J.
Presper Eckert
– University of
Pennsylvania, 1946
The first general-purpose computer.
The Army’s ENIAC, 1946 26
Historical Development
• The First Generation: Vacuum Tube Computers
(1945 - 1953)
– IBM 650
(1955)
– Phased out
in 1969.
The first mass-produced computer.
27
Historical Development
• The Second Generation: Transistorized
Computers (1954 - 1965)
– IBM 7094 (scientific)
and 1401 (business)
– Digital Equipment
Corporation (DEC) PDP-
1
– Univac 1100
– . . . and many others.
DEC PDP-1
28
Historical Development
• The Third Generation: Integrated Circuit
Computers (1965 - 1980)
– IBM 360
– DEC PDP-8 and PDP-
11
– Cray-1
supercomputer
– . . . and many IBM 360
others.
Cray-1
29
Historical Development
• The Fourth Generation: VLSI Computers
(1980 - ????)
– Very large scale integrated circuits
(VLSI) have more than 10,000
components per chip.
– Enabled the creation of
microprocessors.
– The first was the 4-bit Intel 4004. Intel
Later versions, such as the 8080, 8086, 4004
and 8088 spawned the idea of “personal
computing.”
30
Computer: Functional View
Data
Storage
Facility
Data
Control
Movement
Apparatus
Mechanism
Data
Processing
Facility
Computer: Operation
Data Movement
e.g. Keyboard to Screen
Data
Storage
Facility
Data
Control
Movement
Apparatus
Mechanism
Data
Processing
Facility
Computer: Operation..
Storage
e.g. Internet Download to Hard Disk
Data
Storage
Facility
Data
Control
Movement
Apparatus
Mechanism
Data
Processing
Facility
Computer: Operation….
Processing from/to storage
e.g. Updating Word/Excel File
Data
Storage
Facility
Data
Control
Movemen
Mechanism
t
Apparatus
Data
Processing
Facility
Computer: Operation…...
Processing from storage to I/O
e.g. Printing a Word/Excel file.
Data
Storage
Facility
Data
Control
Movemen
Mechanism
t
Apparatus
Data
Processing
Facility
Anatomy of a Computer: Block Diagram
Anatomy of a Computer: Detailed Block Diagram
Anatomy of a Computer: Detailed Block Diagram
..
Detailed Anatomy of a Computer
Processor (CPU)
Control Unit Common Bus (address, data & control)
Datapath
Arithmetic
Logic Unit
(ALU)
Registers
Memory
Output
Program Input Units
Units
Storage
Data Storage
Anatomy of a Computer: CPU
The brain of a Computer System
Processor (CPU)
•Decodes and monitors the execution of instructions.
•Controls flow of information in CPU, memory, I/O
Control Unit devices:
Datapath •System clock (Intel® Core™ I7-720QM Processor
(1.6GHz, turbo up to 2.8GHz, 6MB L3 Cache))
•Maintains a register called program counter(PC)
Arithmetic
Logic Unit
(ALU) •ALU: performs all arithmetic computations & logic
Registers evaluations.
•Registers: storage location in CPU, used to hold data
or a memory address during the execution of an
instruction..
Anatomy of a Computer: Common Bus
Common Bus (address, data & control)
A group of conducting wires that allow signals to travel from one
point to another:
• Address bus: the location of data in memory or I/O devices
• Data bus: carry data in & out from CPU
• Control bus: control the operation of the CPU
Anatomy of a Computer: Memory
Memory
Program
Storage
Data Storage
• Volatile: cannot retain data without power.
RAM • Allows the processor to read from & write into any
location on memory chip.
• Nonvolatile: when power is removed, the reapplied, the
ROM original data will still be there
• Can only be read, cannot be written to by the processor
Anatomy of a Computer: Memory
data address
Components of memory
• A memory in Microprocessor stores data in binary format. To retrieve an information, the
Microprocessor assigns addresses to the location. Each location stores 1 byte of data.
• If a value of hex A0 is stored in the location of $2001, show the content of the memory
on $2001.
Anatomy of a Computer: I/O Devices
Input devices
Allow computer user to enter data & programs into the computer
Anatomy of a Computer: I/O Devices
Output device
Displaying the results of computation
The von Neumann Model
• On the ENIAC
(1946-1955), all
programming
was done at the
digital logic
level.
• Programming
the computer
involved moving
plugs and wires.
46
The von Neumann Model
• Inventors of the ENIAC, John Mauchley and
J. Presper Eckert, conceived of a computer
that could store instructions in memory.
• The invention of this idea has since been
ascribed to a mathematician, John von
Neumann, who was a contemporary of
Mauchley and Eckert.
• Stored-program computers have become
known as von Neumann Architecture systems.
47
The von Neumann Model
• Today’s stored-program computers have the
following characteristics:
– Three hardware systems:
• A central processing unit (CPU)
• A main memory system
• An I/O system
– The capacity to carry out sequential instruction
processing.
– A single data path between the CPU and main
memory.
• This single path is known as the von Neumann
bottleneck.
48
The von Neumann Model
• This is a general
depiction of a von
Neumann system:
• These computers
employ a fetch-
decode-execute
cycle to run
programs as
follows . . .
49
The von Neumann Model
• The control unit fetches the next instruction from
memory using the program counter to determine where
the instruction is located.
50
The von Neumann Model
• The instruction is decoded into a language that the ALU
can understand.
51
The von Neumann Model
• Any data operands required to execute the instruction
are fetched from memory and placed into registers
within the CPU.
52
The von Neumann Model
• The ALU executes the instruction and places results in
registers or memory.
53
The Modified von Neumann Architecture
(adding a system bus)
54
The System Bus Model
• A refinement of the von Neumann model, the system bus model has a CPU (ALU and
control), memory, and an input/output unit.
• Communication among components is handled by a shared pathway called the system
bus, which is made up of the data bus, the address bus, and the control bus. There is also
a power bus, and some architectures may also have a separate I/O bus.
Assembly Language
Some Important Questions to ask
• What is Assembly Language?
• Why Learn Assembly Language?
• What is Machine Language?
• How is Assembly related to Machine Language?
• What is an Assembler?
• How is Assembly related to High-Level Language?
• Is Assembly Language portable?
A Hierarchy of Languages
Application Programs
Machine-independent High-Level Languages High-Level Languages
Machine-Specifi Low-Level Language
Assembly Language
Machine Language
Microprogram Control
Hardware
Assembly and Machine Language
• Machine language
• Native to a processor: executed directly by hardware
• Instructions consist of binary code: 1s and 0s
• Assembly language
• A programming language that uses symbolic names to represent
operations, registers and memory locations.
• 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
Compiler and Assembler
Instructions and Machine Language
• Each command of a program is called an instruction (it
instructs the computer what to do).
• Computers only deal with binary data, hence the
instructions must be in binary format (0s and 1s) .
• The set of all instructions (in binary form) makes up the
computer's machine language. This is also referred to as
the instruction set.
Instruction Fields
• Machine language instructions usually are made up of
several fields. Each field specifies different information for
the computer. The major two fields are:
• Opcode field which stands for operation code and it
specifies the particular operation that is to be performed.
• Each operation has its unique opcode.
• Operands fields which specify where to get the source and
destination operands for the operation specified by the
opcode.
• The source/destination of operands can be a constant,
the memory or one of the general-purpose registers.
Translating Languages
English: D is assigned the sum of A times B plus 10.
High-Level Language: D = A * B + 10
A statement in a high-level language is translated
typically into several machine-level instructions
Intel Assembly Language: Intel Machine Language:
mov eax, A A1 00404000
mul B F7 25 00404004
add eax, 10 83 C0 0A
mov D, eax A3 00404008
Mapping Between Assembly Language and HLL
• Translating HLL programs to machine language
programs is not a one-to-one mapping
• A HLL instruction (usually called a statement) will be
translated to one or more machine language instructions
Advantages of High-Level Languages
• Program development is faster
• High-level statements: fewer instructions to code
• Program maintenance is easier
• For the same above reasons
• Programs are portable
• Contain few machine-dependent details
• Can be used with little or no modifications on different
machines
• Compiler translates to the target machine language
• However, Assembly language programs are not portable
Why Learn Assembly Language?
• Accessibility to system hardware
• Assembly Language is useful for implementing system software
• Also useful for small embedded system applications
• Space and Time efficiency
• Understanding sources of program inefficiency
• Tuning program performance
• Writing compact code
• Writing assembly programs gives the computer designer
the needed deep understanding of the instruction set and
how to design one
• To be able to write compilers for HLLs, we need to be
expert with the machine language. Assembly
programming provides this experience
Assembly vs. High-Level Languages
• HLL programs are machine independent. They are easy to learn and
easy to use.
• Assembly language programs are machine specific. It is the
language that the processor directly understands.
Tools for Assembly Language: Assembler
• Software tools are needed for editing, assembling, linking, and
debugging assembly language programs
• An assembler is a program that converts source-code programs
written in assembly language into object files in machine language
• Popular assemblers have emerged over the years for the Intel family
of processors. These include …
• TASM (Turbo Assembler from Borland)
• NASM (Netwide Assembler for both Windows and Linux), and
• GNU assembler distributed by the free software foundation
• MASM (Macro Assembler from Microsoft)
Tools for Assembly Language: Linker & 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
Assemble and Link Process
Source Object
File Assembler File
Source Object Executable
File Assembler File Linker
File
Source Object Link
File Assembler File Libraries
• A project may consist of multiple source files
• Assembler translates each source file separately into an object file
• Linker links all object files together with link libraries
Summary
• Complete anatomy and functional view of a Computer.
• How different components fit together to create working computer
system.
• A computer system can be viewed as consisting of layers. Programs at
one layer are translated or interpreted by the next lower-level layer.
• Assembly language helps you learn how software is constructed at the
lowest levels.
• Assembly language has a one-to-one relationship with machine
language.
• An assembler is a program that converts assembly language programs
into machine language.
• A linker combines individual files created by an assembler into a single
executable file.