The Wayback Machine - https://web.archive.org/web/20240905193408/https://www.geeksforgeeks.org/8086-program-to-convert-a-16-bit-decimal-number-to-binary/
Open In App

8086 program to convert a 16 bit decimal number to binary

Last Updated : 03 Jun, 2021
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Problem: We are given a 16 bit decimal number we have to print the number in binary format

Examples: 

Input: d1 = 16
Output: 10000

Input: d1 = 7
Output: 111 

Explanation:  

  1. Load the value stored into register
  2. Divide the value by 2 to convert it to binary
  3. Push the remainder into the stack
  4. Increase the count
  5. Repeat the steps until the value of the register is greater than 0
  6. Until the count is greater than zero
  7. POP the stack
  8. Add 48 to the top element to convert it into ASCII
  9. Print the character using interrupt
  10. Decrements the count

Program: 




;8086 program to convert a 16 bit decimal number to binary
    .MODEL SMALL
    .STACK 100H
    .DATA
        d1 dw 16
    .CODE
        MAIN PROC FAR
            MOV AX,
    @DATA
        MOV DS,
    AX
  
;load the value stored;
in variable d1
    mov ax,
    d1
  
;convert the value to binary;
print the value
    CALL PRINT
  
;interrupt to exit
    MOV AH,
    4CH INT 21H
  
    MAIN ENDP
        PRINT PROC
  
;initialize count
    mov cx,
    0 mov dx, 0 label1:;
if
    ax is zero
        cmp ax,
        0 je print1
  
;initialize bx to 2 mov bx, 2
  
;divide it by 2
;to convert it to binary
    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
  
;interrupt to print a
;character
    mov ah,
    02h int 21h
  
;decrease the count
    dec cx
        jmp print1
            exit : ret
                       PRINT ENDP
                           END MAIN


Output: 

10000

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
 



Similar Reads

8086 program to convert a 16 bit Decimal number to Octal
Problem: We are given a 16 bit decimal number we have to print the number in octal format. Examples: Input: d1 = 16 Output:20 Input: d1 = 123 Output: 173 Explanation: Load the value stored into register Divide the value by 8 to convert it to octal Push the remainder into the stack Increase the count Repeat the steps until the value of the register
2 min read
8086 program to convert a 16 bit decimal number to Hexadecimal
Problem: We are given a 16 bit decimal number we have to print the number in Hexadecimal format. Examples: Input: d1 = 999 Output: 3E7 Input: d1 = 123 Output: 7B Explanation: Load the value stored into register Divide the value by 16 to convert it to Hexadecimal Push the remainder into the stack Increase the count Repeat the steps until the value o
2 min read
8086 program to divide a 16 bit number by an 8 bit number
Problem - Write an assembly language program in 8086 microprocessor to divide a 16 bit number by an 8 bit number. Example - Algorithm - Assign value 500 in SI and 600 in DI Move the contents of [SI] in BL and increment SI by 1 Move the contents of [SI] and [SI + 1] in AX Use DIV instruction to divide AX by BL Move the contents of AX in [DI]. Halt t
2 min read
8086 program to Print a 16 bit Decimal number
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 registerdivide the value by 10push the remainder into the stackincrease the countrepeat the steps until the value of the register is greater than 0until the count is greater than ze
2 min read
8086 program to reverse 8 bit number using 8 bit operation
Problem – Write an assembly language program in 8086 microprocessor to reverse 8 bit number using 8 bit operation. Example – Assume 8 bit number is stored at memory location 2050 Algorithm – Load contents of memory location 2050 in register AL Assign 0004 to CX Register Pair Rotate the contents of AL by executing ROL instruction using CX Store the
1 min read
8086 program to reverse 16 bit number using 8 bit operation
Problem - Write an assembly language program in 8086 microprocessor to reverse 16 bit number using 8 bit operation. Example - Assume 16 bit number is stored at memory location 2050 and 2051. Algorithm – Load contents of memory location 2050 in register AL Load contents of memory location 2051 in register AH Assign 0004 to CX Register Pair Rotate th
2 min read
8086 program to convert an 8 bit BCD number into hexadecimal number
Problem - Write an assembly language program in 8086 microprocessor to convert an 8 bit BCD number into hexadecimal number. Example - Assumption - Initial value of segment register is 00000. Calculation of physical memory address: Memory Address = Segment Register * 10(H) + Offset where Segment Register is 00000 (Assumption) and Offset is given in
2 min read
8086 program to convert 8 bit BCD number into ASCII Code
Problem – Write an assembly language program in 8086 microprocessor to convert 8-bit BCD number to its respective ASCII Code. Assumption – Starting address of the program: 400 Input memory location: 2000 Output memory location: 3000 Example : Input: DATA: 98H in memory location 2000Output:DATA: 38H in memory location 3000 and 39H in memory location
2 min read
8086 program to convert 8 bit ASCII to BCD number
Problem - Write a program to convert ASCII to BCD 8-bit number where the starting address is 2000 and the number is stored at 2050 memory address and store result in 3050 memory address. Example-Input : location: 2050 Data : 37Output : location: 3050 Data : 07 Algorithm – Move value at [2050] into AL Perform AND operation on AL with 0F Move the con
1 min read
8086 program to find sum of digits of 8 bit number
Problem - Write an assembly language program in 8086 microprocessor to find sum of digit of an 8 bit number using 8 bit operation. Example - Assume 8 bit number is stored at memory location 2050. Assumptions - Addresses of input data and output data are 2050 and 2051 respectively. Algorithm - Load contents of memory location 2050 in register AL Cop
2 min read
8086 program to subtract two 16-bit numbers with or without borrow
Problem - Write a program to subtract two 16-bit numbers where starting address is 2000 and the numbers are at 3000 and 3002 memory address and store result into 3004 and 3006 memory address. Example - Algorithm - Load 0000H into CX register (for borrow) Load the data into AX(accumulator) from memory 3000 Load the data into BX register from memory
2 min read
8086 program to add two 16-bit numbers with or without carry
Problem - Write a program to add two 16-bit numbers where starting address is 2000 and the numbers are at 3000 and 3002 memory address and store result into 3004 and 3006 memory address. Example - Algorithm - Load 0000H into CX register (for carry) Load the data into AX(accumulator) from memory 3000 Load the data into BX register from memory 3002 A
2 min read
8086 program to multiply two 16-bit numbers
Problem - Write a program to multiply two 16-bit numbers where starting address is 2000 and the numbers are at 3000 and 3002 memory address and store result into 3004 and 3006 memory address. Example - Algorithm - First load the data into AX(accumulator) from memory 3000 Load the data into BX register from memory 3002 Multiply BX with Accumulator A
1 min read
8086 program to add two 8 bit BCD numbers
Problem - Write a program in 8086 microprocessor to find out the addition of two 8-bit BCD numbers, where numbers are stored from starting memory address 2000 : 500 and store the result into memory address 2000 : 600 and carry at 2000 : 601. Example - Algorithm - Load data from offset 500 to register AL (first number) Load data from offset 501 to r
2 min read
8086 program to add two 16 bit BCD numbers with carry
Problem - Write an assembly language program to add two 16 bit BCD numbers with carry in 8086 microprocessor. Example - Algorithm - Load the lower part of both the 16 bit BCD numbers in different locations.Add each number by adding first its lower part.Repeat the above step also by adding the carry if any.Make the lower part of register 00 and add
2 min read
8086 program to multiply two 8 bit numbers
Problem - Write a program in 8086 microprocessor to multiply two 8-bit numbers, where numbers are stored from offset 500 and store the result into offset 600. Examples - Inputs and output are given in Hexadecimal representation. Algorithm - Load data from offset 500 to register AL (first number) Load data from offset 501 to register BL (second numb
1 min read
8086 program to subtract two 8 bit BCD numbers
Problem - Write a program in 8086 microprocessor to find out the Subtraction of two 8-bit BCD numbers, where numbers are stored from starting memory address 2000 : 500 and store the result into memory address 2000 : 600 and carry (borrow) at 2000 : 601. Example - Algorithm - Load data from offset 500 to register AL (first number) Load data from off
2 min read
8086 program to subtract two 16 bit BCD numbers
Prerequisite - 8086 program to subtract two 8 bit BCD numbers Problem - Write a program in 8086 microprocessor to find out the subtraction of two 16-bit BCD numbers, where numbers are stored from starting offset 500 and store the result into offset 600. Example - Algorithm - Load data from offset 500 to register AL Load data from offset 502 to regi
2 min read
8086 program to convert binary to Grey code
Prerequisite - Binary to/from Gray Code Problem - Write a program to convert Binary number to Grey code 8-bit number where starting address is 2000 and the number is stored at 2500 memory address and store result into 2600 memory address. Example – Algorithm – Move value at [2500] into AL Move AL into BL Logical shift right AL one time XOR BL with
1 min read
8086 program to determine largest number in an array of n numbers
Problem - Write a program in 8086 microprocessor to find out the largest among 8-bit n numbers, where size “n” is stored at memory address 2000 : 500 and the numbers are stored from memory address 2000 : 501 and store the result (largest number) into memory address 2000 : 600. Example - Algorithm - Load data from offset 500 to register CL and set r
2 min read
8086 program to find the factorial of a number
Prerequisite - 8085 program to find the factorial of a number Problem – Write an assembly language program for calculating the factorial of a number using 8086 microprocessor Examples - Input : 04H Output : 18H as In Decimal : 4*3*2*1 = 24 In Hexadecimal : 24 = 18H Input : 06H Output : 02D0H as In Decimal : 6*5*4*3*2*1 = 720 In Hexadecimal : 720 =
2 min read
8086 program to find Square Root of a number
Problem – Write an assembly language program in 8086 microprocessor to find square root of a number. Example - Algorithm – Move the input data in register AX Move the data 0000 in CX and FFFF in BX Add 0002 to the contents of BX Increment the content of CX by 1 Subtract the contents of AX and BX If Zero Flag(ZF) is not set go to step 3 else go to s
2 min read
8086 program to search a number in a string
Problem – Write an assembly language program in 8086 microprocessor to search a number in a string of 5 bytes, store the offset where the element is found and the number of iterations used to find the number. Example - Algorithm – Move 2000 in AX and assign it to ES Assign value 600 to DI Move 25 in AL Move 0005 in CX Move the contents of CX to BX
3 min read
8086 program to find the square root of a perfect square root number | Set-2
Prerequisite - 8086 program to find Square Root of a number Problem - Write a program to find the square root of a perfect number where starting address for code is 2000 and number is stored at 3000 memory address and store result into 3002 memory address. Example – Algorithm – Move 0000 to register CX immediatelyMove value of memory 3000 into regi
2 min read
8085 program to convert an 8 bit number into Grey number
Prerequisite - Binary to/from Gray Code Problem - Write an assembly language program in 8085 which convert an 8 bit number into grey number Example - Assumption - 8 bit number (input) is stored at memory location 2050 and output to be stored at memory location 3050. Algorithm - Load the content of memory location 2050 in AccumulatorReset carry flag
2 min read
8085 program to convert an 8 bit BCD number into hexadecimal number
Problem - Write an assembly language program in 8085 microprocessor to convert an 8 bit BCD number into hexadecimal number. Assumptions - Assume that starting address of the program is 2000, input memory locations, 2050, 2051, and output memory location is 2052. Example - INPUT: 2050:02H 2051: 09H OUTPUT:2052: 1DH Algorithm - Initialize memory poin
2 min read
8086 program to sort an integer array in ascending order
Problem - Write a program in 8086 microprocessor to sort numbers in ascending order in an array of n numbers, where size “n” is stored at memory address 2000 : 500 and the numbers are stored from memory address 2000 : 501. Example - Example explanation: Pass-1: F9 F2 39 05 F2 F9 39 05 F2 39 F9 05 F2 39 05 F9 (1 number got fix) Pass-2: F2 39 05 F9 3
3 min read
8086 program to find the min value in a given array
Problem - Write a program to find the min value in a given array in assembly 8086 microprocessor Example - Assumptions - Starting address of input array is 0500 and store the result at address 0600 Algorithm – Assign value 500 in SI and 600 in DIMove the contents of [SI] in CL and increment SI by 1Assign the value 00 H to CHMove the content of [SI]
2 min read
8086 program to find sum of odd numbers in a given series
Problem - Write an Assembly Language Program to find sum of odd numbers in a given series containing 8 bit numbers stored in a continuous memory location and store the result in another memory location. Example - Example Explanation - 500 offset stores the counter value of the series and the elements of the series starts from 501 to 504 offset. In
3 min read
8086 program to transfer a block of bytes by using string instruction
Problem: Write an assembly language program to transfer a block of bytes from one memory location to another memory location by using string instruction. Example: Example: In this example, the counter value stored in CX register is 4.The block of data which is stored from memory location starting from 501 to 504 offset is transferred to another mem
3 min read