Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 12

Input and Output Instructions

The INT Instruction


• To invoke a DOS or BIOS, the INT (interrupt)
instruction is used.
INT interrupt_number
INT 21h
• INT 21H, Function 04CH terminate the code properly and return
to the DOS Prompt.

• INT 21H, Function 02H Display a number or character on the


screen.

• INT 21H, Function 09H Display the string on the screen

• INT 21H, Function 01H Get Character input with Echo.

• INT 21h, function 08H Get Character input without Echo.


Functions 01 - Read a character input with Echo from
keyboard
 
Reads a character from the standard input device and echoes it to the standard
output device. If no character is ready it waits until one is available.

 
MOV ah, 01H; input key function
 
INT 21H; get ASCII code in AL
 
On entry: Ah= 01H
Returns: AL= 8 bit data input.
 
When a character is pressed, AL will contain its ASCII code if any other key is
pressed, such as an arrow key or F0-F10 and so on, AL will contain 0.
Function 02 - Display a Character on Screen

To display a character “A‟ on screen execute the following instruction, actually DL must
contain the ASCII code of Character that is to be displayed. In this example DL will
contain ASCI code of “A‟.
 
MOV AH, 2; display character function
MOV DL, “A‟; character is “A
INT 21H ; display character

On entry:
AH = 02h
DL = 8 bit data (usually ASCII character)

Returns:
Nothing
 
 
Function 08 - Read a character input without
Echo from keyboard
Reads a character from the standard input device without copying it
to the display. If no character is ready it waits until one is available.
 
MOV AH, 08h ; Input key function
INT 21h ; get ASCII code in AL.
On entry: Ah= 01H
Returns: AL= 8 bit data input.
Function 09 - Display a string on Screen
To display a String execute the following instruction, DX register must
contain the starting offset Address of string that to be displayed
 LEA DX, msg; get offset address of msg
OR
 MOV DX, offset msg ; get offset address of msg.
 
MOV AH, 9; string Display function
Int 21h; Display msg
 
  On entry: Ah= 09H
DS: DX = segment: offset of string
 
Returns: Nothing.
 
 Where msg is string define in Data Segment as
 
Msgdb‟hello world‟, 0Ah, 0Dh, “$‟ or
Msgdb “hello world” ,13h,10h,24h
Displaying an integer 0-9
• We can print character only
• Ascii of 0-9 is 30h-39h respectively
• First convert the didgit inro its ascii by adding
30h then print it like a character
Input two numbers from user .. Adding them and displaying them
; taking input 1 saving in bh
mov ah,1
int 21h
mov bh,al

; taking input 2 saving in bl


mov ah,1
int 21h
mov bl,al

add bh,bl ; adding them


sub bh,30H ; getting its ascii

; displaying the result


mov dl,bh
mov ah,2
int 21h
Read a character and display it on the next
line
Displaying a string
Reference
• Chap 4 complete
• Go through Case Conversion program 4.12
• Do short exercises 1-7

You might also like