0% found this document useful (0 votes)
10 views79 pages

SP Week 3-4

Uploaded by

sisayyohannes997
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views79 pages

SP Week 3-4

Uploaded by

sisayyohannes997
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 79

WEEK 3-4

Contents
• Machine Considerations for Assemblers
• Modularization and program assembly
• Memory Management
Machine Considerations for Assemblers
• Machine code is a computer program written in
machine language instructions that can be executed
directly by a computer's central processing unit (CPU).
• Each instruction causes the CPU to perform a very
specific task, such as a load, a store, a jump, or an
arithmetic logic unit (ALU) operation on one or more
units of data in central processing unit (CPU) registers or
memory.
Instruction set architecture
An instruction set architecture (ISA) is an
abstract model of a computer.
It is also referred to as architecture or computer
architecture.
Instruction set architecture continued..
• One instruction may have several fields, which identify the
logical operation, and may also include source and destination
addresses and constant values.
• This is the MIPS "Add Immediate" instruction, which allows
selection of source and destination registers and inclusion of a
small constant.
• MIPS (Microprocessor without Interlocked Pipelined
Stages) is a reduced instruction set computer (RISC)
instruction set architecture (ISA) developed by MIPS
Computer Systems
• MIPS I has thirty-two 32-bit general-purpose registers
(GPR).
• Instructions are divided into three types: R, I and J. Every
instruction starts with a 6-bit opcode.
• In addition to the opcode,
• R-type instructions specify three registers, a shift
amount field, and a function field;
• I-type instructions specify two registers and a 16-
bit immediate value;
• J-type instructions follow the opcode with a 26-bit
jump target.
• The following are the three formats used for
the core instruction set:
• Load instructions source the base from the contents of a GPR (rs)
and write the result to another GPR (rt).
• Store instructions source the base from the contents of a GPR (rs)
and the store data from another GPR (rt).
• All load and store instructions compute the memory address by
summing the base with the sign-extended 16-bit immediate.
• MIPS I has instructions to perform addition and subtraction.
These instructions source their operands from two GPRs (rs and
rt), and write the result to a third GPR (rd).
Number of operands
• Instruction sets may be categorized by the maximum number
of operands explicitly specified in instructions.
• (In the examples that follow, a, b, and c are (direct or
calculated) addresses referring to memory cells, while reg1
and so on refer to machine registers.)
• C = A+B
• 0-operand (zero-address machines), so called stack machines:
All arithmetic operations take place using the top one or two
positions on the stack: push a, push b, add, pop c.
– C = A+B needs four instructions.
– For stack machines, the terms "0-operand" and "zero-
address" apply to arithmetic instructions, but not to all
instructions, as 1-operand push and pop instructions are
used to access memory.
• 1-operand (one-address machines), so called
accumulator machines, include early computers and many
small microcontrollers: most instructions specify a single right
operand (that is, constant, a register, or a memory location),
with the implicit accumulator as the left operand (and the
destination if there is one): load a, add b, store c.
• C = A+B needs three instructions.
• 2-operand — many CISC and RISC machines fall under this
category:
• CISC — move A to C; then add B to C.
– C = A+B needs two instructions. This effectively 'stores'
the result without an explicit store instruction.
• CISC — Often machines are limited to one memory operand
per instruction: load a,reg1; add b,reg1; store reg1,c; This
requires a load/store pair for any memory movement
regardless of whether the add result is an augmentation
stored to a different place, as in C = A+B, or the same memory
location: A = A+B.
– C = A+B needs three instructions.
• RISC — Requiring explicit memory loads, the
instructions would be: load a,reg1; load b,reg2; add
reg1,reg2; store reg2,c.
– C = A+B needs four instructions.
• 3-operand, allowing better reuse of data:
• CISC — It becomes either a single instruction: add
a,b,c
– C = A+B needs one instruction.
• more operands—some CISC machines permit a
variety of addressing modes that allow more than 3
operands (registers or memory accesses), such as the
VAX "POLY" polynomial evaluation instruction.
• A computer is a machine that can be
instructed to carry out sequences of
arithmetic or logical operations
automatically v
• MOSFET (MOS transistor), showing gate (G),
body (B), source (S) and drain (D) terminals.
• The gate is separated from the body by an insulating
layer (pink).ia computer programming.
• The metal–oxide–silicon field-effect transistor (MOSFET),
also known as the MOS transistor
• A central processing unit (CPU), also called a central
processor or main processor, is the electronic circuitry
within a computer that executes instructions that make
up a computer program.
• Block diagram of a basic
uniprocessor-CPU
computer.
• Black lines indicate data
flow, whereas red lines
indicate control flow;
arrows indicate flow
directions.
• The arithmetic logic unit (ALU) is a
digital circuit within the processor
that performs integer arithmetic
and bitwise logic operations.
• The inputs to the ALU are the data
words to be operated on (called
operands), status information from
previous operations, and a code
from the control unit indicating
which operation to perform.
• An arithmetic logic unit (ALU) is a combinational
digital electronic circuit that performs arithmetic and
bitwise operations on integer binary numbers.
• Bit shift operations
• ALU shift operations cause operand A (or B) to shift left or right
(depending on the opcode) and the shifted operand appears at Y.
• Simple ALUs typically can shift the operand by only one bit
position, whereas more complex ALUs employ barrel shifters that
allow them to shift the operand by an arbitrary number of bits in
one operation.
• In all single-bit shift operations, the bit shifted out of the
operand appears on carry-out; the value of the bit shifted
into the operand depends on the type of shift.
• Arithmetic shift: the operand is treated as a
two's complement integer, meaning that the most
significant bit is a "sign" bit and is preserved.
• Logical shift: a logic zero is shifted into the operand. This
is used to shift unsigned integers.
• Rotate: the operand is
treated as a circular buffer
of bits so its least and
most significant bits are
effectively adjacent.
• Rotate through carry: the
carry bit and operand are
collectively treated as a
circular buffer of bits.
• Integer range
• Every CPU represents numerical values in a specific way. For
example, some early digital computers represented numbers as
familiar decimal (base 10) numeral system values
• A six-bit word containing the binary encoded representation of
decimal value 40. Most modern CPUs employ word sizes that
are a power of two, for example 8, 16, 32 or 64 bits.
• Parallelism
• The description of the basic operation of a CPU offered in the
previous section describes the simplest form that a CPU can
take. This type of CPU, usually referred to as subscalar, operates
on and executes one instruction on one or two pieces of data at
a time, that is less than one instruction per clock cycle (IPC < 1).
• Model of a subscalar CPU, in which it takes fifteen clock cycles
to complete three instructions
• Instruction-level parallelism
• One of the simplest methods used to accomplish increased
parallelism is to begin the first steps of instruction fetching and
decoding before the prior instruction finishes executing.
• This is the simplest form of a technique known as
instruction pipelining, and is used in almost all modern general-
purpose CPUs.
• Pipelining allows more than one instruction to be executed at
any given time by breaking down the execution pathway into
discrete stages.
• This separation can be compared to an assembly line, in which
an instruction is made more complete at each stage until it
exits the execution pipeline and is retired.
• Basic five-stage pipeline. In the best case scenario, this pipeline
can sustain a completion rate of one instruction per clock cycle.
• A compiler is a computer program that
translates computer code written in one
programming language (the source language)
into another language (the target language).
• (e.g., assembly language, object code, or
machine code) to create an executable
program.
• A diagram of the
operation of a typical
multi-language, multi-
target compiler
• Three-stage compiler structure

Compiler design
• The stages include a front end, a middle end, and a back
end.
• The front end verifies syntax and semantics according to a
specific source language.
• The middle end performs optimizations on the IR that are
independent of the CPU architecture being targeted.
• The back end takes the optimized IR from the middle end.
• Machine code is a strictly numerical language
which is intended to run as fast as possible,
and may be regarded as the lowest-level
representation of a compiled or assembled
computer program or as a primitive and
hardware-dependent programming language.
• The overwhelming majority of practical programs
today are written in higher-level languages or
assembly language.
• The source code is then translated to executable
machine code by utilities such as compilers,
assemblers, and linkers, with the important exception
of interpreted programs, which are not translated into
machine code.
• In computing, a linker or link editor is a computer
System program that takes one or more object files
generated by a compiler or an assembler and
combines them into a single executable file, library file,
or another 'object' file.
• An illustration of the linking process.
• Object files and static libraries are assembled into a
new library or executable
• An interpreter is a computer program that directly executes
instructions written in a programming or scripting language,
without requiring them previously to have been compiled
into a machine language program.
• Machine code is by definition the lowest level of
programming detail visible to the programmer, but internally
many processors use microcode or optimise and transform
machine code instructions into sequences of micro-ops.
• This is not generally considered to be a machine code.
• Microcode is a computer hardware technique that
interposes a layer of organisation between the CPU
hardware and the programmer-visible instruction set
architecture of the computer.
• Micro-operations (also known as a micro-ops or μops)
are detailed low-level instructions used in some designs
to implement complex machine instructions (sometimes
termed macro-instructions in this context)
• A high-level
illustration showing
the decomposition of
machine instructions
into micro-
operations,
performed during
typical
fetch-decode-execute
cycles
• A memory address is a
reference to a specific
memory location used at
various levels by software
and hardware.
• In a computer using
virtual memory,
accessing the location
corresponding to a
memory address may
involve many levels.
• A system call is the programmatic way in which
a computer program requests a service from the
kernel of the operating system it is executed on.
• A high-level overview of the Linux kernel's
system call interface, which handles
communication between its various components
and the userspace
Modularization and Program Assembly
• Modular programming is a software design technique
that emphasizes separating the functionality of a
program into independent, interchangeable modules,
such that each contains everything necessary to execute
only one aspect of the desired functionality.
• A module interface expresses the elements that are
provided and required by the module. The elements
defined in the interface are detectable by other modules.
• A computer
program is a collection
of instructions that
can be executed by a
computer to perform a
specific task.
• A computer program
written in the
imperative
programming style
• The implementation contains the working code that
corresponds to the elements declared in the interface.
• While the historical usage of these terms has been
inconsistent, "modular programming" now refers to high-
level decomposition of the code of an entire program into
pieces: structured programming to the low-level code use of
structured control flow, and object-oriented programming to
the data use of objects, a kind of data structure.
• Control flow (or flow of control) is
the order in which individual
statements, instructions or
function calls of an imperative
program are executed or evaluated.
• A flow chart showing control flow.
• If-then-(else) statements

