Multiplication and Division Instructions & the 0Ah function.

Slides:



Advertisements
Similar presentations
Program.-(9)* Write a program Input two numbers from keyboard and multiply of given values using by variables. Input value No 1 input value No2 Multiply.
Advertisements

DOS and BIOS Interrupts DOS and BIOS interrupts are used to perform some very useful functions, such as displaying data to the monitor, reading data from.
1 x86’s instruction sets. 2 Instruction Set Classification  Transfer Move  Arithmetic Add / Subtract Mul / Div, etc.  Control Jump Call / Return, etc.
Department of Computer Science and Software Engineering
Computer Organization & Assembly Language
Assembly Language Lecture 9
1 Multiplication, Division, and Numerical Conversions Chapter 6.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, MUL Instruction The MUL (unsigned multiply) instruction.
1 Lecture 7 Integer Arithmetic Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
Kip Irvine: Assembly Language for Intel-Based Computers
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 7: Integer Arithmetic (c) Pearson Education, All rights reserved. You may.
Shift and Rotate Instructions
Chapter 4 Basic Instructions. 4.1 Copying Data mov Instructions mov (“move”) instructions are really copy instructions, like simple assignment statements.
Assembly Language for Intel-Based Computers
Integer Arithmetic Computer Organization & Assembly Language Programming Dr Adnan Gutub aagutub ‘at’ uqu.edu.sa [Adapted from slides of Dr. Kip Irvine:
Integer Arithmetic COE 205 Computer Organization and Assembly Language
8.4 Instruction Execution Times TOBIN PROC FAR SUB AX,AX MOV DX,AX MOV CX,4 NEXTD: PUSH CX SUB BP,BP MOV CX,4 GETNUM: RCL BX,1 RCL BP,1 LOOP GETNUM.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#8) By Dr. Syed Noman.
CE302 Outline Multiplication Division Program Segment Prefix Command Line Parameters.
MUL Instruction (Unsigned Multiply) Multiplies an 8-, 16-, or 32-bit operand by either AL, AX or EAX. MUL r/m8 MUL r/m16 MUL r/m32.
Assembly Language – Lab 5
ICS312 Set 4 Program Structure. Outline for a SMALL Model Program Note the quiz at the next lecture will be to reproduce this slide.MODEL SMALL.586 ;
Sahar Mosleh California State University San MarcosPage 1 Applications of Shift and Rotate Instructions.
BIOS1 Basic Input Output System BIOS BIOS refers to a set of procedures or functions that enable the programmer have access to the hardware of the computer.
BIOS and DOS Programming in DOS INT 10 and 21H. Interrupts There are some extremely useful subroutines within BIOS or DOS that are available to the user.
ECE291 Computer Engineering II Lecture 6 & Lecture 7 Dr. Zbigniew Kalbarczyk University of Illinois at Urbana- Champaign.
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 4 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
1 IKI10230 Pengantar Organisasi Komputer Kuliah no. 05.b: Arithmetic Operations Sumber: 1. Paul Carter, PC Assembly Language 2. Hamacher. Computer Organization,
Integer Arithmetic Computer Organization and Assembly Languages Yung-Yu Chuang 2007/12/24 with slides by Kip Irvine.
Assembly Language for Intel-Based Computers Chapter 7: Integer Arithmetic (c) Pearson Education, All rights reserved. You may modify and copy.
Chapter 7: Integer Arithmetic. 2 Chapter Overview Shift and Rotate Instructions Shift and Rotate Applications Multiplication and Division Instructions.
Irvine, Kip R. Assembly Language for Intel-Based Computers. Chapter 7: Integer Arithmetic Slides to Accompany Assembly Language for Intel-Based Computers,
ICS 312 SET 10 Multiplication & Division & input using function 0Ah.
Chapter 7 Bit Manipulation. 7.1 Logical Operations.
Microprocessor & Assembly Language Arithmetic and logical Instructions.
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.
K.K. Leung Fall 2008Introductory Pentium Programming1 Pentium Architecture: Introductory Programming Kin K. Leung
File Operations. FILE PROCESSING For the purposes of the following discussion, reading means copying all or part of an existing file into memory Writing.
Multiplication and Division instructions Dr.Hadi AL Saadi.
Computer Architecture and Assembly Language
Format of Assembly language
Data Transfers, Addressing, and Arithmetic
Assembly Language for Intel-Based Computers, 5th Edition
Additional Assembly Programming Concepts
Basic Assembly Language
Multiplication and Division Instructions
Defining Types of data expression Dn [name] expression Dn [name]
Symbolic Instruction and Addressing
CS 301 Fall 2002 Assembly Instructions
X86’s instruction sets.
Chapter 4: Instructions
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Microprocessor and Assembly Language
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Symbolic Instruction and Addressing
Shift & Rotate Instructions)
Multiplication and Division Instructions
Symbolic Instruction and Addressing
Assembly Language for Intel-Based Computers, 4th Edition
Assembly Language for Intel-Based Computers, 4th Edition
Assembly Language for Intel-Based Computers, 5th Edition
Computer Architecture and System Programming Laboratory
Chapter 6 –Symbolic Instruction and Addressing
Multiplication and Division Instructions
Multiplication and Division Instructions
By Nasser Halasa Assembly Language.
Division instruction.
Computer Architecture and System Programming Laboratory
Presentation transcript:

Multiplication and Division Instructions & the 0Ah function

IMUL Instruction (signed multiplication) (1) Newer forms of IMUL instruction allow use of immediate operands. (There is no corresponding form for the MUL instruction). For each of these instructions, the operands are all the same length. 3 operands: IMUL reg1, reg2/memory, immediate ; reg1 = reg2/mem * immed 2 operands IMUL reg1, reg2/memory/immediate ; reg1 = reg1 * reg2/immed 1 operand IMUL multiplies an 8, 16, or 32-bit signed operand by AL or AX or EAX respectively. It sign-extends the result into the word or DX:AX or EDX:EAX respectively. IMUL multiplier ; multiplier is 8, 16, or 32-bit register or memory operand.

IMUL Instruction (2) Operand: Multiplier (explicit)Multiplier (implicit)Result is in: 8-bit reg/mem operand AL AX 16-bit reg/mem operand AX DX:AX 32-bit reg/mem operand EAX EDX:EAX

Applications of Multiplication (1) Write a subroutine procedure to compute N! for a positive integer N. Return N! in AX. Definition: for N > 1, N! = N (N-1)*(N-2)…* 1 for N = 1, N! = 1 Algorithm: factorial = 1 (initialization) input: N for N times do factorial = factorial * N N = N - 1 (loop instruction) end for

Applications of Multiplication (2) Code: FACTORIAL PROC ; computes N factorial ; input: CX = N ; output: AX = N! MOV AX, 1 ; factorial TOP: iMUL CX ; fact = fact * N LOOP TOP ; decrements N RET ; return to caller: AX = factorial FACTORIAL ENDP

IDIV Instruction (signed division) (1) IDIV divides AX, DX:AX, or EDX:EAX (dividend) by an 8, 16, or 32-bit signed register or memory operand (divisor) Syntax: IDIV divisor ; divisor is 8, 16, or 32-bit register or memory operand. Operands: Divisor (explicit)Dividend(implicit)QuotientReminder 8-bit reg/mem operand AX ALAH 16-bit reg/mem operand DX:AX AXDX 32-bit reg/mem operand EDX:EAX EAXEDX

IDIV Instruction (signed division) (2) Note: The high byte/word/doubleword of the dividend must be initialized before the division is performed to ensure the correct results are obtained. For signed division, this usually means that the value in the low byte/word/doubleword of the operand must be sign-extended into the high byte/word/doubleword before the division can be performed.

CBW, CWD, CDQ, CWDE Instructions (1) InterpretationMnemonic OPCODEEffect Convert Byte to WordCBWsign extends AL into AX Convert Word to DoublewordCWD sign extends AX into DX:AX Convert Word to Extended Double CWDEsign extends AX into EAX Convert Doubleword to Quadword CDQ sign extends EAX into EDX:EAX These instructions perform the following sign-extensions:

Reading an Entire Line with an Echo (Function 0Ah) Function 0AH reads an entire line of information --- up to 255 characters from the keyboard. It continues to acquire data until either the enter key (0DH) is typed or the character count expires. Required Input: AH = 0AH DS:DX gives the address for the buffer for the keyboard input. The first byte of the buffer area must contain the maximum number of keyboard characters to be read by this function, including the carriage return at the end of the string. If the number typed exceeds this maximum number, the function stops accepting input until the carriage return is entered. Function 0Ah Output: The second byte of the buffer contains the count of the actual number of characters typed, not including the carriage return. The number is filled in by DOS after the string, including the carriage return has been entered. The remaining bytes in the buffer contain the ASCII keyboard data, including the carriage return character at the end of the string.

Example Here is a convenient way to set up the input buffer area to use Function 0Ah: The data: MAX db 15 ACTUAL db ? BUFFER db 15 dup (?) The code: mov ah, 0Ah ; input string function lea dx, MAX ; address of input buffer int 21h ; read string This assigns variable names to the first byte, the second byte, and the beginning of the actual input buffer area. The string read in from the keyboard is stored starting at the address given by BUFFER, and the no. of bytes read in including the carriage return is stored in ACTUAL.