Problem: Write a 8086 program to Print a 16 bit Decimal number.
Examples:
Input: d1 = 655 Output: 655 Input: d1 = 234 Output:234
Explanation:
- load the value stored into register
- divide the value by 10
- push the remainder into the stack
- increase the count
- repeat the steps until the value of the register is greater than 0
- until the count is greater than zero
- pop the stack
- add 48 to the top element to convert it into ASCII
- print the character using interrupt
- decrements the count
Program:
ALP
;8086 program to print a 16 bit decimal number .MODEL SMALL .STACK 100H .DATA d1 dw 655 .CODE MAIN PROC FAR MOV AX,@DATA MOV DS,AX ;load the value stored ; in variable d1 mov ax,d1 ;print the value CALL PRINT ;interrupt to exit MOV AH,4CH INT 21H MAIN ENDP PRINT PROC ;initilize count mov cx,0 mov dx,0 label1: ; if ax is zero cmp ax,0 je print1 ;initilize bx to 10 mov bx,10 ; extract the last digit div bx ;push it in the stack push dx ;increment the count inc cx ;set dx to 0 xor dx,dx jmp label1 print1: ;check if count ;is greater than zero cmp cx,0 je exit ;pop the top of stack pop dx ;add 48 so that it ;represents the ASCII ;value of digits add dx,48 ;interuppt to print a ;character mov ah,02h int 21h ;decrease the count dec cx jmp print1 exit: ret PRINT ENDP END MAIN |
Output:
655
Note: The program cannot be run on an online editor , please use MASM to run the program and use dos box to run MASM , you might use any 8086 emulator to run the program
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.
Recommended Posts:
- 8086 program to convert a 16 bit decimal number to binary
- 8086 program to convert a 16 bit Decimal number to Octal
- 8086 program to convert a 16 bit decimal number to Hexadecimal
- 8086 program to divide a 16 bit number by an 8 bit number
- 8086 program to reverse 8 bit number using 8 bit operation
- 8086 program to reverse 16 bit number using 8 bit operation
- 8086 program to convert an 8 bit BCD number into hexadecimal number
- 8086 program to convert 8 bit ASCII to BCD number
- 8086 program to find sum of digits of 8 bit number
- 8086 program to convert 8 bit BCD number into ASCII Code
- 8086 program to subtract two 16-bit numbers with or without borrow
- 8086 program to add two 16-bit numbers with or without carry
- 8086 program to multiply two 16-bit numbers
- 8086 program to add two 8 bit BCD numbers
- 8086 program to add two 16 bit BCD numbers with carry
- 8086 program to multiply two 8 bit numbers
- 8086 program to subtract two 8 bit BCD numbers
- 8086 program to subtract two 16 bit BCD numbers
- 8086 program to print the table of input integer
- 8086 program to print a String
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

