SlideShare a Scribd company logo
Intro to Assembly
Language
MUHAMMAD TASNIM MOHIUDDIN
LECTURER, CSE, UIU
1
Levels of Programming Languages
1) Machine Language
2) Assembly Language (Low Level Language)
3) High Level Languages
2
Machine Language
 Set of fundamental instructions
 Native to a processor: executed directly by hardware
 Expressed as a pattern of 1’s and 0’s
Here’s what a program-fragment looks like:
10100001 10111100 10010011 00000100
00001000 00000011 00000101 11000000
10010011 00000100 00001000 10100011
11000000 10010100 00000100 00001000
It means: z = x + y;
3
Assembly Language
 One step up from machine language
 Designed for a specific family of processors (different processor groups/family
has different Assembly Language)
 Consists of symbolic instructions directly related to machine language
instructions one-for-one and are assembled into machine language.
 Alphanumeric equivalent of machine language
 Mnemonics more human-oriented than 1’s and 0’s
 Example: for A = A + 4
MOV AX, A
ADD AX, 4
MOV A, AX
4
High Level Languages
 Similar to Natural language.
 Designed to eliminate the technicalities of a particular computer.
 Statements compiled in a high level language typically generate many low-
level instructions.
 Example: C, Java, Python etc
5
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
6
Why Assembly Language?
 Accessibility to system hardware
 Assembly Language is useful for implementing system software
 Also useful for small embedded system applications
 Faster and shorter programs.
 Compilers do not always generate optimum code.
 Resident programs (that reside in memory while other program execute)
and interrupt service routines (that handle input and output) are almost
always develop in Assembly Language.
 Instruction set knowledge is important for machine designers.
 Compiler writers must be familiar with details of machine language.
7
Advantages of Assembly Language
 Shows how program interfaces with the processor, operating system, and
BIOS.
 Shows how data is represented and stored in memory and on external
devices.
 Clarifies how processor accesses and executes instructions and how
instructions access and process data.
8
Assembler
 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
9
Compiler and Assembler 10
Computer Architecture
CPU
I/O Devices
Memory
11
Computer Architecture
Control Bus
CPU Memory I/O
Address Bus
Data Bus
12
Organization of 8086 Processor
 16 bit Processor
 16 bit data bus
 16 bit registers
 20 bit Address bus
13
Organization of 8086 Processor
CPU Memory
Address Bus
Data Bus
20
16
CPU-Memory Interface
16-bit
Control Bus
14
Bytes and Words
 Information processed by computer is stored in its memory
 A memory element can store one bit of data
 Group of 8 bits forms one byte
 Group of 16 bits or 2 bytes forms one word
15
RAM and ROM
 Random-Access Memory (RAM)
 Can be performed read and write operation
 Program instruction and data are loaded into RAM
 Contents are lost when the machine is turned off
 ROM (Read-Only-Memory)
 Once initialized can’t be changed, can only be read
 Retain values event the machine is turned off
 Hence used to store system programs
16
Address Space of 8086 17
Number System
18
Number System
• Consists of TWO Things:
– A BASE or RADIX Value
– A SET of DIGITS
• Digits are symbols representing all values
less than the radix value.
• Example is the Common Decimal System:
– RADIX (BASE) = 10
– Digit Set = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
19
Decimal Number Systems
 Consider: 5032.21
210123
10
)10(1)10(2)10(2)10(3)10(0)10(5
01.02.023005000)21.5032(


5032.21
20
Commonly Occurring Bases
• Binary
– Radix = (2)10
– Digit Set = {0,1}
• Octal
– Radix = (8)10
– Digit Set = {0,1,2,3,4,5,6,7}
• Hexadecimal
– Radix = (16)10
– Digit Set = {0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F}
21
Any Base to Decimal
 A number with radix r is represented by a string of
digits:
An - 1An - 2 … A1A0 . A- 1 A- 2 … A- m  1 A- m
The string of digits represents the power series:
(Number)r
=
 
j = - 1
j
j
i
i = 0
i rArA
(Integer Portion) + (Fractional Portion)
i = n - 1 j = - m
22
Hexadecimal
 16-base number system
 16 symbols (0—9, A, B, C, D, E, F)
 Again radix is power of 2
 4 bits to represent a hexadecimal number
23
Hexadecimal to Binary
Restate the hexadecimal as four binary digits starting
at the radix point and going both ways.
24
Binary to Hexadecimal
Group the binary digits into four bits groups starting at
the radix point and going both ways, padding with
zeros as needed in the fractional part.
Convert each group of three bits to an hexadecimal
digit.
25
Binary to Hexadecimal 26
Binary Negative Numbers
• In decimal we are quite familiar with placing a
“-” sign in front of a number to denote that it is negative
• But for binary numbers a computer won’t understand
that
• What happens in memory then?
27
Binary Negative Numbers
There are several representations
- Signed magnitude
- One’s complement
- Two’s complement
28
Signed Magnitude
 Left bit (MSB) used as the sign bit
29
One’s Complement
 Invert the ones and zeros
30
Subtraction with One's Complement
 Steps for subtracting x from y with an n-bit 1's
complement representation:
 Negate x using 1's complement.
 Add -x and y.
 If the sum exceeds n bits, add the extra bit to the result.
 If the sum does not exceed n bits, leave the result as it is.
The result will be in 1's complement form
31
Example: subtracting 1 from 7 using 1's
complement
First, we need to convert 0001 to its negative equivalent in 1's complement.
Next we perform addition of 7 and our computed 1's complement of -1.
Notice that our addition caused an overflow bit. Whenever we have an overflow
bit in 1's complement, we add this bit to our sum to get the correct answer. If
there is no overflow bit, then we leave the sum as it is.
32
Another Example 33
Two’s Complement
Take 1’s complement then add 1
OR
Toggle all bits to the left of the first ‘1’ from the right
Example:
0 1 0 1 0 0 0 0
1 0 1 1 0 0 0 0
0 1 0 0 1 1 1 1
+ 1
1 0 1 1 0 0 0 0
00001010
34
Two’s Complement 35
Subtraction with Two’s Complement
Steps for subtracting x from y with an n-bit 2's
complement representation:
Negate x using 2's complement.
 Reverse all the bits in x.
 Add 1 to form -x.
Add -x and y.
Discard any bits greater than n.
The result will be in 2's complement form
36
Example: subtracting 1 from 7 using 2's
complement
First, we need to convert 00012 to its negative equivalent in 2's complement.
Next we perform addition of 7 and our computed 2's complement of -1.
Notice that our addition caused an overflow bit. Whenever we have an overflow
bit in 2's complement, we discard the extra bit. This gives us a final answer of
01102 (or 610)
37
Another Example
 1 -7 = 1 + (-7)
0001
+1001
1010
2’s complement of -7
1010 is the 2’s complement of -6
38
Registers of 8086
Intel 8086 contains following registers:
General Purpose Registers
Pointer and Index Registers
Segment Registers
Instruction Pointer
Status Flags
39
General Purpose Registers
There are four 16-bit general purpose registers:
Accumulator Register (AX)
Base Register (BX)
Count Register (CX)
Data Register (DX)
40
Following four 16-bit registers are under this
category:
Stack Pointer (SP)
Base Pointer (BP)
Source Index (SI)
 Destination Index (DI).
Pointer & Index Register 41
Segment Register
There are four 16-bit segment registers in Intel
8086:
 Code Segment Register (CS),
 Data Segment Register (DS),
 Stack Segment Register (SS),
 Extra Segment Register (ES).
42
Rest 2 Registers
Instruction Pointer
Status Flag Register
43
Ad

Recommended

Assembly Language
Assembly Language
Ibrahimcommunication Al Ani
 
Internal memory
Internal memory
Siddique Ibrahim
 
Genetic Algorithm (GA) Optimization - Step-by-Step Example
Genetic Algorithm (GA) Optimization - Step-by-Step Example
Ahmed Gad
 
Introduction to system programming
Introduction to system programming
sonalikharade3
 
Assembly language
Assembly language
shashank puthran
 
E-commerce project in brief pdf
E-commerce project in brief pdf
kapil sharma
 
Interfacing With High Level Programming Language
Interfacing With High Level Programming Language
.AIR UNIVERSITY ISLAMABAD
 
Operating System.pdf
Operating System.pdf
Syed Zaid Irshad
 
Part I:Introduction to assembly language
Part I:Introduction to assembly language
Ahmed M. Abed
 
quine mc cluskey method
quine mc cluskey method
Unsa Shakir
 
Floating point arithmetic operations (1)
Floating point arithmetic operations (1)
cs19club
 
Direct memory access (dma)
Direct memory access (dma)
Zubair Khalid
 
Code Conversion in 8085 Microprocessor
Code Conversion in 8085 Microprocessor
MOHIT AGARWAL
 
Programming with 8085
Programming with 8085
Shehrevar Davierwala
 
Register transfer language
Register transfer language
Sanjeev Patel
 
Addressing modes
Addressing modes
karthiga selvaraju
 
Interfacing memory with 8086 microprocessor
Interfacing memory with 8086 microprocessor
Vikas Gupta
 
Intel 8051 Programming in C
Intel 8051 Programming in C
Sudhanshu Janwadkar
 
Assembly 8086
Assembly 8086
Mustafa Salah
 
Weighted and Non Weighted Codes
Weighted and Non Weighted Codes
SubhamSatpathy2
 
Hamming codes
Hamming codes
GIGI JOSEPH
 
Instruction format
Instruction format
Sanjeev Patel
 
Arithmetic micro operations
Arithmetic micro operations
lavanya marichamy
 
8086 alp
8086 alp
Velalar College of Engineering and Technology
 
List of 8085 programs
List of 8085 programs
ASHOKA INSTITUTE OF TECHNOLOGY & MANAGEMENT,VARANASI,U.P.
 
Multiplexers & Demultiplexers
Multiplexers & Demultiplexers
Jayanshu Gundaniya
 
Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086
Shehrevar Davierwala
 
80286 microprocessor
80286 microprocessor
Avin Mathew
 
Assembly Language Basics
Assembly Language Basics
Education Front
 
Introduction to Assembly Language
Introduction to Assembly Language
Motaz Saad
 

More Related Content

What's hot (20)

Part I:Introduction to assembly language
Part I:Introduction to assembly language
Ahmed M. Abed
 
quine mc cluskey method
quine mc cluskey method
Unsa Shakir
 
Floating point arithmetic operations (1)
Floating point arithmetic operations (1)
cs19club
 
Direct memory access (dma)
Direct memory access (dma)
Zubair Khalid
 
Code Conversion in 8085 Microprocessor
Code Conversion in 8085 Microprocessor
MOHIT AGARWAL
 
Programming with 8085
Programming with 8085
Shehrevar Davierwala
 
Register transfer language
Register transfer language
Sanjeev Patel
 
Addressing modes
Addressing modes
karthiga selvaraju
 
Interfacing memory with 8086 microprocessor
Interfacing memory with 8086 microprocessor
Vikas Gupta
 
Intel 8051 Programming in C
Intel 8051 Programming in C
Sudhanshu Janwadkar
 
Assembly 8086
Assembly 8086
Mustafa Salah
 
Weighted and Non Weighted Codes
Weighted and Non Weighted Codes
SubhamSatpathy2
 
Hamming codes
Hamming codes
GIGI JOSEPH
 
Instruction format
Instruction format
Sanjeev Patel
 
Arithmetic micro operations
Arithmetic micro operations
lavanya marichamy
 
8086 alp
8086 alp
Velalar College of Engineering and Technology
 
List of 8085 programs
List of 8085 programs
ASHOKA INSTITUTE OF TECHNOLOGY & MANAGEMENT,VARANASI,U.P.
 
Multiplexers & Demultiplexers
Multiplexers & Demultiplexers
Jayanshu Gundaniya
 
Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086
Shehrevar Davierwala
 
80286 microprocessor
80286 microprocessor
Avin Mathew
 

Viewers also liked (20)

Assembly Language Basics
Assembly Language Basics
Education Front
 
Introduction to Assembly Language
Introduction to Assembly Language
Motaz Saad
 
Assembly Language -I
Assembly Language -I
Devika Rangnekar
 
Assembly Language Lecture 5
Assembly Language Lecture 5
Motaz Saad
 
Assembly language programming
Assembly language programming
himhk
 
Assembly
Assembly
nick333y
 
.NET Framework Projet with C#
.NET Framework Projet with C#
eclumson
 
Assembly fundamentals
Assembly fundamentals
Syed Zaid Irshad
 
Assembly Language Tanka - SAKAI Hiroaki
Assembly Language Tanka - SAKAI Hiroaki
asmtanka
 
Assembly language part I
Assembly language part I
Mohammed A. Imran
 
Chapt 01 basic concepts
Chapt 01 basic concepts
bushrakainat214
 
Processor Basics
Processor Basics
Education Front
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Bilal Amjad
 
Chapter 1
Chapter 1
Ashhad Kamal
 
Lec 01 basic concepts
Lec 01 basic concepts
Abdul Khan
 
[ASM] Lab1
[ASM] Lab1
Nora Youssef
 
Assembly Language Lecture 4
Assembly Language Lecture 4
Motaz Saad
 
Assembly Language Lecture 2
Assembly Language Lecture 2
Motaz Saad
 
Math Puzzle Game By Assembly Language
Math Puzzle Game By Assembly Language
Sanzid Kawsar
 
Chp6 assembly language programming for pic copy
Chp6 assembly language programming for pic copy
mkazree
 
Assembly Language Basics
Assembly Language Basics
Education Front
 
Introduction to Assembly Language
Introduction to Assembly Language
Motaz Saad
 
Assembly Language Lecture 5
Assembly Language Lecture 5
Motaz Saad
 
Assembly language programming
Assembly language programming
himhk
 
.NET Framework Projet with C#
.NET Framework Projet with C#
eclumson
 
Assembly Language Tanka - SAKAI Hiroaki
Assembly Language Tanka - SAKAI Hiroaki
asmtanka
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Bilal Amjad
 
Lec 01 basic concepts
Lec 01 basic concepts
Abdul Khan
 
Assembly Language Lecture 4
Assembly Language Lecture 4
Motaz Saad
 
Assembly Language Lecture 2
Assembly Language Lecture 2
Motaz Saad
 
Math Puzzle Game By Assembly Language
Math Puzzle Game By Assembly Language
Sanzid Kawsar
 
Chp6 assembly language programming for pic copy
Chp6 assembly language programming for pic copy
mkazree
 
Ad

Similar to Intro to assembly language (20)

Class2
Class2
guest046c293
 
Computer organization and assembly language .pdf
Computer organization and assembly language .pdf
MUhammadMiladAwan
 
Chapter 1SyllabusCatalog Description Computer structu
Chapter 1SyllabusCatalog Description Computer structu
EstelaJeffery653
 
Chapter 2
Chapter 2
douglaslyon
 
COMPUTER ORGANIZATION NOTES Unit 2
COMPUTER ORGANIZATION NOTES Unit 2
Dr.MAYA NAYAK
 
Computer Organization
Computer Organization
Radhika Talaviya
 
Bca 2nd sem-u-3.1-basic computer programming and micro programmed control
Bca 2nd sem-u-3.1-basic computer programming and micro programmed control
Rai University
 
Chapter 2 Part2 A
Chapter 2 Part2 A
ececourse
 
Instruction Set Architecture
Instruction Set Architecture
Dilum Bandara
 
Mca i-u-3-basic computer programming and micro programmed control
Mca i-u-3-basic computer programming and micro programmed control
Rai University
 
basic computer programming and micro programmed control
basic computer programming and micro programmed control
Rai University
 
B.sc cs-ii-u-3.1-basic computer programming and micro programmed control
B.sc cs-ii-u-3.1-basic computer programming and micro programmed control
Rai University
 
Microprocessor chapter 9 - assembly language programming
Microprocessor chapter 9 - assembly language programming
Wondeson Emeye
 
Unit 3 assembler and processor
Unit 3 assembler and processor
Abha Damani
 
Chap 01[1]
Chap 01[1]
Hafiz Muhammad Azeem Sarwar
 
Assembly Language Programming
Assembly Language Programming
Niropam Das
 
microprocesser-140306112352-phpapp01.pdf
microprocesser-140306112352-phpapp01.pdf
PriyankaRana171346
 
Microprocessor and its applications third edition
Microprocessor and its applications third edition
Rizwan Ahmed
 
Unit 2 8086 Instruction set.ppt notes good
Unit 2 8086 Instruction set.ppt notes good
SahilSingh866567
 
chapt_01.ppt
chapt_01.ppt
KakalKsa
 
Computer organization and assembly language .pdf
Computer organization and assembly language .pdf
MUhammadMiladAwan
 
Chapter 1SyllabusCatalog Description Computer structu
Chapter 1SyllabusCatalog Description Computer structu
EstelaJeffery653
 
COMPUTER ORGANIZATION NOTES Unit 2
COMPUTER ORGANIZATION NOTES Unit 2
Dr.MAYA NAYAK
 
Bca 2nd sem-u-3.1-basic computer programming and micro programmed control
Bca 2nd sem-u-3.1-basic computer programming and micro programmed control
Rai University
 
Chapter 2 Part2 A
Chapter 2 Part2 A
ececourse
 
Instruction Set Architecture
Instruction Set Architecture
Dilum Bandara
 
Mca i-u-3-basic computer programming and micro programmed control
Mca i-u-3-basic computer programming and micro programmed control
Rai University
 
basic computer programming and micro programmed control
basic computer programming and micro programmed control
Rai University
 
B.sc cs-ii-u-3.1-basic computer programming and micro programmed control
B.sc cs-ii-u-3.1-basic computer programming and micro programmed control
Rai University
 
Microprocessor chapter 9 - assembly language programming
Microprocessor chapter 9 - assembly language programming
Wondeson Emeye
 
Unit 3 assembler and processor
Unit 3 assembler and processor
Abha Damani
 
Assembly Language Programming
Assembly Language Programming
Niropam Das
 
microprocesser-140306112352-phpapp01.pdf
microprocesser-140306112352-phpapp01.pdf
PriyankaRana171346
 
Microprocessor and its applications third edition
Microprocessor and its applications third edition
Rizwan Ahmed
 
Unit 2 8086 Instruction set.ppt notes good
Unit 2 8086 Instruction set.ppt notes good
SahilSingh866567
 
chapt_01.ppt
chapt_01.ppt
KakalKsa
 
Ad

Recently uploaded (20)

DESIGN OF REINFORCED CONCRETE ELEMENTS S
DESIGN OF REINFORCED CONCRETE ELEMENTS S
prabhusp8
 
Rapid Prototyping for XR: Lecture 3 - Video and Paper Prototyping
Rapid Prototyping for XR: Lecture 3 - Video and Paper Prototyping
Mark Billinghurst
 
20CE404-Soil Mechanics - Slide Share PPT
20CE404-Soil Mechanics - Slide Share PPT
saravananr808639
 
Rapid Prototyping for XR: Lecture 5 - Cross Platform Development
Rapid Prototyping for XR: Lecture 5 - Cross Platform Development
Mark Billinghurst
 
Modern multi-proposer consensus implementations
Modern multi-proposer consensus implementations
François Garillot
 
Tesla-Stock-Analysis-and-Forecast.pptx (1).pptx
Tesla-Stock-Analysis-and-Forecast.pptx (1).pptx
moonsony54
 
Stay Safe Women Security Android App Project Report.pdf
Stay Safe Women Security Android App Project Report.pdf
Kamal Acharya
 
Rapid Prototyping for XR: Lecture 1 Introduction to Prototyping
Rapid Prototyping for XR: Lecture 1 Introduction to Prototyping
Mark Billinghurst
 
May 2025: Top 10 Read Articles in Data Mining & Knowledge Management Process
May 2025: Top 10 Read Articles in Data Mining & Knowledge Management Process
IJDKP
 
How to Un-Obsolete Your Legacy Keypad Design
How to Un-Obsolete Your Legacy Keypad Design
Epec Engineered Technologies
 
Solar thermal – Flat plate and concentrating collectors .pptx
Solar thermal – Flat plate and concentrating collectors .pptx
jdaniabraham1
 
Deep Learning for Natural Language Processing_FDP on 16 June 2025 MITS.pptx
Deep Learning for Natural Language Processing_FDP on 16 June 2025 MITS.pptx
resming1
 
System design handwritten notes guidance
System design handwritten notes guidance
Shabista Imam
 
International Journal of Advanced Information Technology (IJAIT)
International Journal of Advanced Information Technology (IJAIT)
ijait
 
Generative AI & Scientific Research : Catalyst for Innovation, Ethics & Impact
Generative AI & Scientific Research : Catalyst for Innovation, Ethics & Impact
AlqualsaDIResearchGr
 
Fatality due to Falls at Working at Height
Fatality due to Falls at Working at Height
ssuserb8994f
 
special_edition_using_visual_foxpro_6.pdf
special_edition_using_visual_foxpro_6.pdf
Shabista Imam
 
Introduction to Natural Language Processing - Stages in NLP Pipeline, Challen...
Introduction to Natural Language Processing - Stages in NLP Pipeline, Challen...
resming1
 
Structural Wonderers_new and ancient.pptx
Structural Wonderers_new and ancient.pptx
nikopapa113
 
Abraham Silberschatz-Operating System Concepts (9th,2012.12).pdf
Abraham Silberschatz-Operating System Concepts (9th,2012.12).pdf
Shabista Imam
 
DESIGN OF REINFORCED CONCRETE ELEMENTS S
DESIGN OF REINFORCED CONCRETE ELEMENTS S
prabhusp8
 
Rapid Prototyping for XR: Lecture 3 - Video and Paper Prototyping
Rapid Prototyping for XR: Lecture 3 - Video and Paper Prototyping
Mark Billinghurst
 
20CE404-Soil Mechanics - Slide Share PPT
20CE404-Soil Mechanics - Slide Share PPT
saravananr808639
 
Rapid Prototyping for XR: Lecture 5 - Cross Platform Development
Rapid Prototyping for XR: Lecture 5 - Cross Platform Development
Mark Billinghurst
 
Modern multi-proposer consensus implementations
Modern multi-proposer consensus implementations
François Garillot
 
Tesla-Stock-Analysis-and-Forecast.pptx (1).pptx
Tesla-Stock-Analysis-and-Forecast.pptx (1).pptx
moonsony54
 
Stay Safe Women Security Android App Project Report.pdf
Stay Safe Women Security Android App Project Report.pdf
Kamal Acharya
 
Rapid Prototyping for XR: Lecture 1 Introduction to Prototyping
Rapid Prototyping for XR: Lecture 1 Introduction to Prototyping
Mark Billinghurst
 
May 2025: Top 10 Read Articles in Data Mining & Knowledge Management Process
May 2025: Top 10 Read Articles in Data Mining & Knowledge Management Process
IJDKP
 
Solar thermal – Flat plate and concentrating collectors .pptx
Solar thermal – Flat plate and concentrating collectors .pptx
jdaniabraham1
 
Deep Learning for Natural Language Processing_FDP on 16 June 2025 MITS.pptx
Deep Learning for Natural Language Processing_FDP on 16 June 2025 MITS.pptx
resming1
 
System design handwritten notes guidance
System design handwritten notes guidance
Shabista Imam
 
International Journal of Advanced Information Technology (IJAIT)
International Journal of Advanced Information Technology (IJAIT)
ijait
 
Generative AI & Scientific Research : Catalyst for Innovation, Ethics & Impact
Generative AI & Scientific Research : Catalyst for Innovation, Ethics & Impact
AlqualsaDIResearchGr
 
Fatality due to Falls at Working at Height
Fatality due to Falls at Working at Height
ssuserb8994f
 
special_edition_using_visual_foxpro_6.pdf
special_edition_using_visual_foxpro_6.pdf
Shabista Imam
 
Introduction to Natural Language Processing - Stages in NLP Pipeline, Challen...
Introduction to Natural Language Processing - Stages in NLP Pipeline, Challen...
resming1
 
Structural Wonderers_new and ancient.pptx
Structural Wonderers_new and ancient.pptx
nikopapa113
 
Abraham Silberschatz-Operating System Concepts (9th,2012.12).pdf
Abraham Silberschatz-Operating System Concepts (9th,2012.12).pdf
Shabista Imam
 

Intro to assembly language

  • 1. Intro to Assembly Language MUHAMMAD TASNIM MOHIUDDIN LECTURER, CSE, UIU 1
  • 2. Levels of Programming Languages 1) Machine Language 2) Assembly Language (Low Level Language) 3) High Level Languages 2
  • 3. Machine Language  Set of fundamental instructions  Native to a processor: executed directly by hardware  Expressed as a pattern of 1’s and 0’s Here’s what a program-fragment looks like: 10100001 10111100 10010011 00000100 00001000 00000011 00000101 11000000 10010011 00000100 00001000 10100011 11000000 10010100 00000100 00001000 It means: z = x + y; 3
  • 4. Assembly Language  One step up from machine language  Designed for a specific family of processors (different processor groups/family has different Assembly Language)  Consists of symbolic instructions directly related to machine language instructions one-for-one and are assembled into machine language.  Alphanumeric equivalent of machine language  Mnemonics more human-oriented than 1’s and 0’s  Example: for A = A + 4 MOV AX, A ADD AX, 4 MOV A, AX 4
  • 5. High Level Languages  Similar to Natural language.  Designed to eliminate the technicalities of a particular computer.  Statements compiled in a high level language typically generate many low- level instructions.  Example: C, Java, Python etc 5
  • 6. 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 6
  • 7. Why Assembly Language?  Accessibility to system hardware  Assembly Language is useful for implementing system software  Also useful for small embedded system applications  Faster and shorter programs.  Compilers do not always generate optimum code.  Resident programs (that reside in memory while other program execute) and interrupt service routines (that handle input and output) are almost always develop in Assembly Language.  Instruction set knowledge is important for machine designers.  Compiler writers must be familiar with details of machine language. 7
  • 8. Advantages of Assembly Language  Shows how program interfaces with the processor, operating system, and BIOS.  Shows how data is represented and stored in memory and on external devices.  Clarifies how processor accesses and executes instructions and how instructions access and process data. 8
  • 9. Assembler  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 9
  • 12. Computer Architecture Control Bus CPU Memory I/O Address Bus Data Bus 12
  • 13. Organization of 8086 Processor  16 bit Processor  16 bit data bus  16 bit registers  20 bit Address bus 13
  • 14. Organization of 8086 Processor CPU Memory Address Bus Data Bus 20 16 CPU-Memory Interface 16-bit Control Bus 14
  • 15. Bytes and Words  Information processed by computer is stored in its memory  A memory element can store one bit of data  Group of 8 bits forms one byte  Group of 16 bits or 2 bytes forms one word 15
  • 16. RAM and ROM  Random-Access Memory (RAM)  Can be performed read and write operation  Program instruction and data are loaded into RAM  Contents are lost when the machine is turned off  ROM (Read-Only-Memory)  Once initialized can’t be changed, can only be read  Retain values event the machine is turned off  Hence used to store system programs 16
  • 17. Address Space of 8086 17
  • 19. Number System • Consists of TWO Things: – A BASE or RADIX Value – A SET of DIGITS • Digits are symbols representing all values less than the radix value. • Example is the Common Decimal System: – RADIX (BASE) = 10 – Digit Set = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} 19
  • 20. Decimal Number Systems  Consider: 5032.21 210123 10 )10(1)10(2)10(2)10(3)10(0)10(5 01.02.023005000)21.5032(   5032.21 20
  • 21. Commonly Occurring Bases • Binary – Radix = (2)10 – Digit Set = {0,1} • Octal – Radix = (8)10 – Digit Set = {0,1,2,3,4,5,6,7} • Hexadecimal – Radix = (16)10 – Digit Set = {0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F} 21
  • 22. Any Base to Decimal  A number with radix r is represented by a string of digits: An - 1An - 2 … A1A0 . A- 1 A- 2 … A- m  1 A- m The string of digits represents the power series: (Number)r =   j = - 1 j j i i = 0 i rArA (Integer Portion) + (Fractional Portion) i = n - 1 j = - m 22
  • 23. Hexadecimal  16-base number system  16 symbols (0—9, A, B, C, D, E, F)  Again radix is power of 2  4 bits to represent a hexadecimal number 23
  • 24. Hexadecimal to Binary Restate the hexadecimal as four binary digits starting at the radix point and going both ways. 24
  • 25. Binary to Hexadecimal Group the binary digits into four bits groups starting at the radix point and going both ways, padding with zeros as needed in the fractional part. Convert each group of three bits to an hexadecimal digit. 25
  • 27. Binary Negative Numbers • In decimal we are quite familiar with placing a “-” sign in front of a number to denote that it is negative • But for binary numbers a computer won’t understand that • What happens in memory then? 27
  • 28. Binary Negative Numbers There are several representations - Signed magnitude - One’s complement - Two’s complement 28
  • 29. Signed Magnitude  Left bit (MSB) used as the sign bit 29
  • 30. One’s Complement  Invert the ones and zeros 30
  • 31. Subtraction with One's Complement  Steps for subtracting x from y with an n-bit 1's complement representation:  Negate x using 1's complement.  Add -x and y.  If the sum exceeds n bits, add the extra bit to the result.  If the sum does not exceed n bits, leave the result as it is. The result will be in 1's complement form 31
  • 32. Example: subtracting 1 from 7 using 1's complement First, we need to convert 0001 to its negative equivalent in 1's complement. Next we perform addition of 7 and our computed 1's complement of -1. Notice that our addition caused an overflow bit. Whenever we have an overflow bit in 1's complement, we add this bit to our sum to get the correct answer. If there is no overflow bit, then we leave the sum as it is. 32
  • 34. Two’s Complement Take 1’s complement then add 1 OR Toggle all bits to the left of the first ‘1’ from the right Example: 0 1 0 1 0 0 0 0 1 0 1 1 0 0 0 0 0 1 0 0 1 1 1 1 + 1 1 0 1 1 0 0 0 0 00001010 34
  • 36. Subtraction with Two’s Complement Steps for subtracting x from y with an n-bit 2's complement representation: Negate x using 2's complement.  Reverse all the bits in x.  Add 1 to form -x. Add -x and y. Discard any bits greater than n. The result will be in 2's complement form 36
  • 37. Example: subtracting 1 from 7 using 2's complement First, we need to convert 00012 to its negative equivalent in 2's complement. Next we perform addition of 7 and our computed 2's complement of -1. Notice that our addition caused an overflow bit. Whenever we have an overflow bit in 2's complement, we discard the extra bit. This gives us a final answer of 01102 (or 610) 37
  • 38. Another Example  1 -7 = 1 + (-7) 0001 +1001 1010 2’s complement of -7 1010 is the 2’s complement of -6 38
  • 39. Registers of 8086 Intel 8086 contains following registers: General Purpose Registers Pointer and Index Registers Segment Registers Instruction Pointer Status Flags 39
  • 40. General Purpose Registers There are four 16-bit general purpose registers: Accumulator Register (AX) Base Register (BX) Count Register (CX) Data Register (DX) 40
  • 41. Following four 16-bit registers are under this category: Stack Pointer (SP) Base Pointer (BP) Source Index (SI)  Destination Index (DI). Pointer & Index Register 41
  • 42. Segment Register There are four 16-bit segment registers in Intel 8086:  Code Segment Register (CS),  Data Segment Register (DS),  Stack Segment Register (SS),  Extra Segment Register (ES). 42
  • 43. Rest 2 Registers Instruction Pointer Status Flag Register 43