TASM Program to divide Two 16 Bit Numbers

On-campus and online computer science courses to Learn the basic concepts of Computer Science.This tutorial will cover c ,c++, java, data structure and algorithm,computer graphics,microprocessor,analysis of algorithms,Digital Logic Design and Analysis,computer architecture,computer networks,operating system.
TASM Program :
Data segment

 msg db 0dh,0ah,"Enter Dividend: $"
 msg1 db 0dh,0ah,"Enter Divisor: $"
 resq db 0dh,0ah,"The Quotient is: $"
 resr db 0dh,0ah,"The Remainder is: $"

Data ends
Code segment
 assume CS:Code,DS:Data
start:
 mov ax,Data ; Move Data to Data Segment
 mov DS,ax

 mov dx,offset msg ; Display contents of variable msg div16
 mov ah,09h
 int 21h

 mov ah,01h ; To accept input and store ASCII value into al
 int 21h

 call AsciitoHex

 mov bh,al ; Accept 1000's place of the Number
 rol bh,4

 mov ah,01h ; To accept input and store ASCII value into al
 int 21h

 call AsciitoHex

 add bh,al

 mov ah,01h ; To accept input and store ASCII value into al
 int 21h

 call AsciitoHex

 mov bl,al ; Accept 10's place of the Number
 rol bl,4

 mov ah,01h ; To accept input and store ASCII value into al
 int 21h

 call AsciitoHex ; Accept unit's place of Number

 add bl,al ; Get the number by adding 10's and unit's place

 mov dx,offset msg1 ; Display contents of variable msg1
 mov ah,09h
 int 21h

 mov ah,01h ; To accept input and store ASCII value into al
 int 21h

 call AsciitoHex ; Accept 10's place of the Number
 mov cl,al
 rol cl,4

 mov ah,01h ; To accept input and store ASCII value into al
 int 21h

 call AsciitoHex ; Accept unit's place of Number

 add cl,al ; Get the number by adding 10's and unit's place

 mov ax,bx ; Divide the two accepted Number's
 mov bl,cl
 div bl

 mov cx,ax ; Store the value of the Result

 mov dx,offset resq ; Display contents of string resq
 mov ah,09h
 int 21h

 mov ax,cx ; Retreive Result

 and al,0f0h ; Isolate 10's place of the Quotient
 ror al,4

 mov bl,al ; Convert to ASCII to display
 call AsciiConv 

 mov dl,bl ; Display a Number/Alphabet
 mov ah,02h
 int 21h

 mov ax,cx ; Retrieve original Result

 and al,0fh ; Isolate unit's place of Result

 mov bl,al ; Convert to ASCII to display
 call AsciiConv 

 mov dl,bl ; Display a Number/Alphabet
 mov ah,02h
 int 21h

 mov dx,offset resr ; Display contents of string resr
 mov ah,09h
 int 21h

 mov ax,cx ; Retrieve original Result

 and ah,0f0h ; Isolate 10's place of the Quotient
 ror ah,4

 mov bl,ah ; Convert to ASCII to display
 call AsciiConv 

 mov dl,bl ; Display a Number/Alphabet
 mov ah,02h
 int 21h

 mov ax,cx ; Retrieve original Result

 and ah,0fh ; Isolate unit's place of Result

 mov bl,ah ; Convert to ASCII to display
 call AsciiConv 

 mov dl,bl ; Display a Number/Alphabet
 mov ah,02h
 int 21h

 mov ah,4ch ; Terminate the program
 int 21h

 AsciiConv proc ; Compare to 0a if it is less than A then we need to add only 30
  cmp bl,0ah ; If it is greater than or equal to 0a then we also need to add 07
  jc skip
  add bl,07h
  skip: add bl,30h
  ret
  endp

 AsciitoHex proc ; Compare to 41 if it is less than A then we need to sub only 30
  cmp al,41h ; If it is greater than or equal to 41 then we also need to sub 07
  jc skippy
  sub al,07h
  skippy: sub al,30h
  ret
  endp
Code ends
end start
output:-
C:\Documents and Settings\admin>cd c:\tasm\bin

C:\TASM\BIN>tasm 16Div.asm
Turbo Assembler  Version 4.1  Copyright (c) 1988, 1996 Borland International

Assembling file:   16Div.asm
Error messages:    None
Warning messages:  None
Passes:            1
Remaining memory:  452k


C:\TASM\BIN>tlink 16Div.obj
Turbo Link  Version 7.1.30.1. Copyright (c) 1987, 1996 Borland International
Warning: No stack

C:\TASM\BIN>16Div

Enter Dividend: 0100
Enter Divisor: 09
The Quotient is: 1C
The Remainder is: 04
--------------------------------

0 comments: