SlideShare una empresa de Scribd logo
1 de 57
Descargar para leer sin conexión
I. INTRODUCTION
Developing Assembly Language
Programs
Instructions and Directives

  Instructions
   tell processor what to do
   assembled into machine code by
    assembler
   executed at runtime by the processor
   from the Intel x86 instruction set
Instructions and Directives

  Directives
   tell assembler what to do
   commands that are recognized and
    acted upon by the assembler
   not part of the instruction set
   used to declare code and data areas,
    define constants and memory for storage
   different assemblers have different
    directives
Assembler Directives

 EQU directive
  defines constants
    – label   equ value
    – count equ 100

  Data definition directive
   defines memory for data storage
   defines size of data
Assembler Directives

 Initialized Data
  db – define byte
  dw – define word
  dd – define double

   – label       directive   initial value
   – int         db          0
   – num         dw          100
Assembler Directives

 Character constants
  single quote delimited
  ‘A’

   – char   db   ‘!’
Assembler Directives

 String constants
  single quote delimited or sequence of
    characters separated by commas
  each character is one byte each
  ‘hello’
  ‘h’, ’e’, ’l’, ’l’, ’o’

   – prompt1    db    ‘Please enter number: ’
   – prompt2    db    ‘Please enter number: ’,10
Assembler Directives




                       Declarations
Assembler Directives

 Uninitialized Data
  resb – reserve byte
  resw – reserve word
  resd – reserve double word

   – label   directive   value
   – num     resb        1     ; reserves 1 byte
   – nums    resb        10    ; reserves 10 bytes
Assembler Directives




                       Uninitialized
                       variables
Assembly Instructions

 Basic Format
   instruction operand1, operand2

 Operand
  Register
  Immediate
  Memory
Instruction Operands

 Registers
  eax, ax, ah, al
  ebx, bx, bh, bl
  ecx, cx, ch, cl
  edx, dx, dh, dl
Instruction Operands

 Immediate
  character constants
    – character symbols enclosed in quotes
    – character ASCII code
  integer constants
    – begin with a number
    – ends with base modifier (B, O or H)
  ‘A’ = 65 = 41H = 01000001B
Instruction Operands

 Memory
  when using the value of a variable,
   enclose the variable name in square
   brackets
  [num]    -    value of num
  num      -    address of num
Instruction Operands

  If the operands are registers or
   memory locations, they must be of
   the same type.
  Two memory operands are not
   allowed in an instruction.
LABORATORY TOPICS
Basic Input/Output
Basic Input/Output

 Interrupts
  can be a hardware or software interrupt
  the printer is out of paper
    – hardware interrupt
  assembly program issuing a system call
    – software interrupt
 An interrupt simply gets the attention of the
   processor so that it would context switch and
   execute the system's interrupt handler being
   invoked.
Basic Input/Output

 Interrupts
  break the program execution cycle
    (Fetch-Decode-Execute)
  wait for interrupt to be serviced

 Linux services
  int 0x80, int 80H – function calls
INT 80H

 system call numbers for this service are
   placed in EAX

  1 – sys_exit (system exit)
  3 – sys_read (read from standard input)
  4 – sys_write (write to standard output)
INT 80H

   mov eax, 1
   mov ebx, 0
   int 80H


  terminate program
  return 0 at the end of main program (no
   error)
INT 80H

   mov   eax, 3
   mov   ebx, 0
   mov   ecx, <address>
   int   80H


  reads user input
  stores input to a variable referenced by
   address
INT 80H

   mov   eax,   4
   mov   ebx,   1
   mov   ecx,   <string>
   mov   edx,   <length>
   int   80H


  outputs a character/string
  character/string must be in ECX and string
   length must be in EDX before issuing interrupt
Basic Input/Output




                     Instructions
Basic Input/Output
Basic Input/Output
Basic Input/Output
Basic Input/Output
Basic Input/Output
Converting Characters to Numbers

  Input read from the keyboard are ASCII-
   coded characters.
  Output displayed on screen are ASCII-
   coded characters.
  To perform arithmetic, a numeric character
   must be converted from ASCII to its
   equivalent value.
  To print an integer, a number must be
   converted to its equivalent ASCII
   character(s).
