Experiment No: 1
(i)
Experiment Name: Input and Output in assembly.
Objectives: To be able to take an input and print as an output.
Apparatus: MICROPROCESSOR EMULATOR 8086, Computer etc
Introduction: In assembly it is not possible to take a number containing more than one digits at at a time or not possible to show a number containing more than one digit at once. We have to take user input one by one character and also print by one. So it is little bit difficult. Let’s see a program that will take a simple user input and will print the output.
We have to assign a value in 'AH' register and then occur an interrupt to take user input or show output in assembly.
For single character input we have to put '1' in AH
For single character output we have to put '2' in AH
For string output, put '9' in AH
Then call an interrupt to happen this. Generally call ‘INT 21H' for input and output.
Procedure:
1. Create: open emu8086 write a program after that save the program with .asm extension.
2. Compile: Emulator
3. Execute: Run
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
.MODEL SMALL .STACK 100H .DATA PROMPT_1 DB 'Enter the Number : $' PROMPT_2 DB 0DH,0AH,'The Number is : $' .CODE MAIN PROC MOV AX, @DATA ; initialize DS MOV DS, AX LEA DX, PROMPT_1 ; load and print PROMPT_1 MOV AH, 9 INT 21H MOV AH, 1 ; read a Number INT 21H MOV BL, AL LEA DX, PROMPT_2 ; load and print PROMPT_2 MOV AH, 9 INT 21H MOV AH, 2 ; print the Number MOV DL, BL INT 21H MOV AH, 4CH ; return control to DOS INT 21H MAIN ENDP END MAIN |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
.MODEL SMALL .STACK 100H .DATA PROMPT DB 'The counting from 0 to 9 is : $' .CODE MAIN PROC MOV AX, @DATA MOV DS, AX LEA DX, PROMPT MOV AH, 9 INT 21H MOV CX, 10 MOV AH, 2 MOV DL, 48 @LOOP: INT 21H INC DL DEC CX JNZ @LOOP MOV AH, 4CH INT 21H MAIN ENDP END MAIN |