• Case and switch statements


• Assembly language uses a mnemonic to represent each
low-level machine instruction or opcode, typically also
each architectural register, flag, etc.
• Many operations require one or more operands in order
to form a complete instruction.
• Most assemblers permit named constants, registers, and
labels for program and memory locations, and can
calculate expressions for operands.
• Thus, the programmers are freed from tedious repetitive
calculations and assembler programs are much more readable
than machine code.
• Depending on the architecture, these elements may also be
combined for specific instructions or addressing modes using
offsets or other data as well as fixed addresses.
• Many assemblers offer additional mechanisms to facilitate
program development, to control the assembly process, and to
aid debugging.
• A mnemonic, the first "m" is
not pronounced) device,
or memory device, is any learning
technique that aids information
retention or retrieval
(remembering) in the human
memory.
• Knuckle mnemonic for the number
of days in each month of the
Gregorian Calendar. Each knuckle
represents a 31-day month.
• A processor register is a quickly accessible
location available to a computer's
central processing unit (CPU).
• Registers usually consist of a small amount of
fast storage, although some registers have
specific hardware functions, and may be read-
only or write-only.
• Computer data storage is a
technology consisting of computer
components and recording media
that are used to retain digital data
• Various forms of storage, divided
according to their distance from
the central processing unit.
• The fundamental components of a
general-purpose computer are
arithmetic and logic unit,
control circuitry, storage space,
and input/output devices.
• A bit field is a data structure used in
computer programming.
• It consists of a number of adjacent computer memory
locations which have been allocated to hold a sequence
of bits, stored so that any single bit or group of bits
within the set can be addressed.
• Addressing modes are an aspect of the
instruction set architecture in most
central processing unit (CPU) designs.
• Simple addressing modes for code
• Absolute or direct
• Sequential addressing modes

• Simple addressing modes for data

• This "addressing mode" does not have an effective address and


is not considered to be an addressing mode on some
computers.
• In this example, all the operands are in registers, and the result
is placed in a register.
• Number of passes
• There are two types of assemblers based on how many passes
through the source are needed (how many times the assembler reads
the source) to produce the object file.
• One-pass assemblers go through the source code once. Any symbol
used before it is defined will require "errata" at the end of the object
code (or, at least, no earlier than the point where the symbol is
defined) telling the linker or the loader to "go back" and overwrite a
placeholder which had been left where the as yet undefined symbol
was used.
• A macro assembler includes a macroinstruction facility
so that (parameterized) assembly language text can be
represented by a name, and that name can be used to
insert the expanded text into other code.
• A cross assembler (see also cross compiler) is an
assembler that is run on a computer or operating system
(the host system) of a different type from the system on
which the resulting code is to run (the target system).
• A high-level assembler is a program that provides language
abstractions more often associated with high-level languages, such as
advanced control structures (IF/THEN/ELSE, DO CASE, etc.) and high-
level abstract data types, including structures/records, unions, classes,
and sets.
• A microassembler is a program that helps prepare a microprogram,
called firmware, to control the low level operation of a computer.
• A meta-assembler is a term used in some circles for "a program that
accepts the syntactic and semantic description of an assembly
language, and generates an assembler for that language."
• Multi-pass assemblers create a table with all
symbols and their values in the first passes,
then use the table in later passes to generate
code.
• Memory management is a form of resource management
applied to computer memory.
• The essential requirement of memory management is to
provide ways to dynamically allocate portions of memory
to programs at their request, and free it for reuse when no
longer needed.
• This is critical to any advanced computer system where
more than a single process might be underway at any time.
Process states
• An operating system kernel that allows
multitasking needs processes to have
certain states.
• Names for these states are not standardised,
but they have similar functionality
• In computing, scheduling is the method by
which work is assigned to resources that
complete the work.
• A sample thread pool (green boxes) with a
queue (FIFO) of waiting tasks (blue) and a
queue of completed tasks (yellow)
• While the process is "waiting", it waits for the
scheduler to do a so-called context switch.
• The context switch loads the process into the
processor and changes the state to "running"
while the previously "running" process is
stored in a "waiting" state.
• If a process in the "running" state needs to wait
for a resource (wait for user input or file to
open, for example), it is assigned the "blocked"
state.
• The process state is changed back to "waiting"
when the process no longer needs to wait (in a
blocked state).
• Once the process finishes execution, or is
terminated by the operating system, it is no
longer needed.
• The process is removed instantly or is moved to
the "terminated" state.
• When removed, it just waits to be removed from
main memory.
• Memory management within an address
space is generally categorized as either
automatic memory management, usually
involving garbage collection, or
manual memory management.
Dynamic memory allocation
Automatic variables
• In many programming language implementations, all
variables declared within a procedure (subroutine, or
function) are local to that function;
• the runtime environment for the program
automatically allocates memory for these variables on
program execution entry to the procedure, and
automatically releases that memory when the
procedure is exited.
Systems with virtual memory
• Virtual memory is a method of decoupling the
memory organization from the physical hardware.
• In computing, virtual memory (also virtual
storage) is a memory management technique
that provides an "idealized abstraction of the
storage resources that are actually available on a
given machine" which "creates the illusion to
users of a very large (main) memory
• Virtual memory
combines active RAM
and inactive memory
on DASD to form a large
range of contiguous
addresses.
• Even though the memory allocated for specific
processes is normally isolated, processes
sometimes need to be able to share
information.
• Shared memory is one of the fastest
techniques for inter-process communication.
• In computer science, shared memory is
memory that may be simultaneously accessed
by multiple programs with an intent to provide
communication among them or avoid
redundant copies.
• Shared memory is an efficient means of passing
data between programs.
• In computer science, shared memory is
memory that may be simultaneously accessed
by multiple programs with an intent to provide
communication among them or avoid
redundant copies.
• Shared memory is an efficient means of
passing data between programs.
• Depending on context, programs may run on a
single processor or on multiple separate
processors.
• An illustration of a shared memory system of
three processors.
• In computer science, inter-process
communication or interprocess
communication (IPC) refers specifically to the
mechanisms an operating system provides to
allow the processes to manage shared data.
• A grid computing
system that
connects many
personal computers
over the Internet via
inter-process
network
communication
Next topic
Week 5-6
• Input/Output at a systems level
• Device drivers
• File systems and directories

You might also like