an assembly language procedure that divides a 32-bit number by a 16-bit number and can be called in any other module. 10m Jun2006

By | June 6, 2015

Write an assembly language procedure for 8086 microprocessor that divides a 32-bit number by a 16-bit number. The procedure should be written in general, so that it may be defined in one module and can be called in any other module.       10m Jun2006

 

 Large Number Division ;-

J := (K*M)/P

mov ax, K ;Note that the imul instruction produces

imul M ; a 32 bit result in DX:AX, so we don’t

idiv P ; need to sign extend AX here.

mov J, ax ;Hope and pray result fits in 16 bits!

DATA SEGMENT
K DW 7777
M DW 77
P DW 77
J DW ?
RES DB 10 DUP (‘$’)
DATA ENDS

CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
MOV AX,DATA
MOV DS,AX

MOV AX,K
IMUL M

CALL CHECKCARRY

MOV J,AX

LEA SI,RES
CALL HEX2DEC

LEA DX,RES
MOV AH,9
INT 21H

MOV AH,4CH
INT 21H
CODE ENDS

CHECKCARRY PROC NEAR

IDIV P
RET
CHECKCARRY ENDP

HEX2DEC PROC NEAR
MOV CX,0
MOV BX,10

LOOP1: MOV DX,0
DIV BX
ADD DL,30H
PUSH DX
INC CX
CMP AX,9
JG LOOP1

ADD AL,30H
MOV [SI],AL

LOOP2: POP AX
INC SI
MOV [SI],AL
LOOP LOOP2
RET
HEX2DEC ENDP

END START

DATA SEGMENT
K DW 7777
M DW 77
P DW 77
J DW ?
RES DB 10 DUP ('$')
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
MOV AX,DATA
MOV DS,AX
MOV AX,K
IMUL M
CALL CHECKCARRY
MOV J,AX
LEA SI,RES
CALL HEX2DEC
LEA DX,RES
MOV AH,9
INT 21H
MOV AH,4CH
INT 21H
CODE ENDS
CHECKCARRY PROC NEAR
IDIV P
RET
CHECKCARRY ENDP
HEX2DEC PROC NEAR
MOV CX,0
MOV BX,10
LOOP1: MOV DX,0
DIV BX
ADD DL,30H
PUSH DX
INC CX
CMP AX,9
JG LOOP1
ADD AL,30H
MOV [SI],AL
LOOP2: POP AX
INC SI
MOV [SI],AL
LOOP LOOP2
RET
HEX2DEC ENDP
END START

Screen shots: -

Asm_program_Divide_32bit_16bit

After Execution: -

Asm_program_Divide_32bit_16bit_Out