Showing posts with label 8086 assembly code. Show all posts
Showing posts with label 8086 assembly code. Show all posts

Wednesday, December 1, 2021

Subtraction of two decimal digits in 8086 Microprocessor x86 Assembly Language

Subtraction of two decimal digits in 8086 Microprocessor x86 Assembly Language

This 8086 microprocessor assembly program subtracts two decimal digits and prints the output accordingly. If you want to know how can you print a single character in 8086 assembly language you can find it IN THIS LINK. If you have questions or any problems feel free to ask in the comments section.





TITLE THE_LAME_PROGRAMMER 
.MODEL SMALL 
.STACK 100H 
.DATA 
    DIGIT1 DB 0AH, 0DH, "ENTER FIRST DIGIT: $" 
    DIGIT2 DB 0AH, 0DH, "ENTER SECOND DIGIT: $" 
    RESULT DB 0AH, 0DH, "RESULT IS: $" 
  
.CODE 
 
    MAIN: 
        MOV AX, @DATA 
        MOV DS, AX 
         
        MOV DX, OFFSET DIGIT1 
        MOV AH, 09H 
        INT 21H 
         
        MOV AH, 01H 
        INT 21H 
        SUB AL, 30H 
        MOV BH, AL 
         
        MOV DX, OFFSET DIGIT2 
        MOV AH, 09H 
        INT 21H 
         
        MOV AH, 01H 
        INT 21H 
        SUB AL, 30H 
        MOV BL, AL 
         
        CMP BH, BL 
         
        JL MINUS 
         
        SUB BH, BL 
         
        MOV DX, OFFSET RESULT 
        MOV AH, 09H 
        INT 21H 
         
        MOV DL, BH 
        ADD DL, 30H 
        MOV AH, 02H 
        INT 21H 
         
        JMP EXIT 
         
   MINUS: 
        SUB BL, BH 
         
        MOV DX, OFFSET RESULT 
        MOV AH, 09H 
        INT 21H 
         
        MOV DL, '-' 
        MOV AH, 02H 
        INT 21H 
         
        MOV DL, BL 
        ADD DL, 30H 
        MOV AH, 02H 
        INT 21H 
         
   EXIT: 
        MOV AH, 04CH 
        INT 21H 
   END MAIN 


OUTPUT OF THE PROGRAM
Subtraction of decimal digits in 8086 assembly Language














Subtraction of decimal digits in 8086 assembly Language


Thursday, November 18, 2021

Find Cube | 8086 Microprocessor Assembly Language Program

 This x86 Assembly Language program takes users input in 8086 Microprocessor Assembly Language and prints the cube of it.

To run this x86 Assembly Code you need to Download emu8086 software. Copy the following 8086 microprocessor Assembly Language code and paste this code to emu8086 and hit the play button.

TITLE PUCHTAA
.MODEL SMALL
.STACK 100H
.DATA


    MSG DB 0AH, 0DH, "ENTER A NUMBER TO FIND CUBE OF IT: $"
    OUT1 DB 0AH, 0DH, "CUBE OF $"
    OUT2 DB " IS $"
    QUIT DB 0AH, 0DH, "CONTINUE? Y FOR YES ELSE FOR NO: $"
   
.CODE
   
    MAIN:
        MOV AX, @DATA
        MOV DS, AX
    AGAIN:
        LEA DX, MSG
        MOV AH, 09H
        INT 21H
       
       
        MOV AH, 01H
        INT 21H
       
        PUSH AX
       
        CMP AL, 39H
        JG AGAIN
        CMP AL, 30H
        JL AGAIN
       
        PUSH AX
        PUSH AX
       
        SUB AL, 30H
        MOV BL, AL
        MUL BL
        AAM
               
        MOV BX, AX ; BH = 06, BL, 04 ; IF ENTERED 08
       
        POP AX
       
        SUB AL, 30H
       
        MUL BL
       
        AAM
       
        MOV CL, AL ; FIRST RESULT
        MOV CH, AH ;CARRY
        POP AX
       
        SUB AL, 30H
        MOV BL, AL
        MOV AL, BH
        MUL BL
        AAM
       
        ADD AL, CH
        AAA
       
        MOV BX, AX
       
       
        LEA DX, OUT1
        MOV AH, 09H
        INT 21H
       
        POP DX
        MOV AH, 02H
        INT 21H
       
        LEA DX, OUT2
        MOV AH, 09H
        INT 21H
       
        MOV DL, BH
        ADD DL, 30H
        MOV AH, 02H
        INT 21H
       
        MOV DL, BL
        ADD DL, 30H
        MOV AH, 02H
        INT 21H
       
       
        MOV DL, CL
        ADD DL, 30H
        MOV AH, 02H
        INT 21H
       
              
        LEA DX, QUIT
        MOV AH, 09H
        INT 21H
       
        MOV AH, 01H
        INT 21H
        OR AL, 20H
        CMP AL, 'y'
        JE AGAIN
       
        MOV AH, 04CH
        INT 21H
  END MAIN


OUTPUT 

Find Cube | 8086 Microprocessor Assembly Language Program












TAGS:

  • assembly language
  • emu8086
  • assembly code
  • assembly language programming
  • x86 assembly
  • assembly language example
  • cube of number assembly language

Friday, November 12, 2021

8085/8086 Microprocessor Assembly Language Program to Find Square of a Number

This 8085/8086 microprocessor assembly language program asks users to input a number and finds out the square of a number and then prints it. This 8085/8086 microprocessor assembly language program has one more feature by which it doesn't accept any value other than decimal numbers and asks users if they want to quit the program or not 

TITLE PUCHTAA
.MODEL SMALL
.STACK 100H
.DATA


    MSG DB 0AH, 0DH, "ENTER A NUMBER TO SQUARE IT: $"
    OUT1 DB 0AH, 0DH, "SQUARE OF $"
    OUT2 DB " IS $"
    QUIT DB 0AH, 0DH, "CONTINUE? Y FOR YES ELSE FOR NO: $"
   
.CODE
   
    MAIN:
        MOV AX, @DATA
        MOV DS, AX
    AGAIN:
        LEA DX, MSG
        MOV AH, 09H
        INT 21H
               
        MOV AH, 01H
        INT 21H
       
        PUSH AX
       
        CMP AL, 39H
        JG AGAIN
        CMP AL, 30H
        JL AGAIN
       
        PUSH AX
       
        SUB AL, 30H
        MOV BL, AL
        MUL BL
        AAM
               
        MOV BX, AX
       
        LEA DX, OUT1
        MOV AH, 09H
        INT 21H
       
        POP DX
        MOV AH, 02H
        INT 21H
       
        LEA DX, OUT2
        MOV AH, 09H
        INT 21H
       
        MOV DL, BH
        ADD DL, 30H
        MOV AH, 02H
        INT 21H
       
        MOV DL, BL
        ADD DL, 30H
        MOV AH, 02H
        INT 21H
       
        LEA DX, QUIT
        MOV AH, 09H
        INT 21H
       
        MOV AH, 01H
        INT 21H
        OR AL, 20H
        CMP AL, 'y'
        JE AGAIN
       
        MOV AH, 04CH
        INT 21H
    END MAIN

Friday, October 8, 2021

How To Print A Single Character in 8086 Assembly Language

 If you are getting started with 8086 assembly programming, you might encounter the elementary and very beginning program of your life, which is “how to print text in 8086 assembly language”. However, in most cases, the next step is to print a single character in the 8086 assembly language.


In an 8086 assembly language computer always works with registers of the microprocessor. in intel’s 8086 microprocessor, there are four basic general-purpose or data registers i.e.


Accumulator Register (AX)

Base Register (BX)

Counter Register (CX)

Data Register (DX)


Above mentioned registers are 16bit registers which means they consist of two bytes. These registers are further broken into ‘high byte’ and ‘low byte'. We can use them for any purpose we want. Look at the table below.



8086_General_Purpose_Registers


There are other types of registers as well, but for now, we will stick to them.



Now that we have an overview of Data registers, we can now write a simple assembly language program that prints single character output. 


First, we write our basic program template, which does nothing but is very important and will always be used in each assembly program.


TITLE SINGLE_CHARACTER_PRINTING

.MODEL SMALL

.STACK 100H

.DATA


;;THIS IS DATA SECTION



.CODE   


;THIS IS CODE SECTION

    MAIN:

        MOV AX, @DATA

        MOV DS, AX

        

        

            

        

        

        MOV AH, 04CH

        INT 21H

   END MAIN


If you don’t understand or want to understand more basics, you can follow this link for the instructions used in this program.


In the 8086 assembly language, a single character means one byte. Let’s say we want to print ‘A’ first, we need to move it to the data register, which is DX, and ‘A’ is one byte so that we will place it in the DL register. If you are confused, remember that if you want to print a single character, always move it to the ‘DL’ register.



MOV DL, ‘A’

MOV AH, 02H

INT 21H


Just add three lines in the above code, and you will see the output of the program. If you don't understand MOV AH, 02H and INT 21H, just go with it as at this point there is no need to get stuck to it. Just remember we write these three statements to display a single character. You just need to replace the ‘A’ in DL if you want to print something else.


Following is the complete code of above program


TITLE SINGLE_CHARACTER_PRINTING
.MODEL SMALL
.STACK 100H
.DATA

;;THIS IS DATA SECTION

.CODE   

;THIS IS CODE SECTION
    MAIN:
        MOV AX@DATA
        MOV DSAX
        
        MOV DL'A'
        MOV AH02H
        INT 21H
                        
        MOV AH04CH
        INT 21H
   END MAIN

You should see output of the program as 'A'


If you have any question or trouble you can always choose to click Ask for Help section mentioned above.

Saturday, May 16, 2020

How to Print Sum of Series in Assembly Language


This Program Prints the sum of a series, of a number which is input by the user.



TITLE PUCHTAA 
.MODEL SMALL 
.STACK 100H 
.DATA 
    INTRO DB 0AH, 0DH, 07H, 09H, "THIS PROGRAM PRINTS THE SUM OF SERIES$" 
    MSG DB 0AH, 0DH, "ENTER A NUMBER: $" 
    NEWLINE DB 0AH, 0DH, "$" 
    DOAGAIN DB 0AH, 0DH, "DO AGAIN? Y FOR YES ELSE FOR NO: $" 
.CODE 
 
    MAIN: 
        MOV AX, @DATA 
        MOV DS, AX 
 
        LEA DX, INTRO 
        MOV AH, 09H 
        INT 21H 
 
         
    NUMBER:     
        LEA DX, MSG 
        MOV AH, 09H 
        INT 21H 
         
        MOV AH, 01H 
        INT 21H 
         
        SUB AL, 30H 
        CMP AL, 09H 
        JG NUMBER 
         
         
        MOV BL, AL 
        MOV BH, AL 
        PUSH BX 
        CMP AL, 00H 
        JE RESULT 
   AGAIN: 
         
         
        DEC BL 
        ADD BH, BL 
        CMP BL, 00H 
        JG AGAIN 
         
        MOV AH, 00H 
        MOV AL, BH 
        MOV BL, 0AH 
        DIV BL 
        MOV BX, AX 
        POP CX 
  RESULT:       
        LEA DX, NEWLINE 
        MOV AH, 09H 
        INT 21H 
        MOV CH, 00H 
         
  DISPLAY: 
        MOV DL,CH 
        ADD DL, 30H 
        MOV AH, 02H 
        INT 21H 
         
        MOV DL, '+' 
        MOV AH, 02H 
        INT 21H 
         
        INC CH 
        CMP CH, CL 
        JLE DISPLAY  
         
         
        MOV DL, 08H 
        MOV AH, 02H 
        INT 21H 
         
        MOV DL, '=' 
        MOV AH, 02H 
        INT 21H 
         
         
         
        MOV DL,BL 
        ADD DL, 30H 
        MOV AH, 02H 
        INT 21H       
         
        MOV DL, BH 
        ADD DL, 30H 
        MOV AH, 02H 
        INT 21H 
         
        LEA DX, DOAGAIN 
        MOV AH, 09H 
        INT 21H 
         
        MOV AH, 01H 
        INT 21H 
        OR AL, 20H 
        CMP AL, 'y' 
        JE NUMBER 
         
         
        MOV AH, 4CH 
        INT 21H 
    END MAIN 

OUTPUT of the program

Sum of Series Programming in Assembly Language
  • assembly language program for sum of series
  • sum of series in assembly language
  • series addition azevedotechcrunch

Click to Download Code

Download

Sunday, June 23, 2019

How To Print Text In 8086 Assembly : Code Explained





This program prints simple text on screen in 8086 assembly language. Click to download the code

Printing a text in assembly language is very easy.

In assembly language we need to build a logic and then write a program. In this program we only need to print a simple message for which we have written this code.

1.      First we write the title of program so that we can understand the purpose of program

   TITLE TEXT_MESSAGE

2.      Then we define the model, model is the part of program which tells assembler which model we need to use for our program. In this program we are using SMALL,  but there are many like TINY, SMALL and LARGE

   .MODEL SMALL

3.      Then we define the stack of program. STACK usually tells assembler that how much bytes we need to use for our DATA SEGMENT (explained later). In this program we have used 100 bytes in hexadecimal

   .STACK 100H
4.      Now comes the DATA SEGMENT, which, we define as .DATA. in DATA SEGMENT  we store our variables and temporary data. For example our temporary bytes. In this program we have stored an array of characters containing our message.

That’s how you define a array of characters (string) in assembly.

NAME
TYPE

“MESSAGES$”
MSG
DB
0AH, 0DH, "TEXT MESSAGE$"

MSG is the name of message you can have any name, DB is DEFINE BYTE (will be explained further in variables section) and then our text message. You notice 0AH and 0DH these bytes are for carriage return and line feed, now the message which is in quotes, be careful for dollar sign ($), which is string terminator, do not forget to add it after every message.


5.      After setting up DATA SEGMENT, CODE SEGMENT starts, which tells assembler that our program has been started. We define CODE SEGMENT same as we defined DATA SEGMENT.

.CODE

In the code segment first we define a label from which our program starts, in this program we have defined MAIN: with colon. Then we move starting address of DATA SEGMENT by using AX register in to DS register (will be explained later programs). First move address to AX register then mov it back to DS register.

MOV AX, @DATA
MOV DS, AX


6.      To print the message we need to move its address to DX register there are two way to do it but we will use OFFSET command to do it. After moving address to DX register we store 09H byte in AH register to tell assembler that we want to print a string. Now we invoke interrupt service routine by using INT 21H

MOV DX, OFFSET MSG
MOV AH, 09H
INT 21H
      
7.      Now that we have completed the task of string printing we need to tell assembler that where to end the program for this we simply define another label name EXIT: with colon and move 4CH byte in AH register and invoke INT 21H after this we use END MAIN (without colon)

EXIT:    
        MOV AH, 04CH
        INT 21H
END MAIN

Here is the complete program.

Saturday, June 16, 2018

Table Printing In 8086 Assembly With User Input | Version 2

Following code prints the table of the number which the user inputs. This program is an updated version of my previous program. In this program, I have adjusted output formatting as well.
 Feel free to copy the code and use it for your projects and assignments. Furthermore, if you have any queries do let me know in the comments section. Thanks



[READ BEFORE YOU PROCEED] IF YOU ARE A BEGINNER AND LOOKING FOR A SIMPLE TEXT PRINTING PROGRAM. A GREAT TUTORIAL WITH EXPLANATION IS LINKED HERE


[CODE]
TITLE TABLEPRINTING 
.MODEL SMALL 
.STACK 100H 
.DATA 
    MESSAGE DB 0AH, 0DH, "ENTER A NUMBER: $" 
    NOTPROCESS DB 0AH, 0DH, "NOT A VALID DIGIT, CANNOT PROCES$" 
    AGAIN DB 0AH, 0DH, "REPEAT?(Y/N): $" 
.CODE 
 
    MAIN: 
        MOV AX, @DATA 
        MOV DS, AX 
         
        LEA DX, MESSAGE 
        MOV AH, 09H 
        INT 21H 
         
        MOV AH, 01H 
        INT 21H 
         
        MOV CH, 0AH 
        MOV CL, 00H       
         
        CMP AL, 3AH 
        JGE NOT_PRO 
        SUB AL, 30H 
        MOV BH, AL 
        MOV BL, 01H 
  NEXT: 
                    
        MOV DL, 0DH 
        MOV AH, 02H 
        INT 21H            
         
        MOV DL, 0AH 
        MOV AH, 02H 
        INT 21H            
         
        MOV DL, '0' 
        MOV AH, 02H 
        INT 21H 
         
         
        MOV DL, BH 
        ADD DL, 30H 
        MOV AH, 02H 
        INT 21H 
         
        MOV DL, '*' 
        MOV AH, 02H 
        INT 21H 
         
         
        MOV AL, BL 
        MUL BH 
         
        AAM 
         
        PUSH AX 
        
         
        MOV AH, 00H 
        MOV AL, BL 
        AAA 
         
         
         
        MOV CL, AH 
        MOV BL, AL 
         
         
        MOV DL, CL 
        ADD DL, 30H 
        MOV AH, 02H 
        INT 21H 
         
        MOV DL, BL 
        ADD DL, 30H 
        MOV AH, 02H 
        INT 21H 
         
  RESULT:       
        MOV DL, '=' 
        MOV AH, 02H 
        INT 21H 
         
        ;----------------------- 
         
        POP AX 
         
        MOV DH, AL 
        MOV DL, AH 
        ADD DL, 30H 
        MOV AH, 02H 
        INT 21H 
         
        MOV DL, DH 
        ADD DL, 30H 
        MOV AH, 02H 
        INT 21H 
         
         
        ;----------------------- 
         
        INC BL 
        DEC CH 
        CMP CH, 00H 
        JNE NEXT 
        JMP QUESTION 
   NOT_PRO: 
        LEA DX, NOTPROCESS 
        MOV AH, 09H 
        INT 21H 
         
   QUESTION: 
        LEA DX, AGAIN 
        MOV AH, 09H 
        INT 21H 
         
        MOV AH, 01H 
        INT 21H 
         
        OR AL, 20H 
         
        CMP AL, 'y' 
        JNE EXIT 
        JMP MAIN 
   EXIT:          
        MOV AH, 04CH 
        INT 21H
  END MAIN
[/CODE]

output of the program


Output of the assembly program which prints multiplication table of any given number in assembly language

Complete Video Tutorials