Simple Echo Program for Character Input and Display Using DOS Interrupts
130 likes | 252 Vues
This guide provides a straightforward implementation of an echo program using assembly language for microprocessors. It demonstrates how to read a character from the keyboard and display it on the next line using DOS interrupts. The program uses BIOS function calls to facilitate input/output operations, including displaying a question mark as a prompt and processing carriage return and line feed for proper formatting. Steps include assembling the source code, linking object files, and creating an executable file.
Simple Echo Program for Character Input and Display Using DOS Interrupts
E N D
Presentation Transcript
1st prog! Q: Read a char – from a keyboard & display it at the beginning of the next line! ====== A A
Display a question mark: MOV AH, 2 ;display character fn. – p.456 DOS Interrupts – Function 2h display output to standard output device I/P: AH = 02h o/p: DL = character
MOV DL, ‘?’ ; char is ‘?’ • It moves 3Fh [‘?’] into DL INT 21h ; display character • Next read a char. MOV AH, 1 ; read char fn • Fn 1h Keyboard input INT 21h ; char in AL
Now display the char on the next line: [the char MUST be saved in another register] MOV BL, AL ; save it in BL Why? We move the input character from AL to BL – as the INT 21h, function 2 changes AL.
To move the cursor to the beginning of the next line, we must execute a carriage return and line feed. So, put the ASCII codes for them in DL and execute INT 21h MOV AH, 2 ; display char fn [আগের] MOV DL, 0Dh ; for carriage return INT 21h ; execute carr ret. MOV DL, 0Ah ; for line feed INT 21h ; execute line feed
So full prog TITLE Echo prog .MODEL SMALL .STACK 100h .CODE MAIN PROC ; make a comment for a block MOV AH, 2 ; display char func … … ; another block… … … ; return to DOS MOV AH, 4Ch ; DOS exit func INT 21h ; exit to DOS MAINENDP END MAIN
RUN! • Create the source program file – in a word proc/text/… [*.asm file] • Assemble the prog using an Assembler [*.obj file] • Link object program – to link one or more obj files to create a run file [*.exe file]
Do/Read 4.11 Displaying a string INT 21h , Function 1 to read a single char Function 2 to display a single char Function 9 to display a string Input: DX = offset address of string The string must end with a ‘$’ char
LEA • LEA – Load Effective Address - puts a copy of the source offset address into the dest. LEA DX, MSG - Puts the offset address of the variable MSG into DX
Read 4.12 A case conversion prog. lowercase to UPPER UPPER to lover
Chapter 4 – finish the exercises Chapter 5 – next