Converting Characters to Numbers

 Character to Number:
 section .bss
   num resb 1
 section .text
   mov   eax, 3
   mov   ebx, 0
   mov   ecx, num
   int   80h
Converting Characters to Numbers

 Character to Number:
 section .bss
   num resb 1
 section .text
   mov   eax, 3
   mov   ebx, 0
   mov   ecx, num
   int   80h

   sub [num], 30h
Converting Numbers to Characters

 Number to Character:
 section .text
   mov eax, 4
   mov ebx, 1
   mov ecx, num
   mov edx, 1
   int 80h
Converting Numbers to Characters

 Number to Character:
 section .text
   add [num], 30h

   mov   eax,   4
   mov   ebx,   1
   mov   ecx,   num
   mov   edx,   1
   int   80h
ASCII Table
ASCII Table
Converting Characters to Numbers

 Character to Number:
   mov ecx, num
   int 80h
   sub [num], 30h


   num =   0   0   1   1   0   1   0   0
   30h =   0   0   1   1   0   0   0   0
   num =   0   0   0   0   0   1   0   0
Converting Numbers to Characters

 Number to Character:
   add [num], 30h




   num =   0   0   0   0   0   1   1   0
   30h =   0   0   1   1   0   0   0   0
   num =   0   0   1   1   0   1   1   0
LABORATORY TOPICS
Implementing Sequential
Statements
Assignment Instruction

  mov instruction
     mov destination, source

  mov is a storage command
  copies a value into a location
  destination may be register or memory
  source may be register, memory or
   immediate
  operands should not be both memory
  operands must be of the same size
Simple Instructions

   inc destination
    – increase destination by 1
   dec destination
    – decrease destination by 1
   neg destination
    – negate destination (2’s complement)


   destination may be a register or a memory
Add and Sub Instructions

  add destination, source
      destination = destination + source
  sub destination, source
      destination = destination – source

  same restrictions as the mov instruction
Multiplication

   mul source
   Source is the multiplier

   Source may be a register or memory
   If source is byte-size then
               AX = AL * source
   If source is word-size then
               DX:AX = AX * source
   If source is double word-size then
               EDX:EAX = EAX * source
Multiplication

   mov al, 2
   mov [num], 80H
   mul byte [num]
Multiplication

    mov al, 2
    mov [num], 80H
    mul byte [num]

   This results in AX = 2 * 128 = 256 = 0100 H
Multiplication

    mov al, 2
    mov [num], 80H
    mul byte [num]

   This results in AX = 2 * 128 = 256 = 0100 H
   In Binary, AX = 0000000100000000 B
Multiplication

    mov al, 2
    mov [num], 80H
    mul byte [num]

   This results in AX = 2 * 128 = 256 = 0100 H
   In Binary, AX = 0000000100000000 B
   So, AH = 1 and AL = 0.
Multiplication
    mov ax, 2
    mov [num], 65535
    mul word [num]


   This results in 2 * 65535 = 131070
                              = 0001FFFE H.
   DX = 1 and AX = FFFE H
   Only when taken together will one get the
    correct product.
Division

     div source
     Source is the divisor
     Source may be a register or memory
     If source is byte-size then
                  AH = AX mod source
                  AL = AX div source
Division

   If source is word-size then
                DX = DX:AX mod source
                AX = DX:AX div source
   If source is double word-size then
                EDX = EDX:EAX mod source
                EAX = EDX:EAX div source
   div == integer division
   mod == modulus operation (remainder)
Division (Divide word by byte)

   mov ax, 257
   mov [num], 2
   div byte [num]
Division (Divide word by byte)

   mov ax, 257
   mov [num], 2
   div byte [num]



  This results in AH = 1 and AL = 128
Division (Divide byte by byte)

   mov   [num], 129
   mov   al, [num]
   mov   ah, 0
   mov   [num], 2
   div   byte [num]
Division (Divide byte by byte)

   mov   [num], 129
   mov   al, [num]
   mov   ah, 0
   mov   [num], 2
   div   byte [num]


  AX = 129 since AH = 0 and AL = 129
Division (Divide byte by byte)

   mov   [num], 129
   mov   al, [num]
   mov   ah, 0
   mov   [num], 2
   div   byte [num]


  AX = 129 since AH = 0 and AL = 129
  This results in AH = 1 and AL = 64
Division (Divide word by word)

   mov   dx, 0
   mov   ax, 65535
   mov   [num], 32767
   div   word [num]

  DX:AX = 65535
  num = 32767
  This results in DX = 1 and AX = 2.
Division (Divide word by word)

   mov   dx, 1
   mov   ax, 65535
   mov   [num], 65535
   div   word [num]

  Taken together the values in DX and AX is 131071.
  This is divided by 65535.
  The results are in DX = 1 and in AX = 2.
Divide Overflow Error

   mov ax, 65535
   mov [num], 2
   div byte [num]

  Dividing 65535 by 2 results in a quotient of
   32767 with a remainder of 1.
  The value 32767 will not fit in AL, the destination
   of the quotient, thus resulting in an error.

Más contenido relacionado

La actualidad más candente

String in c programming
String in c programmingString in c programming
String in c programmingDevan Thakur
 
Handling of character strings C programming
Handling of character strings C programmingHandling of character strings C programming
Handling of character strings C programmingAppili Vamsi Krishna
 
String Handling in c++
String Handling in c++String Handling in c++
String Handling in c++Fahim Adil
 
Pointers & References in C++
Pointers & References in C++Pointers & References in C++
Pointers & References in C++Ilio Catallo
 
SAE: Structured Aspect Extraction
SAE: Structured Aspect ExtractionSAE: Structured Aspect Extraction
SAE: Structured Aspect ExtractionGiorgio Orsi
 
Functional programming in ruby
Functional programming in rubyFunctional programming in ruby
Functional programming in rubyKoen Handekyn
 
Creating Domain Specific Languages in Python
Creating Domain Specific Languages in PythonCreating Domain Specific Languages in Python
Creating Domain Specific Languages in PythonSiddhi
 
Advanced Python, Part 2
Advanced Python, Part 2Advanced Python, Part 2
Advanced Python, Part 2Zaar Hai
 
Learning C++ - Pointers in c++ 2
Learning C++ - Pointers in c++ 2Learning C++ - Pointers in c++ 2
Learning C++ - Pointers in c++ 2Ali Aminian
 
Manipulating strings
Manipulating stringsManipulating strings
Manipulating stringsJancypriya M
 

La actualidad más candente (20)

String in c programming
String in c programmingString in c programming
String in c programming
 
Handling of character strings C programming
Handling of character strings C programmingHandling of character strings C programming
Handling of character strings C programming
 
The string class
The string classThe string class
The string class
 
Advanced C - Part 3
Advanced C - Part 3Advanced C - Part 3
Advanced C - Part 3
 
String Handling in c++
String Handling in c++String Handling in c++
String Handling in c++
 
Savitch ch 022
Savitch ch 022Savitch ch 022
Savitch ch 022
 
Strings
StringsStrings
Strings
 
Pointers & References in C++
Pointers & References in C++Pointers & References in C++
Pointers & References in C++
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
C++ string
C++ stringC++ string
C++ string
 
String C Programming
String C ProgrammingString C Programming
String C Programming
 
SAE: Structured Aspect Extraction
SAE: Structured Aspect ExtractionSAE: Structured Aspect Extraction
SAE: Structured Aspect Extraction
 
05 c++-strings
05 c++-strings05 c++-strings
05 c++-strings
 
Functional programming in ruby
Functional programming in rubyFunctional programming in ruby
Functional programming in ruby
 
Pointer
PointerPointer
Pointer
 
Creating Domain Specific Languages in Python
Creating Domain Specific Languages in PythonCreating Domain Specific Languages in Python
Creating Domain Specific Languages in Python
 
String in c
String in cString in c
String in c
 
Advanced Python, Part 2
Advanced Python, Part 2Advanced Python, Part 2
Advanced Python, Part 2
 
Learning C++ - Pointers in c++ 2
Learning C++ - Pointers in c++ 2Learning C++ - Pointers in c++ 2
Learning C++ - Pointers in c++ 2
 
Manipulating strings
Manipulating stringsManipulating strings
Manipulating strings
 

Destacado

N_Asm Assembly macros (sol)
N_Asm Assembly macros (sol)N_Asm Assembly macros (sol)
N_Asm Assembly macros (sol)Selomon birhane
 
