Computer Organization and Architecture
Chapter 3-Assembly level
machine organization
Basic organization of the von Neumann machine
Von-Neumann computer architecture design was proposed in 1945.
It was later known as Von-Neumann architecture.
Historically there have been 2 types of Computers:
Fixed Program Computers- their function is very specific and they couldn’t be
reprogrammed, e.g. Calculators.
Stored Program Computers- these can be programmed to carry out many
different tasks, applications are stored on them.
Modern computers are based on a stored-program concept introduced by John
Von Neumann.
In this stored-program concept, programs and data are stored in a separate
storage unit called memories and are treated the same.
This novel idea meant that a computer built with this architecture would be
much easier to reprogram.
The basic structure is like this,
It is also known as ISA (Instruction
set architecture) computer and is
having three basic units:
1.The Central Processing Unit (CPU)
2.The Main Memory Unit
3.The Input/Output Device
Basic organization of the von Neumann machine
1. Central Processing Unit-
The central processing unit is an electric circuit used for the executing the
instruction of computer program.
It has following major components:
1. Control Unit(CU)
2. Arithmetic and Logic Unit(ALU)
3. variety of Registers
Basic organization of the von Neumann machine
1. Control Unit
It handles all processor control signals.
It directs all input and output flow, fetches code for instructions, and
controls how data moves around the system.
2. Arithmetic and Logic Unit (ALU)
is that part of the CPU that handles all the calculations the CPU may
need, e.g. Addition, Subtraction, Comparisons.
It performs Logical Operations, Bit Shifting Operations, and Arithmetic
operations.
Basic organization of the von Neumann machine
3. Registers: is high-speed storage areas in the CPU.
The data processed by the CPU are fetched from the registers.
There are different types of registers used in architecture:-
Accumulator: Stores the results of calculations made by ALU.
It holds the intermediate of arithmetic and logical operations.
it act as a temporary storage location or device.
Program Counter (PC): Keeps track of the memory location of the next
instructions to be dealt with.
The PC then passes this next address to the Memory Address Register
(MAR).
Memory Address Register (MAR): It stores the memory locations of
instructions that need to be fetched from memory or stored in memory.
Basic organization of the von Neumann machine
Memory Data Register (MDR): It stores instructions fetched from memory
or any data that is to be transferred to, and stored in, memory.
Current Instruction Register (CIR): It stores the most recently fetched
instructions while it is waiting to be coded and executed.
Instruction Buffer Register (IBR): The instruction that is not to be executed
immediately is placed in the instruction buffer register IBR.
Basic organization of the von Neumann machine
Figure 1.1: Basic CPU structure, illustrating ALU
Basic organization of the von Neumann machine
2. Memory
Memory in the von Neumann architecture stores both data and program
instructions.
It is typically divided into:
Primary Memory (RAM): is the main memory used to store data and
instructions that the CPU needs while performing tasks.
RAM (Random Access Memory)
• is a type of volatile memory used for temporary storage while the
computer is running.
ROM (Read-Only Memory)
• is a type of non-volatile memory that is used to store firmware or
software that is not intended to be modified frequently.
Secondary Memory (Storage): This refers to devices like hard drives and
SSDs, which store data and programs permanently. It is non-volatile.
Basic organization of the von Neumann machine
3. Input/output Devices
allow the computer to communicate with the outside world. They
include:
Input Devices: Devices used to input data into the computer (e.g.,
keyboard, mouse).
Output Devices: Devices used to output data from the computer (e.g.,
monitor, printer).
If some results are evaluated by the computer and it is stored in the
computer, then with the help of output devices, we can present them to
the user.
Basic organization of the von Neumann machine
Buses:- Data is transmitted from one part of a computer to another,
connecting all major internal components to the CPU and memory, by the
means of Buses.
Types of buses:
• Data Bus: It carries data among the memory unit, the I/O devices, and the
processor.
• Address Bus: It carries the address of data (not the actual data) between
memory and processor.
• Control Bus: It carries control commands from the CPU (and status
signals from other devices) in order to control and coordinate all the
activities within the computer.
Basic organization of the von Neumann machine
Generally the basic operation of a von Neumann machine follows these steps:
1. Fetch: fetches an instruction from memory using the address bus.
2. Decode: decodes the fetched instruction to understand what action is
required.
3. Execute: executes the instruction using the ALU for arithmetic or logic
operations.
4. Store (if needed): result of the execution is stored back in memory or sent to
an output device.
Assembly/machine language programming
Assembly language programming and machine language programming are low-
level programming approaches used to write instructions that are directly
executed by a computer's CPU.
Machine Language Programming
is the most basic programming language, consisting of binary code that the
computer's central processing unit (CPU) can execute directly.
It is composed of instructions written in binary (0s and 1s), specific to the
architecture of the machine.
Characteristics:
Binary Code: Instructions and data are represented in binary form.
Direct Execution: The CPU executes machine language instructions directly.
Architecture-Specific: Different CPU architectures have different machine languages.
Assembly/machine language programming
Binary Representation:
Machine language consists of binary instructions that the CPU can directly
execute.
Each instruction is represented by a specific sequence of bits, encoding the
operation, operands, and other necessary information.
CPU Instructions:
Machine language instructions directly correspond to CPU operations, such
as arithmetic, logic, and control flow.
Hexadecimal Representation:
Machine language instructions are typically represented in hexadecimal
format for readability.
Hexadecimal digits (0-9, A-F) are used to represent groups of four binary
bits (nibbles).
Assembly/machine language programming
Example:
For an 8-bit CPU, a machine language instruction might look like this:
10110000
This binary code could represent an instruction to move the value 61 (in
hexadecimal) into a register.
Assembly/machine language programming
Assembly Language Programming
• Human-Readable Mnemonics:
• Assembly language provides mnemonics for CPU instructions, making it
easier for programmers to write and understand code.
• Mnemonics represent specific CPU operations, such as arithmetic, data
movement, and control flow instructions.
• Symbolic Representation:
• Assembly language allows programmers to use symbolic labels to
represent memory addresses, making the code more readable and
maintainable.
• Labels can be used for branching, looping, and referencing memory
locations.
Assembly/machine language programming
• Low-Level Programming:
• Assembly language programming is considered low-level programming, as
it provides direct control over CPU registers, memory, and I/O operations.
• Programmers have fine-grained control over hardware resources, which is
useful for system programming, device drivers, and embedded systems
development.
• Platform-Specific:
• Assembly language is highly platform-specific, as instructions and syntax
vary between CPU architectures (e.g., x86, ARM, MIPS).
• Programs written in assembly language are not easily portable between
different hardware platforms.
Assembly/machine language programming
is a low-level programming language that uses mnemonic codes and labels to
represent machine-level instructions.
It provides a more human-readable way to program compared to machine
language.
Characteristics:
Mnemonics: Uses symbolic names (mnemonics) for operations (e.g., MOV,
ADD).
Labels: Allows the use of labels for memory addresses, making programs
easier to read and write.
One-to-One Correspondence: Each assembly language instruction typically
corresponds to a single machine language instruction.
Assembler Required: An assembler is needed to translate assembly language
into machine language.
Assembly/machine language programming
Key Components of Assembly Language
Instructions: Basic operations such as data movement, arithmetic operations, and
control flow.
Data Movement: MOV, LOAD, STORE
Arithmetic/Logic: ADD, SUB, MUL, DIV, AND, OR
Control Flow: JMP, CALL, RET, JE, JNE
Registers: used to hold data temporarily.
Examples: AX: Accumulator register. BX: Base register. CX: Counter register. DX: Data
register for general-purpose registers.
Labels: Named locations in the code used for branching and looping.
Example: START:, LOOP:
Directives: Instructions to the assembler on how to process the program.
Examples: .data, .code, .org
Assembly/machine language programming
Example:
• For the same 8-bit CPU, the equivalent assembly language instruction for
moving the value 61 into a register might look like this:
MOV AL, 61h
Data Movement Instructions
Syntax: MOV destination, source
Example: MOV AL, 61h (Moves the hexadecimal value 61 into the AL register)
Assembly/machine language programming
Data Movement Instructions
MOV: Transfers data from one location to another.
Example: MOV AX, BX (Moves the content of register BX into register AX)
LOAD: Loads data from memory into a register.
Example: LOAD AX, [1234h] (Loads the value at memory address 1234h
into AX)
STORE: Stores data from a register into memory.
Example: STORE [1234h], AX (Stores the value of AX into memory address
1234h)
Assembly/machine language programming
Arithmetic/Logic
These instructions perform arithmetic and logical operations.
ADD: Adds two values.
Example: ADD AX, BX (Adds the value of BX to AX)
SUB: Subtracts one value from another.
Example: SUB AX, BX (Subtracts the value of BX from AX)
MUL: Multiplies two values.
Example: MUL BX (Multiplies AX by BX, result in DX
Assembly/machine language programming
Instruction formats
Instruction formats in assembly language define the structure and layout of
machine instructions that the CPU can execute.
Different instruction formats are used to accommodate various types of
operations and operands.
1. One-Operand Format
Used for instructions that involve only one operand.
Operand: specifies the data or address on which the operation is to be
performed
Example: INC AX (Increment the value in the AX register by 1)
2. Two-Operand Format
Used for instructions involving two operands.
Example: MOV AX, BX (Move the value from BX to AX)
Assembly/machine language programming
3. Three-Operand Format
Used for instructions involving three operands.
Example: ADD AX, BX, CX (Add the values in BX and CX and store the
result in AX)
Format: operation source1, source2, destination
4. Zero-Operand Format
Used for instructions that do not require any operands.
Example: HLT (Halt the CPU)
In this format, the operation is performed without any
operands.
Assembly/machine language programming
Instruction formats
There are different instruction formats regarding number of address used.
3 address instruction
2 address instruction
1 address instruction
0 address instruction
3 address instruction
-it takes the form of Add A,B,C
-indicates value to be added are content of memory location B and C and stored
on memory location A.
Example: X=Y+Z Add X,Y,Z
Assembly/machine language programming
2 address instruction
• It takes the form of Add ,A,B
• Indicates add the content of A&B and store on A.
• It is equivalent to Add A,A B
• Example: X=X+Y Add X,X,Y
1 address instruction
-it takes the form of Add A
-indicates add content of Accumulator (ACC)to content of A
-Example: ACC ACC+A
Assembly/machine language programming
I/O and interrupts
In assembly and machine language, I/O and interrupts are handled through
specific instructions and hardware mechanisms:
I/O Operations in Assembly Language:
In assembly language, input/output operations involve specific instructions to
transfer data between the CPU and external devices.
These instructions vary based on the architecture and hardware of the system
but typically include commands to read from or write to specific memory-
mapped I/O ports or memory addresses associated with peripheral devices.
Examples of assembly instructions for I/O operations might include IN and
OUT instructions in x86 assembly language or specialized instructions provided
by the particular architecture's instruction set for accessing I/O devices.
Assembly/machine language programming
Interrupt Handling in Assembly Language:
Interrupts are signals sent by hardware devices or software to interrupt the
normal execution flow of the CPU.
In assembly language, interrupt handling involves defining interrupt service
routines (ISRs) that are executed when specific interrupts occur.
The ISR, written in assembly language, executes the necessary code to handle
the interrupt, which may involve servicing the I/O device, responding to a
system call, or handling an exception.
When an interrupt occurs, the CPU automatically saves its current state and
jumps to the memory address of the corresponding interrupt vector, which
points to the ISR for that interrupt.
Once the ISR completes execution, control typically returns to the interrupted
program, which resumes execution from where it was interrupted.