SlideShare ist ein Scribd-Unternehmen logo
1 von 26
Downloaden Sie, um offline zu lesen
Group Activity

 1. printf(“%c”,x);

 2. sum = x + y;

 3. prod = x * y;

    (assume x and y are byte-size variables)
Group Activity

 1. printf(“%c”,x);




                  mov eax, 4
                  mov ebx, 1
                  mov ecx, x
                  mov edx, 1
                  int 80h
Group Activity

 2. sum = x + y;




                   mov bl, [x]
                   add bl, [y]
                   mov [sum], bl
Group Activity

 3. prod = x * y;




                    mov al, [x]
                    mul byte[y]
                    mov [prod], ax
Structured Assembly Language
Programming Techniques
Control Transfer Instructions
Control Transfer Instructions

   allows program control to transfer to
    specified label
   Unconditional or Conditional
   Unconditional
     – executed without regards to any situation
       or condition in the program
     – transfer of control goes from one code to
       another by force
          jmp label – unconditional jump
Control Transfer Instructions


   mov al, 5       next:
   add [num1],al
                   mov eax, 4
   jmp next
                   mov ebx, 1
                   mov ecx, num2
   mov eax, 4      mov edx, 1
   mov ebx, 1      int 80h
   mov ecx, num1
   mov edx, 1
   int 80h
       (1)                 (2)
Control Transfer Instructions

   Conditional
    – a jump carried out on the basis of a
      truth value
    – the information on which such
      decisions are based is contained in
      the flags registers
Boolean Expressions

  evaluates to True or False
  compares two values

  cmp source1, source2
  Source1 may be a register or memory
  Source2 may be a register, memory or
   immediate
  Operands cannot be both memory.
  Operands must be of the same size.
Conditional Jumps

  usually placed after a cmp instruction
    conditional_jump label



  JE – branches if source1 == source2
  JNE – branches if source1 ≠ source2
Conditional Jumps

  Signed Conditional Jump
   – JL or JNGE
       branches if source1 < source2
   – JLE or JNG
       branches if source1 ≤ source2
   – JG or JNLE
       branches if source1 > source2
   – JGE or JNL
       branches if source1 ≥ source2
Conditional Jumps

  Unsigned Conditional Jumps
   – JB or JNAE
       branches if source1 < source2
   – JBE or JNA
       branches if source1 ≤ source2
   – JA or JNBE
       branches if source1 > source2
   – JAE or JNB
       branches if source1 ≥ source2
Signed or Unsigned

   mov al, FFh     1    1   1   1   1   1   1   1

   cmp al, 10
   jb label



    FFh == 255
    will not jump to
     label
Signed or Unsigned

   mov al, FFh      1   1   1   1   1   1   1   1

   cmp al, 10
   jl label         -   0   0   0   0   0   0   1




    FFh == -1
    will jump to label
Control Structure: IF Statement

 if (boolean)       cmp AX, CX
    {statements;}   jg if_statement
                    jmp next_statement
 if(AX>CX){
    BX = DX + 2;    if_statement:
 }                     add DX, 2
                       mov BX, DX
                    next_statement:
                       ...
Better Design: Save on Jumps

 cmp AX, CX           cmp AX, CX
 jg if_statement      jng next_statement
 jmp next_statement

 if_statement:        if_statement:
    add DX, 2            add DX, 2
    mov BX, DX           mov BX, DX
 next_statement:      next_statement:
    ...                  ...
Control Structure: IF-ELSE Statement

  if (boolean)      cmp AX, CX
  {statements;}     jg if_statement
  else              jmp else_statement
                    if_statement:
  {statements;}
                       add DX, 2
                       mov BX, DX
  if(AX>CX){           jmp next_statement
     BX = DX + 2;   else_statement:
  } else {             sub DX, 2
                       mov BX, DX
     BX = DX – 2;
                    next_statement:
  }                    ...
Better Design: Save on Jumps

 cmp AX, CX              cmp AX, CX
 jg if_statement         jng else_statement
 jmp else_statement
 if_statement:           if_statement:
    add DX, 2               add DX, 2
    mov BX, DX              mov BX, DX
    jmp next_statement      jmp next_statement
 else_statement:         else_statement:
    sub DX, 2               sub DX, 2
    mov BX, DX              mov BX, DX
 next_statement:         next_statement:
    ...
                            ...
Compound Boolean Expressions

  ANDed expressions
   – P and Q
   – True if and only if both expressions are True


  ORed expressions
   – P or Q
   – False if and only if both expressions are False
Short Circuited Evaluation

  ANDed Expressions
    – if the first expression is False, there is no need
      to check the second expression.


  ORed Expressions
    – If the first expression if True, there is no need
      to check the second expression.
Short Circuited Evaluation

  P and Q
   if (P == FALSE) then proceed to ELSE-part
   else
       if (Q == FALSE) then proceed to ELSE-part
       else
       proceed to THEN-part
Short Circuited Evaluation

  P or Q
   if (P == TRUE) then proceed to THEN-part
   else
       if (Q == TRUE) then proceed to THEN-part
       else
       proceed to ELSE-part
ANDed Expressions

 if(AX >= 100) &&   cmp AX, 100
                    jge other_cond
 (AX <=120) {
                    jmp else_stmt
    BX = AX;        other_cond:
 } else {               cmp AX, 120
                        jle if_stmt
    BX = CX;
                        jmp else_stmt
 }                  if_stmt:
                        mov BX, AX
                        jmp next_stmt
                    else_stmt:
                        mov BX, CX
                    next_stmt:
                        ...
ANDed Expressions

 if(AX >= 100) &&   cmp AX, 100
 (AX <=120) {       jnge else_part
    BX = AX;        cmp AX, 120
 } else {           jnle else_part
                    then_part:
    BX = CX;
                       mov BX, AX
 }
                        jmp next_part
                    else_part:
                       mov BX, CX
                    next_part:
                       ...
ORed Expressions

 if(AX < 100) ||   cmp AX, 100
 (AX > 120) {      jl then_part
    BX = CX;       cmp AX, 120
 } else {          jng else_part
    BX = AX;       then_part:
 }                     mov BX, CX
                       jmp next_part
                   else_part:
                       mov BX, AX
                   next_part:
                       ...
Group Activity


     if ((al>=bl) && (al<10)){
        printf(“%s”,msg1);
     }
     else {
        printf(“%s”,msg2);
     }
     cl=bl;

Weitere ähnliche Inhalte

Was ist angesagt?

signal and system Dirac delta functions (1)
signal and system Dirac delta functions (1)signal and system Dirac delta functions (1)
signal and system Dirac delta functions (1)iqbal ahmad
 
Laplace transform & fourier series
Laplace transform & fourier seriesLaplace transform & fourier series
Laplace transform & fourier seriesvaibhav tailor
 
Discreate time system and z transform
Discreate time system and z transformDiscreate time system and z transform
Discreate time system and z transformVIKAS KUMAR MANJHI
 
TMPA-2017: The Quest for Average Response Time
TMPA-2017: The Quest for Average Response TimeTMPA-2017: The Quest for Average Response Time
TMPA-2017: The Quest for Average Response TimeIosif Itkin
 
Controllers for 3R Robot
Controllers for 3R RobotControllers for 3R Robot
Controllers for 3R RobotGiovanni Murru
 
237654933 mathematics-t-form-6
237654933 mathematics-t-form-6237654933 mathematics-t-form-6
237654933 mathematics-t-form-6homeworkping3
 
DSP_FOEHU - MATLAB 01 - Discrete Time Signals and Systems
DSP_FOEHU - MATLAB 01 - Discrete Time Signals and SystemsDSP_FOEHU - MATLAB 01 - Discrete Time Signals and Systems
DSP_FOEHU - MATLAB 01 - Discrete Time Signals and SystemsAmr E. Mohamed
 
DSP_2018_FOEHU - Lec 04 - The z-Transform
DSP_2018_FOEHU - Lec 04 - The z-TransformDSP_2018_FOEHU - Lec 04 - The z-Transform
DSP_2018_FOEHU - Lec 04 - The z-TransformAmr E. Mohamed
 
Asymptotic Notation and Complexity
Asymptotic Notation and ComplexityAsymptotic Notation and Complexity
Asymptotic Notation and ComplexityRajandeep Gill
 
Parametrized Model Checking of Fault Tolerant Distributed Algorithms by Abstr...
Parametrized Model Checking of Fault Tolerant Distributed Algorithms by Abstr...Parametrized Model Checking of Fault Tolerant Distributed Algorithms by Abstr...
Parametrized Model Checking of Fault Tolerant Distributed Algorithms by Abstr...Iosif Itkin
 
discrete time signals and systems
 discrete time signals and systems  discrete time signals and systems
discrete time signals and systems Zlatan Ahmadovic
 

Was ist angesagt? (20)

signal and system Dirac delta functions (1)
signal and system Dirac delta functions (1)signal and system Dirac delta functions (1)
signal and system Dirac delta functions (1)
 
Laplace transform & fourier series
Laplace transform & fourier seriesLaplace transform & fourier series
Laplace transform & fourier series
 
Discreate time system and z transform
Discreate time system and z transformDiscreate time system and z transform
Discreate time system and z transform
 
Dfa h11
Dfa h11Dfa h11
Dfa h11
 
Lecture 23 loop transfer function
Lecture 23 loop transfer functionLecture 23 loop transfer function
Lecture 23 loop transfer function
 
Z transfrm ppt
Z transfrm pptZ transfrm ppt
Z transfrm ppt
 
wddd
wdddwddd
wddd
 
TMPA-2017: The Quest for Average Response Time
TMPA-2017: The Quest for Average Response TimeTMPA-2017: The Quest for Average Response Time
TMPA-2017: The Quest for Average Response Time
 
Controllers for 3R Robot
Controllers for 3R RobotControllers for 3R Robot
Controllers for 3R Robot
 
Z transform
 Z transform Z transform
Z transform
 
237654933 mathematics-t-form-6
237654933 mathematics-t-form-6237654933 mathematics-t-form-6
237654933 mathematics-t-form-6
 
DSP_FOEHU - MATLAB 01 - Discrete Time Signals and Systems
DSP_FOEHU - MATLAB 01 - Discrete Time Signals and SystemsDSP_FOEHU - MATLAB 01 - Discrete Time Signals and Systems
DSP_FOEHU - MATLAB 01 - Discrete Time Signals and Systems
 
Lyapunov stability
Lyapunov stability Lyapunov stability
Lyapunov stability
 
Fourier series 2
Fourier series 2Fourier series 2
Fourier series 2
 
Properties of laplace transform
Properties of laplace transformProperties of laplace transform
Properties of laplace transform
 
DSP_2018_FOEHU - Lec 04 - The z-Transform
DSP_2018_FOEHU - Lec 04 - The z-TransformDSP_2018_FOEHU - Lec 04 - The z-Transform
DSP_2018_FOEHU - Lec 04 - The z-Transform
 
Asymptotic Notation and Complexity
Asymptotic Notation and ComplexityAsymptotic Notation and Complexity
Asymptotic Notation and Complexity
 
Parametrized Model Checking of Fault Tolerant Distributed Algorithms by Abstr...
Parametrized Model Checking of Fault Tolerant Distributed Algorithms by Abstr...Parametrized Model Checking of Fault Tolerant Distributed Algorithms by Abstr...
Parametrized Model Checking of Fault Tolerant Distributed Algorithms by Abstr...
 
Dsp case study
Dsp case studyDsp case study
Dsp case study
 
discrete time signals and systems
 discrete time signals and systems  discrete time signals and systems
discrete time signals and systems
 

Andere mochten auch (11)

Chapter2a
Chapter2aChapter2a
Chapter2a
 
Chapter2c
Chapter2cChapter2c
Chapter2c
 
Chapter1b
Chapter1bChapter1b
Chapter1b
 
Chapter2a
Chapter2aChapter2a
Chapter2a
 
Cmsc 100 xhtml and css
Cmsc 100 xhtml and cssCmsc 100 xhtml and css
Cmsc 100 xhtml and css
 
Cmsc 100 (web content)
Cmsc 100  (web content)Cmsc 100  (web content)
Cmsc 100 (web content)
 
linked list (CMSC 123)
linked list (CMSC 123)linked list (CMSC 123)
linked list (CMSC 123)
 
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)
 
Chapter1c
Chapter1cChapter1c
Chapter1c
 
Chapter2d
Chapter2dChapter2d
Chapter2d
 
Chapter1a
Chapter1aChapter1a
Chapter1a
 

Ähnlich wie Chapter2b

09 - Program verification
09 - Program verification09 - Program verification
09 - Program verificationTudor Girba
 
Open GL 04 linealgos
Open GL 04 linealgosOpen GL 04 linealgos
Open GL 04 linealgosRoziq Bahtiar
 
Knowledge extraction from support vector machines
Knowledge extraction from support vector machinesKnowledge extraction from support vector machines
Knowledge extraction from support vector machinesEyad Alshami
 
Assembly Language Lecture 5
Assembly Language Lecture 5Assembly Language Lecture 5
Assembly Language Lecture 5Motaz Saad
 
ガウス過程入門
ガウス過程入門ガウス過程入門
ガウス過程入門ShoShimoyama
 
SVM (Support Vector Machine & Kernel)
SVM (Support Vector Machine & Kernel)SVM (Support Vector Machine & Kernel)
SVM (Support Vector Machine & Kernel)SEMINARGROOT
 
Continuation Passing Style and Macros in Clojure - Jan 2012
Continuation Passing Style and Macros in Clojure - Jan 2012Continuation Passing Style and Macros in Clojure - Jan 2012
Continuation Passing Style and Macros in Clojure - Jan 2012Leonardo Borges
 
Automata theory - Push Down Automata (PDA)
Automata theory - Push Down Automata (PDA)Automata theory - Push Down Automata (PDA)
Automata theory - Push Down Automata (PDA)Akila Krishnamoorthy
 
Lab lect03 arith_control
Lab lect03 arith_controlLab lect03 arith_control
Lab lect03 arith_controlMPDS
 

Ähnlich wie Chapter2b (20)

Al2ed chapter8
Al2ed chapter8Al2ed chapter8
Al2ed chapter8
 
09 - Program verification
09 - Program verification09 - Program verification
09 - Program verification
 
alt klausur
alt klausuralt klausur
alt klausur
 
Teori automata lengkap
Teori automata lengkapTeori automata lengkap
Teori automata lengkap
 
Open GL 04 linealgos
Open GL 04 linealgosOpen GL 04 linealgos
Open GL 04 linealgos
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
 
Knowledge extraction from support vector machines
Knowledge extraction from support vector machinesKnowledge extraction from support vector machines
Knowledge extraction from support vector machines
 
Msc lecture07
Msc lecture07Msc lecture07
Msc lecture07
 
ASQ Talk v4
ASQ Talk v4ASQ Talk v4
ASQ Talk v4
 
Assembly Language Lecture 5
Assembly Language Lecture 5Assembly Language Lecture 5
Assembly Language Lecture 5
 
ガウス過程入門
ガウス過程入門ガウス過程入門
ガウス過程入門
 
Canonicals
CanonicalsCanonicals
Canonicals
 
SVM (Support Vector Machine & Kernel)
SVM (Support Vector Machine & Kernel)SVM (Support Vector Machine & Kernel)
SVM (Support Vector Machine & Kernel)
 
2.3 implicits
2.3 implicits2.3 implicits
2.3 implicits
 
Continuation Passing Style and Macros in Clojure - Jan 2012
Continuation Passing Style and Macros in Clojure - Jan 2012Continuation Passing Style and Macros in Clojure - Jan 2012
Continuation Passing Style and Macros in Clojure - Jan 2012
 
1551 limits and continuity
1551 limits and continuity1551 limits and continuity
1551 limits and continuity
 
Servo systems
Servo systemsServo systems
Servo systems
 
8086 instruction set
8086  instruction set8086  instruction set
8086 instruction set
 
Automata theory - Push Down Automata (PDA)
Automata theory - Push Down Automata (PDA)Automata theory - Push Down Automata (PDA)
Automata theory - Push Down Automata (PDA)
 
Lab lect03 arith_control
Lab lect03 arith_controlLab lect03 arith_control
Lab lect03 arith_control
 

Kürzlich hochgeladen

Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
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
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
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
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
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
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
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
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 

Kürzlich hochgeladen (20)

Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
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
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.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...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
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...
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
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
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 

Chapter2b

  • 1. Group Activity 1. printf(“%c”,x); 2. sum = x + y; 3. prod = x * y; (assume x and y are byte-size variables)
  • 2. Group Activity 1. printf(“%c”,x); mov eax, 4 mov ebx, 1 mov ecx, x mov edx, 1 int 80h
  • 3. Group Activity 2. sum = x + y; mov bl, [x] add bl, [y] mov [sum], bl
  • 4. Group Activity 3. prod = x * y; mov al, [x] mul byte[y] mov [prod], ax
  • 5. Structured Assembly Language Programming Techniques Control Transfer Instructions
  • 6. Control Transfer Instructions  allows program control to transfer to specified label  Unconditional or Conditional  Unconditional – executed without regards to any situation or condition in the program – transfer of control goes from one code to another by force jmp label – unconditional jump
  • 7. Control Transfer Instructions mov al, 5 next: add [num1],al mov eax, 4 jmp next mov ebx, 1 mov ecx, num2 mov eax, 4 mov edx, 1 mov ebx, 1 int 80h mov ecx, num1 mov edx, 1 int 80h (1) (2)
  • 8. Control Transfer Instructions  Conditional – a jump carried out on the basis of a truth value – the information on which such decisions are based is contained in the flags registers
  • 9. Boolean Expressions  evaluates to True or False  compares two values  cmp source1, source2  Source1 may be a register or memory  Source2 may be a register, memory or immediate  Operands cannot be both memory.  Operands must be of the same size.
  • 10. Conditional Jumps  usually placed after a cmp instruction conditional_jump label  JE – branches if source1 == source2  JNE – branches if source1 ≠ source2
  • 11. Conditional Jumps  Signed Conditional Jump – JL or JNGE  branches if source1 < source2 – JLE or JNG  branches if source1 ≤ source2 – JG or JNLE  branches if source1 > source2 – JGE or JNL  branches if source1 ≥ source2
  • 12. Conditional Jumps  Unsigned Conditional Jumps – JB or JNAE  branches if source1 < source2 – JBE or JNA  branches if source1 ≤ source2 – JA or JNBE  branches if source1 > source2 – JAE or JNB  branches if source1 ≥ source2
  • 13. Signed or Unsigned mov al, FFh 1 1 1 1 1 1 1 1 cmp al, 10 jb label  FFh == 255  will not jump to label
  • 14. Signed or Unsigned mov al, FFh 1 1 1 1 1 1 1 1 cmp al, 10 jl label - 0 0 0 0 0 0 1  FFh == -1  will jump to label
  • 15. Control Structure: IF Statement if (boolean) cmp AX, CX {statements;} jg if_statement jmp next_statement if(AX>CX){ BX = DX + 2; if_statement: } add DX, 2 mov BX, DX next_statement: ...
  • 16. Better Design: Save on Jumps cmp AX, CX cmp AX, CX jg if_statement jng next_statement jmp next_statement if_statement: if_statement: add DX, 2 add DX, 2 mov BX, DX mov BX, DX next_statement: next_statement: ... ...
  • 17. Control Structure: IF-ELSE Statement if (boolean) cmp AX, CX {statements;} jg if_statement else jmp else_statement if_statement: {statements;} add DX, 2 mov BX, DX if(AX>CX){ jmp next_statement BX = DX + 2; else_statement: } else { sub DX, 2 mov BX, DX BX = DX – 2; next_statement: } ...
  • 18. Better Design: Save on Jumps cmp AX, CX cmp AX, CX jg if_statement jng else_statement jmp else_statement if_statement: if_statement: add DX, 2 add DX, 2 mov BX, DX mov BX, DX jmp next_statement jmp next_statement else_statement: else_statement: sub DX, 2 sub DX, 2 mov BX, DX mov BX, DX next_statement: next_statement: ... ...
  • 19. Compound Boolean Expressions  ANDed expressions – P and Q – True if and only if both expressions are True  ORed expressions – P or Q – False if and only if both expressions are False
  • 20. Short Circuited Evaluation  ANDed Expressions – if the first expression is False, there is no need to check the second expression.  ORed Expressions – If the first expression if True, there is no need to check the second expression.
  • 21. Short Circuited Evaluation  P and Q if (P == FALSE) then proceed to ELSE-part else if (Q == FALSE) then proceed to ELSE-part else proceed to THEN-part
  • 22. Short Circuited Evaluation  P or Q if (P == TRUE) then proceed to THEN-part else if (Q == TRUE) then proceed to THEN-part else proceed to ELSE-part
  • 23. ANDed Expressions if(AX >= 100) && cmp AX, 100 jge other_cond (AX <=120) { jmp else_stmt BX = AX; other_cond: } else { cmp AX, 120 jle if_stmt BX = CX; jmp else_stmt } if_stmt: mov BX, AX jmp next_stmt else_stmt: mov BX, CX next_stmt: ...
  • 24. ANDed Expressions if(AX >= 100) && cmp AX, 100 (AX <=120) { jnge else_part BX = AX; cmp AX, 120 } else { jnle else_part then_part: BX = CX; mov BX, AX } jmp next_part else_part: mov BX, CX next_part: ...
  • 25. ORed Expressions if(AX < 100) || cmp AX, 100 (AX > 120) { jl then_part BX = CX; cmp AX, 120 } else { jng else_part BX = AX; then_part: } mov BX, CX jmp next_part else_part: mov BX, AX next_part: ...
  • 26. Group Activity if ((al>=bl) && (al<10)){ printf(“%s”,msg1); } else { printf(“%s”,msg2); } cl=bl;