Computer instruction
Computer instructionComputer instruction
Computer instructionSanjeev Patel
 
instruction set of 8086
instruction set of 8086instruction set of 8086
instruction set of 8086muneer.k
 
Time delay programs and assembler directives 8086
Time delay programs and assembler directives 8086Time delay programs and assembler directives 8086
Time delay programs and assembler directives 8086Dheeraj Suri
 
Instruction cycle
Instruction cycleInstruction cycle
Instruction cycleKumar
 
Assembly Language Lecture 5
Assembly Language Lecture 5Assembly Language Lecture 5
Assembly Language Lecture 5Motaz Saad
 
Computer instructions
Computer instructionsComputer instructions
Computer instructionsAnuj Modi
 
Types of instructions
Types of instructionsTypes of instructions
Types of instructionsihsanjamil
 
Chapter 3 INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMING
Chapter 3 INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMINGChapter 3 INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMING
Chapter 3 INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMINGFrankie Jones
 
Assembly Language Programming Of 8085
Assembly Language Programming Of 8085Assembly Language Programming Of 8085
Assembly Language Programming Of 8085techbed
 

Destacado (13)

Chapter4.7-mikroprocessor
Chapter4.7-mikroprocessorChapter4.7-mikroprocessor
Chapter4.7-mikroprocessor
 
N_Asm Assembly macros (sol)
N_Asm Assembly macros (sol)N_Asm Assembly macros (sol)
N_Asm Assembly macros (sol)
 
It322 intro 3
It322 intro 3It322 intro 3
It322 intro 3
 
Chapter2d
Chapter2dChapter2d
Chapter2d
 
Computer instruction
Computer instructionComputer instruction
Computer instruction
 
instruction set of 8086
instruction set of 8086instruction set of 8086
instruction set of 8086
 
Time delay programs and assembler directives 8086
Time delay programs and assembler directives 8086Time delay programs and assembler directives 8086
Time delay programs and assembler directives 8086
 
Instruction cycle
Instruction cycleInstruction cycle
Instruction cycle
 
Assembly Language Lecture 5
Assembly Language Lecture 5Assembly Language Lecture 5
Assembly Language Lecture 5
 
Computer instructions
Computer instructionsComputer instructions
Computer instructions
 
Types of instructions
Types of instructionsTypes of instructions
Types of instructions
 
Chapter 3 INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMING
Chapter 3 INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMINGChapter 3 INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMING
Chapter 3 INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMING
 
Assembly Language Programming Of 8085
Assembly Language Programming Of 8085Assembly Language Programming Of 8085
Assembly Language Programming Of 8085
 

Similar a Chapter1c

N_Asm Assembly arithmetic instructions (sol)
N_Asm Assembly arithmetic instructions (sol)N_Asm Assembly arithmetic instructions (sol)
N_Asm Assembly arithmetic instructions (sol)Selomon birhane
 
6_2018_11_23!09_24_56_PM (1).pptx
6_2018_11_23!09_24_56_PM (1).pptx6_2018_11_23!09_24_56_PM (1).pptx
6_2018_11_23!09_24_56_PM (1).pptxHebaEng
 
Arrays and addressing modes
Arrays and addressing modesArrays and addressing modes
Arrays and addressing modesBilal Amjad
 
Creating a Fibonacci Generator in Assembly - by Willem van Ketwich
Creating a Fibonacci Generator in Assembly - by Willem van KetwichCreating a Fibonacci Generator in Assembly - by Willem van Ketwich
Creating a Fibonacci Generator in Assembly - by Willem van KetwichWillem van Ketwich
 
Topic 6 - Programming in Assembly Language_230517_115118.pdf
Topic 6 - Programming in Assembly Language_230517_115118.pdfTopic 6 - Programming in Assembly Language_230517_115118.pdf
Topic 6 - Programming in Assembly Language_230517_115118.pdfezaldeen2013
 
Instruction Set of 8086 Microprocessor
Instruction Set of 8086 MicroprocessorInstruction Set of 8086 Microprocessor
Instruction Set of 8086 MicroprocessorAshita Agrawal
 
system software 16 marks
system software 16 markssystem software 16 marks
system software 16 marksvvcetit
 
Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086Shehrevar Davierwala
 
