introduction:

In other programming languages such as C/C++ int command is basically a data type “integer” and int can be input from user or defined value but in emu8086 int (interrupt) command is little bit different so in assembly language we used it to read a character from keyboard, to display a  character or string on the screen by placing it into a specific register. The AH register is used to pass I/O information.

Write a code to enter a character from keyboard

org 100h
mov ah,1h       ;used to enter character from keyboard
int 21h             ;most commonly used command to read
                        ;character into al
mov ax,4c00h  ;return the command back to emulator
int 21h
ret

Now run this code

For first line we move 01h in ah

after int 21h it starts asking for enter character on black screen

so if enter ‘a’ then we can see ‘a’ written on the screen but we can’t re-write it on black screen and to return the code back to emu use register ax,4c00h

Write a code to display a character ‘a’ on the screen

org 100h
mov dl,’a’             ;it stores ascii code of a in dl
mov ah,3h           ;emu character output function
int 21h                 ;display character in dl register

mov ax,4c00h     ;return command back to emu
int 21h
ret

Let’s run the code

we can see that in dl we got 61 which is ascii of ‘a’ and ah,3h is emu output character functions.

Write a program to read a character from keyboard and display it on the screen

org 100h
mov ah,1h
int 21h

mov dl,’*’
mov ah,2h
int 21h

mov ax,4c00h
int 21h
ret

Let’s run the code

First part is used to take input from the keyboard, second part is used take ascii code of ‘*’ in dl and 2h is used to dispaly it on the black screen while third part is used to return the command and final output is look like if enter ‘a’ in first portion

Write a code to display “?B B” on screen

org 100h
mov dl,’?’
mov ah,2h
int 21h

mov ah,1h
int 21h

mov bl,al
mov dl,’ ‘
mov ah,2h
int 21h

mov dl,bl
mov ah,2h
int 21h

mov ax,4c00h
int 21h
ret

Let’s run the code

In the first portion we enter the character ? through keyboard in the second portion we enter B and then we copy that value by swapping method.

so its final output is