-3

Write a complete program in real-address mode that:

  1. Prompts the user to read from the keyboard one uppercase letter between K and P.
  2. Validates the input and if the character is not in the range prompt the user again and again until a valid character is entered.
  3. Displays the 5 neighboring letters on each side.

For example, if the user enters a letter ‘M’ then the output would be: HIJKL M NOPQR. i try on solve it but my answer is wrong

include irvine16.inc

.data
M1 byte "Enter one upper case letter between K and P : $"
letter byte 1,?,1

.code
main PROC
  mov ax, @data
  mov ds, ax

L1: mov ah,9 ;display msg m1
  lea dx,M1
  int 21h

mov ah,01h ;read a char
lea dx,letter
int 21h

mov bl,letter
CMP bl,'K'
Jb L1
CMP bl, 'P'
Ja L1


mov cx,5
lea si, letter
L3:
 dec si
loop L3

mov cx,11
lea si, letter
L2: sub si,5
  mov ah,05h
int 21h

LOOP L2



mov ah, 4ch
int 21h

main ENDP
END main
rkhb
  • 14,159
  • 7
  • 32
  • 60
BLACKY
  • 3
  • 2

2 Answers2

3

That's not how int 21h / function 01h works. The character is returned in AL:

mov ah,01h ;read a char
int 21h

cmp al,'K'

This code makes no sense:

mov cx,5
mov  bl  
L3:
dec si 
loop L3

It won't assemble since mov bl isn't a valid istruction. Even if it did, it serves no purpose.


mov ah,05h
int 21h

That's not the function you want. To write a character to the standard output you should use function 02h with the character placed in DL.

Michael
  • 57,169
  • 9
  • 80
  • 125
0

Maybe you also should consider pushing valuable registers before interruption and poping them back after. I don't quite remember how all of 21h functions work, but AFAIR some might affect for example cx register resulting in unpredictable loops.

akalenuk
  • 3,815
  • 4
  • 34
  • 56