Advanced procedures in assembly language Full chapter ppt
Advanced procedures in assembly language Full chapter pptAdvanced procedures in assembly language Full chapter ppt
Advanced procedures in assembly language Full chapter pptMuhammad Sikandar Mustafa
 
Lecture 2 coal sping12
Lecture 2 coal sping12Lecture 2 coal sping12
Lecture 2 coal sping12Rabia Khalid
 

Similar a Chapter1c (20)

[ASM]Lab4
[ASM]Lab4[ASM]Lab4
[ASM]Lab4
 
Al2ed chapter4
Al2ed chapter4Al2ed chapter4
Al2ed chapter4
 
N_Asm Assembly arithmetic instructions (sol)
N_Asm Assembly arithmetic instructions (sol)N_Asm Assembly arithmetic instructions (sol)
N_Asm Assembly arithmetic instructions (sol)
 
6_2018_11_23!09_24_56_PM (1).pptx
6_2018_11_23!09_24_56_PM (1).pptx6_2018_11_23!09_24_56_PM (1).pptx
6_2018_11_23!09_24_56_PM (1).pptx
 
Arrays and addressing modes
Arrays and addressing modesArrays and addressing modes
Arrays and addressing modes
 
Wk1to4
Wk1to4Wk1to4
Wk1to4
 
[ASM]Lab8
[ASM]Lab8[ASM]Lab8
[ASM]Lab8
 
Creating a Fibonacci Generator in Assembly - by Willem van Ketwich
Creating a Fibonacci Generator in Assembly - by Willem van KetwichCreating a Fibonacci Generator in Assembly - by Willem van Ketwich
Creating a Fibonacci Generator in Assembly - by Willem van Ketwich
 
Topic 6 - Programming in Assembly Language_230517_115118.pdf
Topic 6 - Programming in Assembly Language_230517_115118.pdfTopic 6 - Programming in Assembly Language_230517_115118.pdf
Topic 6 - Programming in Assembly Language_230517_115118.pdf
 
Instruction set
Instruction setInstruction set
Instruction set
 
Instruction Set of 8086 Microprocessor
Instruction Set of 8086 MicroprocessorInstruction Set of 8086 Microprocessor
Instruction Set of 8086 Microprocessor
 
scripting in Python
scripting in Pythonscripting in Python
scripting in Python
 
system software 16 marks
system software 16 markssystem software 16 marks
system software 16 marks
 
Programming in C.pptx
Programming in C.pptxProgramming in C.pptx
Programming in C.pptx
 
Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086
 
Exp 03
Exp 03Exp 03
Exp 03
 
[ASM]Lab7
[ASM]Lab7[ASM]Lab7
[ASM]Lab7
 
X86 operation types
X86 operation typesX86 operation types
X86 operation types
 
Advanced procedures in assembly language Full chapter ppt
Advanced procedures in assembly language Full chapter pptAdvanced procedures in assembly language Full chapter ppt
Advanced procedures in assembly language Full chapter ppt
 
Lecture 2 coal sping12
Lecture 2 coal sping12Lecture 2 coal sping12
Lecture 2 coal sping12
 

Más de MaeEstherMaguadMaralit (14)

Chapter2c
Chapter2cChapter2c
Chapter2c
 
Chapter2b
Chapter2bChapter2b
Chapter2b
 
Chapter2a
Chapter2aChapter2a
Chapter2a
 
Chapter1b
Chapter1bChapter1b
Chapter1b
 
Chapter1a
Chapter1aChapter1a
Chapter1a
 
linked list (CMSC 123)
linked list (CMSC 123)linked list (CMSC 123)
linked list (CMSC 123)
 
HTTP
HTTPHTTP
HTTP
 
The lovedare
The lovedareThe lovedare
The lovedare
 
Cmsc 100 (web content)
Cmsc 100  (web content)Cmsc 100  (web content)
Cmsc 100 (web content)
 
Cmsc 100 (web forms)
Cmsc 100 (web forms)Cmsc 100 (web forms)
Cmsc 100 (web forms)
 
Cmsc 100 xhtml and css
Cmsc 100 xhtml and cssCmsc 100 xhtml and css
Cmsc 100 xhtml and css
 
Cmsc 100 (web programming in a nutshell)
Cmsc 100 (web programming in a nutshell)Cmsc 100 (web programming in a nutshell)
Cmsc 100 (web programming in a nutshell)
 
Chapter2a
Chapter2aChapter2a
Chapter2a
 
Chapter1b
Chapter1bChapter1b
Chapter1b
 

Último

Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 

Último (20)

Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 

Chapter1c

  • 2. Instructions and Directives Instructions  tell processor what to do  assembled into machine code by assembler  executed at runtime by the processor  from the Intel x86 instruction set
  • 3. Instructions and Directives Directives  tell assembler what to do  commands that are recognized and acted upon by the assembler  not part of the instruction set  used to declare code and data areas, define constants and memory for storage  different assemblers have different directives
  • 4. Assembler Directives EQU directive  defines constants – label equ value – count equ 100 Data definition directive  defines memory for data storage  defines size of data
  • 5. Assembler Directives Initialized Data  db – define byte  dw – define word  dd – define double – label directive initial value – int db 0 – num dw 100
  • 6. Assembler Directives Character constants  single quote delimited  ‘A’ – char db ‘!’
  • 7. Assembler Directives String constants  single quote delimited or sequence of characters separated by commas  each character is one byte each  ‘hello’  ‘h’, ’e’, ’l’, ’l’, ’o’ – prompt1 db ‘Please enter number: ’ – prompt2 db ‘Please enter number: ’,10
  • 8. Assembler Directives Declarations
  • 9. Assembler Directives Uninitialized Data  resb – reserve byte  resw – reserve word  resd – reserve double word – label directive value – num resb 1 ; reserves 1 byte – nums resb 10 ; reserves 10 bytes
  • 10. Assembler Directives Uninitialized variables
  • 11. Assembly Instructions Basic Format instruction operand1, operand2 Operand  Register  Immediate  Memory
  • 12. Instruction Operands Registers  eax, ax, ah, al  ebx, bx, bh, bl  ecx, cx, ch, cl  edx, dx, dh, dl
  • 13. Instruction Operands Immediate  character constants – character symbols enclosed in quotes – character ASCII code  integer constants – begin with a number – ends with base modifier (B, O or H)  ‘A’ = 65 = 41H = 01000001B
  • 14. Instruction Operands Memory  when using the value of a variable, enclose the variable name in square brackets  [num] - value of num  num - address of num
  • 15. Instruction Operands  If the operands are registers or memory locations, they must be of the same type.  Two memory operands are not allowed in an instruction.
  • 17. Basic Input/Output Interrupts  can be a hardware or software interrupt  the printer is out of paper – hardware interrupt  assembly program issuing a system call – software interrupt An interrupt simply gets the attention of the processor so that it would context switch and execute the system's interrupt handler being invoked.
  • 18. Basic Input/Output Interrupts  break the program execution cycle (Fetch-Decode-Execute)  wait for interrupt to be serviced Linux services  int 0x80, int 80H – function calls
  • 19. INT 80H system call numbers for this service are placed in EAX  1 – sys_exit (system exit)  3 – sys_read (read from standard input)  4 – sys_write (write to standard output)
  • 20. INT 80H mov eax, 1 mov ebx, 0 int 80H  terminate program  return 0 at the end of main program (no error)
  • 21. INT 80H mov eax, 3 mov ebx, 0 mov ecx, <address> int 80H  reads user input  stores input to a variable referenced by address
  • 22. INT 80H mov eax, 4 mov ebx, 1 mov ecx, <string> mov edx, <length> int 80H  outputs a character/string  character/string must be in ECX and string length must be in EDX before issuing interrupt
  • 23. Basic Input/Output Instructions
  • 29. Converting Characters to Numbers  Input read from the keyboard are ASCII- coded characters.  Output displayed on screen are ASCII- coded characters.  To perform arithmetic, a numeric character must be converted from ASCII to its equivalent value.  To print an integer, a number must be converted to its equivalent ASCII character(s).
  • 30. Converting Characters to Numbers Character to Number: section .bss num resb 1 section .text mov eax, 3 mov ebx, 0 mov ecx, num int 80h
  • 31. Converting Characters to Numbers Character to Number: section .bss num resb 1 section .text mov eax, 3 mov ebx, 0 mov ecx, num int 80h sub [num], 30h
  • 32. Converting Numbers to Characters Number to Character: section .text mov eax, 4 mov ebx, 1 mov ecx, num mov edx, 1 int 80h
  • 33. Converting Numbers to Characters Number to Character: section .text add [num], 30h mov eax, 4 mov ebx, 1 mov ecx, num mov edx, 1 int 80h
  • 36. Converting Characters to Numbers Character to Number: mov ecx, num int 80h sub [num], 30h num = 0 0 1 1 0 1 0 0 30h = 0 0 1 1 0 0 0 0 num = 0 0 0 0 0 1 0 0
  • 37. Converting Numbers to Characters Number to Character: add [num], 30h num = 0 0 0 0 0 1 1 0 30h = 0 0 1 1 0 0 0 0 num = 0 0 1 1 0 1 1 0
  • 39. Assignment Instruction  mov instruction mov destination, source  mov is a storage command  copies a value into a location  destination may be register or memory  source may be register, memory or immediate  operands should not be both memory  operands must be of the same size
  • 40. Simple Instructions  inc destination – increase destination by 1  dec destination – decrease destination by 1  neg destination – negate destination (2’s complement)  destination may be a register or a memory
  • 41. Add and Sub Instructions  add destination, source destination = destination + source  sub destination, source destination = destination – source  same restrictions as the mov instruction
  • 42. Multiplication  mul source  Source is the multiplier  Source may be a register or memory  If source is byte-size then AX = AL * source  If source is word-size then DX:AX = AX * source  If source is double word-size then EDX:EAX = EAX * source
  • 43. Multiplication mov al, 2 mov [num], 80H mul byte [num]
  • 44. Multiplication mov al, 2 mov [num], 80H mul byte [num]  This results in AX = 2 * 128 = 256 = 0100 H
  • 45. Multiplication mov al, 2 mov [num], 80H mul byte [num]  This results in AX = 2 * 128 = 256 = 0100 H  In Binary, AX = 0000000100000000 B
  • 46. Multiplication mov al, 2 mov [num], 80H mul byte [num]  This results in AX = 2 * 128 = 256 = 0100 H  In Binary, AX = 0000000100000000 B  So, AH = 1 and AL = 0.
  • 47. Multiplication mov ax, 2 mov [num], 65535 mul word [num]  This results in 2 * 65535 = 131070 = 0001FFFE H.  DX = 1 and AX = FFFE H  Only when taken together will one get the correct product.
  • 48. Division  div source  Source is the divisor  Source may be a register or memory  If source is byte-size then AH = AX mod source AL = AX div source
  • 49. Division  If source is word-size then DX = DX:AX mod source AX = DX:AX div source  If source is double word-size then EDX = EDX:EAX mod source EAX = EDX:EAX div source  div == integer division  mod == modulus operation (remainder)
  • 50. Division (Divide word by byte) mov ax, 257 mov [num], 2 div byte [num]
  • 51. Division (Divide word by byte) mov ax, 257 mov [num], 2 div byte [num]  This results in AH = 1 and AL = 128
  • 52. Division (Divide byte by byte) mov [num], 129 mov al, [num] mov ah, 0 mov [num], 2 div byte [num]
  • 53. Division (Divide byte by byte) mov [num], 129 mov al, [num] mov ah, 0 mov [num], 2 div byte [num]  AX = 129 since AH = 0 and AL = 129
  • 54. Division (Divide byte by byte) mov [num], 129 mov al, [num] mov ah, 0 mov [num], 2 div byte [num]  AX = 129 since AH = 0 and AL = 129  This results in AH = 1 and AL = 64
  • 55. Division (Divide word by word) mov dx, 0 mov ax, 65535 mov [num], 32767 div word [num]  DX:AX = 65535  num = 32767  This results in DX = 1 and AX = 2.
  • 56. Division (Divide word by word) mov dx, 1 mov ax, 65535 mov [num], 65535 div word [num]  Taken together the values in DX and AX is 131071.  This is divided by 65535.  The results are in DX = 1 and in AX = 2.
  • 57. Divide Overflow Error mov ax, 65535 mov [num], 2 div byte [num]  Dividing 65535 by 2 results in a quotient of 32767 with a remainder of 1.  The value 32767 will not fit in AL, the destination of the quotient, thus resulting in an error.