Skip to content

Instantly share code, notes, and snippets.

@NikhilAshodariya
Created August 29, 2017 17:25
Show Gist options
  • Select an option

  • Save NikhilAshodariya/582650892ed450994c41a4a2af68ee03 to your computer and use it in GitHub Desktop.

Select an option

Save NikhilAshodariya/582650892ed450994c41a4a2af68ee03 to your computer and use it in GitHub Desktop.
Assembly language program to divide two 8-bit nos
;Division
ansprint macro res
mov dl,res
add dl,30h
mov ah,02h
int 21h
endm
data segment
msg1 db "Enter one number $"
msg2 db 10,13,"Enter second number $"
msg3 db 10,13,"result = $"
msgdecimal db ".$"
a db 0
b db ?
decimal db 10 dup(0)
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
;displaying the message
mov dx,offset msg1
mov ah,09h
int 21h
;taking the 1st input number
mov ah,01h
int 21h
sub al,30h
mov bh,al
mov ah,01h
int 21h
sub al,30h
mov bl,al
;combing two numbers
mov ax,bx
aad
mov bx,ax
;displaying the 2nd message
mov dx,offset msg2
mov ah,09h
int 21h
;taking the 2st input number
mov ah,01h
int 21h
sub al,30h
mov ch,al
mov ah,01h
int 21h
sub al,30h
mov cl,al
;combing two numbers
mov ax,cx
aad
mov cx,ax
mov b,cl
;dividing the number
mov al,bl
div cl
mov bl,ah
aam
mov cx,ax
;displaying the result message
mov dx,offset msg3
mov ah,09h
int 21h
;displaying the result
mov dl,ch
add dl,30h
mov ah,02h
int 21h
mov dl,cl
add dl,30h
mov ah,02h
int 21h
;displaying the decimal
mov dx,offset msgdecimal
mov ah,09h
int 21h
;spliting the decimal
mov ch,00
mov cl,05
label1:
mov al,10
mul bl ;bl contains the remainder part of the ans i.e. the ah part
div b ;b contains the 2nd number of the input
mov bl,ah
aam ;spilts the number into decimal
mov decimal,al;store the number in the array
ansprint decimal
loop label1
mov cx,ax
;terminate the program successfully
mov ax,4c00h
int 21h
code ends
end start
output:
C:\TASM>div
Enter one number 27
Enter second number 14
result = 01.92857
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment