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.

Wednesday, June 27, 2018

Tutorial On Using 555 Timer IC As PWM Generator

Welcome, 555 Timer is a versatile timer IC which can perform different operations and has thousands of applications in industry. Today we are going to learn that how can we use 555 timer as PWM generator. Pulse Width Modulation often refered to as PWM, is as the name suggests, is a type of modulation in which we vary the width of digital signal, be it voltage or current, while frequency of output signal remains constant. When the pulse is varied with the passage of time average output voltage change occurs. You can learn more about PWM in power electronics section where PWM finds numbers of applications.


Here in this circuit 555 timer is configured as Astable multi-vibrator with controlled signal, so when the control signal is changed output pulse is changed with constant frequency.

Required Parts:



  • 555 Timer IC
  • Resistors 1k x 2
  • Resistor 10k 
  • Resistor 540 Ohm
  • LED 
  • Potentiometer 10k
  • Capacitor 4.7uf 
  • Breadboard
  • 9 Volt Battery
Please Click on images to view Larger. 
Breadboard Assembly:

Working circuit of 555 Timer IC as Pulse Width Modulation Generator with 9 Volts battery


Schematic Diagram:


Complete Schemetic of 555 Timer as PWM Generator


Questions and suggestions are welcomed in comments sections.

Thursday, June 21, 2018

How to add two double digit Decimal numbers in 8086 assembly | The Easy Way


This program adds two double digits numbers the easy way. Click to download source code
; CODE BEGINS

TITLE TWO_DIGIT_ADDITION 
.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 
         
        LEA DX, DIGIT1 
        MOV AH, 09H 
        INT 21H 
         
        MOV AH, 01H 
        INT 21H 
         
        SUB AL, 30H 
        MOV BH, AL 
         
        MOV AH, 01H 
        INT 21H 
         
        SUB AL, 30H 
        MOV BL, AL ; BH:BL FIRST NUMBER 
         
        LEA DX, DIGIT2 
        MOV AH, 09H 
        INT 21H 
         
        MOV AH, 01H 
        INT 21H 
         
        SUB AL, 30H 
        MOV CH, AL 
         
        MOV AH, 01H 
        INT 21H 
         
        SUB AL, 30H 
        MOV CL, AL ; CH:CL SECOND NUMBER 
         
        ADD BL, CL 
         
        MOV AL, BL 
        MOV AH, 00H 
        AAA 
         
        MOV CL, AL ; LAST DIGIT OF ANSWER 
        MOV BL, AH 
         
        ADD BL, BH 
        ADD BL, CH 
         
        MOV AL, BL 
        MOV AH, 00H 
        AAA 
         
        MOV BX, AX 
       ;MOV BH, AH 
       ;MOV BL, AL 
        
        MOV DX, OFFSET RESULT 
        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 
    EXIT: 
        MOV AH, 04CH 
        INT 21H 
    END MAIN     
         
         
; CODE ENDS


FOLLOWING IS THE OUTPUT OF THE PROGRAM

OUTPUT OF MULTI DIGIT ADDITION PROGRAM WRITTEN IN ASSEMBLY LANGUAGE FREE SOURCE CODE DOWNLOAD

Tuesday, June 19, 2018

8086 Program To Print Text In Assembly

for code explanation please follow how to print text in 8086 assembly code. Thanks



; CODE BEGINS

TITLE TEXT_MESSAGE 
.MODEL SMALL 
.STACK 100H 
.DATA 
 
    MSG DB 0AH, 0DH, "TEXT MESSAGE$" 
.CODE 
    MAIN: 
        MOV AX, @DATA 
        MOV DS, AX 
         
        MOV DX, OFFSET MSG 
        MOV AH, 09H 
        INT 21H        
         
  ;     LEA DX, MSG 
  ;     MOV AH, 09H 
  ;     INT 21H 
         
         
         
         
         
    EXIT:     
        MOV AH, 04CH 
        INT 21H 
    END MAIN 
; CODE ENDS

Following is the output of the program

Output of assembly program which show how the text or character string can be printed in assembly language

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