Multi Digit Subtraction without Negative Checking in 8086 Assembly Language

Explanation:

This code preforms subtraction between two double digit numbers and prints their result. Note this works only if the digits of first number is bigger than second number. It doesn’t handle the exception that result can be negative.


Code:
;
; Author:  Asif Ahmed
; Site:    https://quickgrid.wordpress.com
; Comment: Semicolon means comment.
;
                                         
                                         
                                         
org 100h
     
.model small        
            
.stack 200h            
            
.data     
            
    
    msg1 db 'Enter first number: ', '$'
    msg2 db 'Enter first number: ', '$'
    msg3 db 'The output is: ', '$'
    crlf db 0dh, 0ah, '$'
    
    
    num1digit1 db ?
    num1digit2 db ?            
    num2digit1 db ?        
    num2digit2 db ?
                       
    
                       
            
.code        
.startup     
    
    
    ; Show prompt for inputting first number
             
    mov ah, 9
    lea dx, msg1
    int 21h         
    
     
                                                         
                                                         
    ; Take input of the first digit for the first number         
    
    mov ah, 1
    int 21h
    mov num1digit1, al
    sub num1digit1, 30h
                
    
    
    ; Take input of the second digit for the first number                   
                       
    mov ah, 1
    int 21h
    mov num1digit2, al
    sub num1digit2, 30h          
                       
                               
                               
                               
    ; Move cursor to a new line                       
             
    mov ah, 9
    lea dx, crlf
    int 21h
             
                               
                               
    
    ; Prompt for input of second number    
        
    mov ah, 9
    lea dx, msg2
    int 21h
    
                               
                               
    
    ; Take input of the first digit for the second number
    
    mov ah, 1
    int 21h
    mov num2digit1, al
    sub num2digit1, 30h
                                    
                                    
                                    
    
    ; Take input of the second digit for the second number
        
    mov ah, 1
    int 21h
    mov num2digit2, al
    sub num2digit2, 30h
     
        
                       
    ; Move cursor to new line
             
    mov ah, 9
    lea dx, crlf
    int 21h
                       
                       
    ; show output message
                
    mov ah, 9
    lea dx, msg3
    int 21h     
    
    
    ;Print the first result digit
    
    mov ah, 2
    mov cl, num1digit1
    sub cl, num2digit1
    mov dl, cl
    add dl, 30h    
    int 21h
        
        
        
    ;Print the second result digit    
   
    mov ah, 2
    mov cl, num1digit2
    sub cl, num2digit2
    mov dl, cl
    add dl, 30h
    int 21h  
    
                    
     
.exit

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s