70 likes | 262 Views
Lab 5. Multiplication, Division Instructions. Multiplication Instruction. MUL source Unsigned multiplication. IMUL source Signed multiplication . Multiplicand assumed in AL (8 bit ) or in AX (16 bit ). Source may be a register or a memory byte.
E N D
Lab 5 Multiplication, Division Instructions
Multiplication Instruction • MUL source • Unsigned multiplication • IMUL source • Signed multiplication. • Multiplicand assumed in AL (8 bit) or in AX (16 bit). • Source may be a register or a memory byte. • 8 bit * 8 bit = 16 bit 16 bit * 16 bit = 32 bit
Example 1 • Type a procedure to calculate N! org 100h MOV CX,5 MOV AX,1 ; AX holds product TOP: MUL CX ; product = product X term LOOP TOP ret
Division Instruction • DIV divisor • Unsigned division. • IDIV divisor • Signed division. • Divisor is 8 bit or 16 bit register or memory byte. • Dividend is assumed in AX for 8 bit divisor or in AX:DX for 16 bit divisor. • Quotient is in AL for 8 bit divisor or in AX for 16 bit divisor. • Remainder is in AH for 8 bit divisor or in DX for 16 bit divisor. • 16 bit / 8 bit = 8 bit and remainder 8 bit • 32 bit / 16 bit = 16 bit and remainder 16 bit
Example 2 • Translate into ASSMBLER the following high-level assignment statement: ANSWER = 130 / A + B / C - D / 7 ORG 100H MOV AX,130 ;move constant to reg CWD ;expand to DX:AX IDIV A ;assume QUOTIENT 130/A in AX MOV ANSWER,AX ;ANSWER=130/A MOV AL,B CBW ;expand to AX IDIV C ;assume quotient B/C in AX CBW ;convert byte quotient in AL to a word ADD ANSWER,AX ;ANSWER=130/A + B/C MOV AX,D MOV BL,7 ;put constant in reg IDIV BL ;assume quotient D/7 in AL CBW ;expand to AX so you can SUB from ANSWER SUB ANSWER,AX;ANSWER=130/A + B/C - D/7 ret A DW 5 ANSWER DW ? B DB 9 C DB 3 D DW 49
Exercises • Calculate the following assignment statement in emu. RESULT = A*5 / B*2 + 3 Where A = 4 and B = 2 , show the result on screen.