Microprocessor and Assembly Language Lecture-12-Multiplication and Division Instructions Muhammad Hafeez Department of Computer Science GC University Lahore
Today’s Agenda Signed and Unsigned Multiplication Signed and Unsigned Division
Multiplication Instructions The process of multiplication is different for signed and unsigned numbers Example: Take 2 number 1000 0000 and 1111 1111 As unsigned numbers are 255 and 128 Product = 32640 As signed numbers are -128 and -1 Product = 128
Instruction for Signed and Unsigned Multiplication MUL is used for Unsigned multiplication IMUL is used for singed multiplication Syntax is: MUL Source IMUL Source
Byte Form For byte x byte, one operand must be in source Second operand is assumed in AL register 16-bit result is stored in AX register The source must be a register or a memory location, constants are not allowed
Word Form For Word multiplication one number must be in source Second number is assumed in AX register 32-bit result is stored in DX:AX DX holds the Most significant bits AX holds the Least Significant bits
Examples: Translate A= 5 x A – 12 X B using IMUL Instruction.
Examples:
Division Instructions DIV instruction is used for unsigned division Syntax: DIV Divisor IDIV instruction is used for signed division Syntax IDIV Divisor
Division Instructions Byte Form: The divisor is 8-bit register or memory location The dividend is 16-bit that is assumed to be in AX After division AL = Quotient AH = Remainder Divisor must not be a constant
Division Instructions Word Form: The divisor is 16-bit register or memory location The dividend is 32-bit that is assumed to be in DX:AX After division AX = Quotient DX = Remainder Execution of DIV or IDIV could result in divide overflow
Decimal Input/ Output In memory everything is represented in binary. Decimal Input and Output could be done through a program
Decimal Input/ Output In memory everything is represented in binary. Decimal Input and Output could be done through a program
Decimal Output
Decimal Output
Test Program
Decimal Input Convert a string of ASCII digits to the binary representation of a decimal equivalent
Decimal Input
Decimal Input