Division of 16-bit Nos (Assembly Language)

; Program to compute 16 bit division of the data.

DATA SEGMENT                            ;INITIALIZE DATA SEGMENT
NUM1 DW 4567H , 2345H         ;INITIALIZE NUM1 ANY DATA.WE HAVE INITIALIZED DIVIDEND AS 32 BIT – 23454537H
NUM2 DW 4111H                            ;INITIALIZE NUM2 ANY DATA. WE HAVE INITIALIZED DIVISOR AS 16 BIT – 2222H
QUO DW 2 DUP(0)                          ;INITIALIZE QUOTIENT AS DATA WORD WITH OFFSET=2.
;IF QUOTIENT IS AT LOCATION 0000H – IT WILL STORE THE LOWER ORDER 16 BIT OF DAT
;THE UPPER 16 BIT OF DATA WILL BE STORED AT QUOTIENT +2 => 0000H +2H => 0002H
REM DW 1 DUP(0)                          ;INITIALIZE REMAINDER AS DATA WORD WITH OFFSET=1.
;IF REMAINDER IS AT LOCATION 0000H – IT WILL STORE THE LOWER ORDER 16 BIT OF DAT
;THE UPPER 16 BIT OF DATA WILL BE STORED AT REMAINDER +2 => 0000H +2H => 0002H
DATA ENDS                                       ;END OF DATA SEGMENT

CODE SEGMENT                            ;INITIALIZE CODE SEGMENT
START:                                                ;START THE CODE
ASSUME CS:CODE , DS:DATA                            ;ASSUMPTION OF CODE AND DATA
MOV AX,DATA                                 ;MOV DATA INTO ACCUMULATOR AX
MOV DS,AX                                        ;MOV DATA FROM ACCUMULATOR INTO DATA SEGMENT REGISTER
MOV AX,NUM1                                ;MOV THE LOWER 16 BITS FROM NUM1 INTO THE ACCUMULATOR AX REGISTER
MOV DX,NUM1+2                          ;MOV THE UPPER 16 BITS FROM NUM1 INTO THE DATA DX REGISTER
DIV NUM2                                          ;DIVIDE NUM2
;BY DEFAULT DIV OPCODE DIVIDES ACCUMULATOR / REGISTER.
;SYNTAX IS DIV XX(BY WHICH REGISTER TO DIVIDE)
MOV QUO,AX                                    ;MOVE THE LOWER 16 BIT RESULT FROM AX TO QUOTIENT
MOV REM,DX                                    ;MOVE THE UPPER 16 BIT RESULT FROM DX TO REMAINDER
MOV AH,4CH                                     ;END OF THE CODE
INT 21H                                                ;END OF THE CODE
CODE ENDS                                        ;END OF CODE SEGMENT
END START                                       ;END OF START
; INPUT :
; NUM1 – 23454567H
; NUM2 – 4111H

; OUTPUT :
; QUOTIENT (AX) – 8AC5H
; REMAINDER (DX) – 0952H

1. siddhartsingh says:
1. Darshan Gajara says: