0% found this document useful (0 votes)
132 views5 pages

MNM Lab # 3 Use of Multiplication and Division Instructions

The document describes different multiplication and division instructions in assembly language. It explains that the MUL instruction multiplies two numbers and stores the result in the AX or DX:AX registers depending on the operand size. The IMUL instruction performs signed multiplication. The DIV instruction performs unsigned division and stores the quotient in AL or AX and residue in AH or DX depending on the operand size. The IDIV instruction performs signed division. It also includes an example program that uses the MUL instruction to calculate and display the factorial of a positive binary number entered by the user.

Uploaded by

Zoobia Tariq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
132 views5 pages

MNM Lab # 3 Use of Multiplication and Division Instructions

The document describes different multiplication and division instructions in assembly language. It explains that the MUL instruction multiplies two numbers and stores the result in the AX or DX:AX registers depending on the operand size. The IMUL instruction performs signed multiplication. The DIV instruction performs unsigned division and stores the quotient in AL or AX and residue in AH or DX depending on the operand size. The IDIV instruction performs signed division. It also includes an example program that uses the MUL instruction to calculate and display the factorial of a positive binary number entered by the user.

Uploaded by

Zoobia Tariq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

MnM Lab # 3

Use of Multiplication and Division instructions.

MUL Instruction

Multiplicand : AH (8-bit reg) / AX (16-bit reg)

x Multiplier : source (8-bit reg) / (16-bit reg)

Result_ : AX (16bit)/ DX:AX (32-bit)

Purpose: Multiplication with unsigned number.


Syntax: MUL source
The assembler assumes that the multiplicand will be of the same size as the multiplier, therefore
it multiplies the value stored on the register given as operator by the one found to be contained in
AH if the multiplier is 8 bits or by AX if the multiplier is 16 bits. When a multiplication is done
with 8 bit values, the result is stored on the AX register and when the multiplication is with 16
bit values the result is stored on the even DX:AX register.
IMUL Instruction
Purpose: Multiplication of two numbers with sign.
Syntax: IMUL source
This command does the same as the one before, but only difference is that this one considers the
signs of the numbers being multiplied.

DIV Instruction
Quotient
Divider)Dividend
xxxxxxx
Residue
Purpose: Division without sign.
Syntax: DIV source
The divider can be a byte or a word and it is the operator which is given the instruction. If the
divider is 8 bits, the 16 bits AX register is taken as dividend and if the divider is 16 bits the even
DX:AX register will be taken as dividend, taking the DX high word and AX as the low. If the
divider was a byte then the quotient will be stored on the AL register and the residue on AH, if it
was a word then the quotient is stored on AX and the residue on DX.
IDIV Instruction
Purpose: Division with sign.
Syntax: IDIV source
It basically the same as the DIV instruction, and the only difference is that this one performs the
operation with sign.
Lab Task
Write a program that will read a positive binary number and print its factorial in
binary form using MUL instruction.
.MODEL SMALL
.STACK 100H
.DATA
PROMPT_1 DB 'Enter a Positive Binary number (max. 1000) : $'
PROMPT_2 DB 0DH,0AH,'The Factorial of the given number is : $'
ILLEGAL DB 0DH,0AH,'Illegal character. Try again : $'
.CODE
MAIN PROC
MOV AX, @DATA ; initialize DS
MOV DS, AX
LEA DX, PROMPT_1 ; load and display the string PROMPT_1
MOV AH, 9
INT 21H
CALL BINARY_INPUT ; call the procedure BINARY_INPUT
CALL FACTORIAL ; call the procedure FACTORIAL
LEA DX, PROMPT_2 ; load and display the string PROMPT_2
MOV AH, 9
INT 21H
CALL BINARY_OUTPUT ; call the procedure BINARY_OUTPUT
MOV AH, 4CH ; return control to DOS
INT 21H
MAIN ENDP
BINARY_INPUT PROC
; this procedure will read a number in binary form
; input : none
; output : store binary number in BL
; uses : MAIN
JMP @START ; jump to label @START
@ERROR: ; jump label
LEA DX, ILLEGAL ; load and display the string ILLEGAL
MOV AH, 9
INT 21H
@START: ; jump label
MOV CX, 4 ; initialize loop counter
XOR BX, BX ; clear BX
MOV AH, 1 ; set input function
@INPUT: ; loop label
INT 21H ; read a digit
CMP AL, 0DH ; compare input and CR
JE @END ; jump to label @END if input is CR
CMP AL, 30H ; compare AL with 0
JL @ERROR ; jump to label @ERROR if AL<0
CMP AL, 31H ; compare AL with 1
JG @ERROR ; jump to label @ERROR if AL>1
AND AL, 0FH ; convert ascii to decimal code
SHL BL, 1 ; shift BL by 1 position towards left
OR BL, AL ; place the input decimal digit in BL
LOOP @INPUT ; jump to label @INPUT if CX!=0
@END: ; jump label
RET ; return control to the calling procedure
BINARY_INPUT ENDP
BINARY_OUTPUT PROC
; this procedure will display a number in binary form
; input : BX
; output : none
; uses : MAIN
MOV CX, 16 ; initialize loop counter
MOV AH, 2 ; set output function
@OUTPUT: ; loop label
SHL BX, 1 ; shift BX by 1 position towards left
JC @ONE ; jump to label @ONE if CF=1
MOV DL, 30H ; move 0 to DL
JMP @DISPLAY ; jump tp label @DISPLAY
@ONE: ; jump label
MOV DL, 31H ; move 1 to DL
@DISPLAY: ; jump label
INT 21H ; display a digit
LOOP @OUTPUT ; jump to label @OUTPUT if CX!=0
RET ; return control to the calling procedure
BINARY_OUTPUT ENDP
FACTORIAL PROC
; this procedure will computes the factorial of a given number
; input : BL
; output : store the factorial of the number in BX
; uses : MAIN
MOV AX, 1 ; set AX=1
XOR CX, CX ; clear CX
MOV CX, BX ; set CX=BX
@LOOP: ; loop label
MUL CX ; multiply CX with AL i.e. AX=AL*CX
LOOP @LOOP ; jump to label @LOOP if CX!=0
MOV BX, AX ; set BX=AX
RET ; return control to the calling procedure
FACTORIAL ENDP
END MAIN

Lab Assignment # 1:
Write an assembly code that accepts two inputs ( 1 st input = 1st letter of your name and 2nd input = last
letter of your name ), store these inputs in appropriate registers, perform multiplication between these
inputs and show the result in binary format.
Lab Assignment # 2:
You all have registration number like 19 – EE – XYZ, write an assembly code that takes last digit (Z) of
your registration number as input, use the result of above-mentioned assignment # 1 task, divide that
result with last digit of your registration number. Show the result that Quotient and Residue.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy