You are on page 1of 29

Assembly Language

Lecture 1
Outline
n Introduction to the course
q General information

q Syllabus

q Course arrangment

q General rules

n Why Assembly?
n Blast from the past
n Layered Perspective of Computing
n Data Representation
q Base 2, 8, 10, 16 Number systems

n Boolean operations and algebra


Outline
n Introduction to the course
q General information
q Syllabus

q Course arrangment

q General rules

n Blast from the past


n Why Assembly?
n Layered Perspective of Computing
n Data Representation
q Base 2, 8, 10, 16 Number systems

n Boolean operations and algebra


History of Computing
Blast from the past
n Once upon a time

Abacus

• The abacus, also called a counting frame, is a hand-operated calculating


tool of unknown origin used since ancient times, it is traditionally made
with a frame holding wires or rods on which movable beads are placed.
The beads stand for digits, and they are moved as calculations are
performed.
Blast from the past

Slide rule

• A slide rule is a hand-operated mechanical calculator consisting of slidable


rulers for evaluating mathematical operations such as multiplication,
division, roots, logarithms, and trigonometry. It is one of the simplest analog
computers.
Blast from the past cont.2

n 20th Century (Electronic)

Half Adder
Blast from the past cont.2
Vacuum Tube

vacuum tube: is a device that controls electric current flow in a high vacuum
between electrodes to which an electric potential difference has been applied.

https://www.youtube.com/watch?v=nA_tgIygvNo&ab_channel=RobRobinette
Blast from the past cont.3
n Memory ?!!

Punched Card

A punched card is a piece of card stock that stores digital data using punched holes.
Punched cards were once common in data processing and the control of automated
machines.
Blast from the past

n Everything is there now, let’s start to code ?!!!


Intel Machine Language Assembly Language

A1 00000000 mov eax, A


F7 25 00000004
03 05 00000008
= mul B
add eax, C
E8 00500000 call WriteInt

C++ language

cout<<(A*B+C)
Notes
• In the Past, the processor came with a sheet used to learn which code belong to which arithmetic
operation such as: addition, subtraction, and multiplication.

• For example, if we want to add two numbers, we write something like:

add==> 03 000, 001


03 represent the addition operation
000 represent the first number
001 represent the second number

• To perform the multiplication operation, we must use another code, and therefore the sheet must always be
used.

Of course, using sheet with various arithmetic operations is a very difficult thing.

• Example: If we have a memory called eax and a value called A, we use Mov to insert the value A into the eax
memory.

mul is used for multiplication operations


add eax , c: use to add C in memory eax

All these operations can be done and print it by using just one command in C++ programing
Count << (A*B+C)
Outline
n Introduction to the course
q General information
q Syllabus
q Course arrangment
q General rules
n Blast from the past
n Why Assembly?
n Layered Perspective of Computing
n Data Representation
q Base 2, 8, 10, 16 Number systems
n Boolean operations and algebra
Why Assembly

n Communicate with hardware (drivers, embedded


systems)

n Games, Graphics

n Some thing High level programming can’t do


(context switch)

n Better understanding of programming (reverse


engineering)
Outline
n Introduction to the course
q General information
q Syllabus
q Course arrangment
q General rules
n Blast from the past
n Why Assembly?
n Layered Perspective of Computing
n Data Representation
q Base 2, 8, 10, 16 Number systems
n Boolean operations and algebra
Layered Architecture
Computers are complicated

Layers à abstraction (Hiding the complexity of layers below)


We also layer programming languages!

Program execution:
Interpretation

Compilation (Translation)
Every CPU has a built-in interpreter for its own "instruction set"
(ISA, Instruction Set Architecture; the binary language it is
programmed in)
Machine Levels

High Level
Level 4
Language

Level 3 Assembly Language

Instruction Set
Level 2 Architecture (ISA)

Level 1 Digital Logic


C++ Concepts
• Programmer (with an editor)
Visual
Studio
• Produces a CProgram

• C Compiler (translator)
Microsoft C
Compiler • Produces assembly language (object file)

• Microsoft Assembler "MASM" (translator)


• Produces Intel Binary code

• Intel x86 CPU (e.g., Intel Core i5)


x86 • Executes (interprets) Intel Binary Instructions
Notes
• What is a program: The program is a set of instructions located
in a text file that is transformed into assembly language and then
into an object file that contains the machine code by using
assembler.

• When writing any program in the C language, it is saved in a .C


file and can be opened by using editor. Secondly, Compiler: The
Compiler translates the .C file into another language, where the
file is converted to assembly language, then to machine code,
then to exe file.

• Then comes the linker, which links some files and thus turns the
program into an exe file.
Java – Different Concepts

• Programmer
JEdit •Produces a Java Program

•Java Compiler (translator)


Javacc •Produces Java Byte Code (class file)

•JVM (Java Virtual Machine – Interpreter)


Java •Runs the byte code to produce output
Notes
Do all programming languages work the same way as C?

The answer is no. At one of the stages of the C program, the program is
converted into an object file, which contains machine code inside it, and
the machine code is linked to the processor only. This means that if a
compiler is made on the C program inside a device that contains a
processor such as: Intel processor, the C program will work on another
device that contains only Intel processor and will not work on another
operating system such as: Linux or Mac. If we want to run this program
on another operating system such as Linux, we must take the source
code of the C program and complier it again using the existing complier
on the Linux system.
Notes
• To solve this problem, Java program was used, where instead of
converting the program instructions to assembly language. It will be
converted into a class file, and then we can run the program on any
other device or operating system by using Java Virtual Machine.
The Key Concepts
1. A High-Level Language (C, C++, Fortran, Cobol)
High Level
is compiled (translated) into Assembly
Language
Language
Assembly
2. The Assembly Language (for a specific CPU) Language

is assembled into binary machine language Instruction Set


Architecture (ISA)
3. The binary machine language is interpreted by
Digital Logic
one of the CPUs in the computer

4. The CPU (Intel, AMD, etc.) uses digital logic


circuits to do the interpretation and generate
the results
Linking and Loading
n Assembling (running MASM) does not actually create
a program that can be executed …

n There are (at least) 4 basic steps that need to be


performed within the program:
q Assembling – translate code into binary
q Linking – join all the parts together and resolve names
q Loading – move the program into memory
q Execution – run the program
Notes
• Function: is a block of code which only runs when it is
called. You can pass data, known as parameters, into a
function. Functions are used to perform certain actions,
and they are important for reusing code: Define the
code once and use it many times.

Or

• Function: It is a code located in another file, and this


code is repeated more than once, so we put it in a
separate file, and when used, we write only the name of
the function and mention its location.
Notes
#include <stdio.h> Standard input out library
int main() {
int x=5; Translate the instructions into Assembly codes then to
int y= 10 machine code

printf (x+y); printf it’s a Function


Linking will link the machine code comes from
return 0; previous Instractions with machine code for printf
} function and put in exe file

.exe
1. x = 5 counter take the order from memory to processor
2. y = 10 counter take the order from memory to processor
3. x+y counter take the order from memory to processor
Assembly Language

n Designed for a specific family of CPUs (i.e., Intel x86)

n Consists of a mnemonic (simplified command word)


followed by the needed data
q Example: mov eax, A
q Move into register eax the contents of the location called A

n Generally each mnemonic (instruction) is equivalent to


a single binary CPU instruction
Notes
• Uses of assembly language

• Assembly language is still used until now. For example, when


connecting a new piece of hardware, it is defined on your computer
using a driver, which is a program written in C language or Assembly
language.

• Assembly language can also be used to increase game performance by


erasing some unnecessary instructions located in the machine code or
object file.

• It can also be used to solve the problem of requesting the serial number
in some programs by hacking the serial number instructions of these
programs through their object file.
CPU Instruction Set

n Appendix B: (Intel IA-32) we will not cover all

n Varies for each CPU

n Intel machines use an approach known as CISC


q CISC = Complex Instruction Set Computing
q Lots of powerful and complex (but slow) instructions

n Opposite is RISC (Reduced) with only a few very


simple instructions that run fast

You might also like