CS2422 Assembly Language and System Programming 0 Week 13 & 14 Codes in Assembly Language.

Slides:



Advertisements
Similar presentations
Flow of Control Instruction/Control structure Looping structure Looping structure Branching structure Branching structure For assembly language program.
Advertisements

Integer Arithmetic: Multiply, Divide, and Bitwise Operations
CSC 221 Computer Organization and Assembly Language Lecture 21: Conditional and Block Structures: Assembly Programs.
NEG Instruction Change operand content into two’s complement (negative value) and stored back into its operand mov bl, b neg bl; bl = mov.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Conditional Loop Instructions LOOPZ and LOOPE LOOPNZ.
ACOE2511 Assembly Language Arithmetic and Logic Instructions.
Computer Organization & Assembly Language
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 6: Conditional Processing (c) Pearson Education, All rights reserved. You may modify.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 7: Integer Arithmetic (c) Pearson Education, All rights reserved. You may modify.
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
Assembly Language for Intel-Based Computers
CS2422 Assembly Language & System Programming October 17, 2006.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 6: Conditional Processing (c) Pearson Education, All rights reserved. You may modify.
CS2422 Assembly Language and System Programming Conditional Processing Department of Computer Science National Tsing Hua University.
Flow Control Instructions
9-1 ECE 424 Design of Microprocessor-Based Systems Haibo Wang ECE Department Southern Illinois University Carbondale, IL x86 Instructions Part.
Shift and Rotate Instructions
Introduction to Computer Engineering by Richard E. Haskell Shift and Rotate Instructions Module M16.2 Section 10.3.
Assembly Language for x86 Processors 6th Edition
Ch. 7 Logic, Shift and Rotate instr.
ICS312 Set 9 Logic & Shift Instructions. Logic & Shift Instructions Logic and Shift Instructions can be used to change the bit values in an operand. The.
Microprocessors Monday, Apr. 13 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University.
Department of Computer Science and Software Engineering
Web siteWeb site ExamplesExamples ASSEMBLY LANGUAGE FOR INTEL- BASED COMPUTERS, 5 TH EDITION Chapter 6: Conditional Processing Kip R. Irvine.
Dr. José M. Reyes Álamo 1.  Review: ◦ of Comparisons ◦ of Set on Condition  Statement Labels  Unconditional Jumps  Conditional Jumps.
Assembly Language for Intel-Based Computers, 6 th Edition Chapter 6: Conditional Processing (c) Pearson Education, All rights reserved. You may modify.
Logic Conditional Processing. Status flags - review The Zero flag is set when the result of an operation equals zero. The Carry flag is set when an instruction.
Chapter 6: Conditional Processing. 2 Chapter Overview Boolean and Comparison Instructions Conditional Jumps Conditional Loop Instructions Conditional.
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 5 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
1 Logic, Shift, and Rotate Instructions Read Sections 6.2, 7.2 and 7.3 of textbook.
Assembly Language. Symbol Table Variables.DATA var DW 0 sum DD 0 array TIMES 10 DW 0 message DB ’ Welcome ’,0 char1 DB ? Symbol Table Name Offset var.
Assembly 05. Outline Bit mapping Boolean logic (review) Bitwise logic Bit masking Bit shifting Lookup table 1.
EEL 3801 Part V Conditional Processing. This section explains how to implement conditional processing in Assembly Language for the 8086/8088 processors.
LEA instruction The LEA instruction can be used to get the offset address of a variable Example ORG 100h MOV AL, VAR1 ; check value of VAR1 by moving it.
October 1, 2003Serguei A. Mokhov, 1 SOEN228, Winter 2003 Revision 1.2 Date: October 25, 2003.
Lecture 12 Integer Arithmetic Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
COMP 2003: Assembly Language and Digital Logic Chapter 2: Flags and Instructions Notes by Neil Dickson.
Chapter 7 Bit Manipulation. 7.1 Logical Operations.
CSC 221 Computer Organization and Assembly Language Lecture 20: Conditional and Block Structures.
Microprocessor & Assembly Language
Computer and Information Sciences College / Computer Science Department CS 206 D Computer Organization and Assembly Language.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization.
Assembly Language for Intel-Based Computers, 4 th Edition Lecture 22: Conditional Loops (c) Pearson Education, All rights reserved. You may modify.
Boolean, Shift and Rotate instructions Dr.Hadi AL Saadi.
Assembly Language for Intel-Based Computers, 4 th Edition Week 10: Conditional Processing Slides modified by Dr. Osama Younes.
Assembly Language for x86 Processors 6th Edition
CSC 221 Computer Organization and Assembly Language
Assembly Language for Intel-Based Computers, 5th Edition
Computer Architecture CST 250
Introduction to assembly programmıng language
Data Transfers, Addressing, and Arithmetic
Practical Session 2.
Assembly Language for x86 Processors 7th Edition
Assembly Language for Intel-Based Computers, 4th Edition
Chapter 3 Bit Operations
EE3541 Introduction to Microprocessors
Assembly IA-32.
More on logical instruction and
Assembly Language Programming Part 2
CS-401 Assembly Language Programming
Computer Organization and Assembly Language
Shift & Rotate Instructions)
Shift & Rotate Instructions)
Assembly Language for Intel-Based Computers, 4th Edition
Assembly Language for Intel-Based Computers, 5th Edition
Shift, Multiply, and Divide
X86 Assembly Review.
Computer Organization and Assembly Language
Shift and Rotate Instructions.
CS-401 Computer Architecture & Assembly Language Programming
Presentation transcript:

CS2422 Assembly Language and System Programming 0 Week 13 & 14 Codes in Assembly Language

“AND” in Assembly

“OR” in Assembly

While Loop  A WHILE loop is really an IF statement followed by the body of the loop, followed by an unconditional jump to the top of the loop. Consider the following example:

Example  Write an assembly program that compare two digits, continue to increase the first until both are equal. top:cmp eax, ebx jge next inc eax jmp top next: 4

While Loop …

Fast Multiplication  Shifting left 1 bit multiplies a number by 2  Shifting left n bits multiplies the operand by 2 n  For example, 5 * 2 2 = 20

Fast Division  The SHR (shift right) instruction performs a logical right shift on the destination operand. The highest bit position is filled with a zero.  Shifting right n bits divides the operand by 2 n

Your turn...  Indicate the hexadecimal value of AL after each shift:

ROL Instruction  ROL (rotate) shifts each bit to the left  The highest bit is copied into both the Carry flag and into the lowest bit  No bits are lost

ROR Instruction  ROR (rotate right) shifts each bit to the right  The lowest bit is copied into both the Carry flag and into the highest bit  No bits are lost

Applications (AND)  Task: Jump to a label if an integer is even (or odd)  Solution: AND the lowest bit with a ‘1’. If the result is Zero, the number was even. str1 byte “Integer is Even” wordVal word 1011.code mov ax,wordVal and ax,1 ; low bit set? jz EV ; jump if Zero flag set EV:mov eax, str1

Applications (OR)  Task:Jump to a label if the value in AL is not zero  Solution: OR the byte with itself, then use the JNZ (jump if not zero) instruction. wordVal word 1011.code or al,al jnz IsNotZero ; jump if not zero Note: ORing any number with itself does not change its value

Applications (Small or Large)  Task: Compare AX to BX, and copy the larger of the two into a variable named Large  Solution: mov Large,bx cmp ax,bx jl Next(or ‘jna’) mov Large,ax Next:  Task: Compare AX to BX, and copy the smaller of the two into a variable named Small mov Small,ax cmp bx,ax jnl Next mov Small,bx Next: