org 100h

mov ah, 09h
mov dx, entername
mov cx, 16
int 21h


getname:

mov ah, 00h ; keyboard input subprogram

int 16h ; character input 

mov [si], al
inc si

jmp getname
printstrg:

mov ah, 09h
mov dx, nameis
int 21h
mov ah, 09h
mov dx, si
int 21h
nameis db 13, 10 , "Your Name IS: ", 0
entername db "Enter Your Name: ", 0

What IS WRONG!!!:(

Dani AI

Generated

This program fails for a few separate reasons. correctly flagged the unconditional jump that keeps execution trapped in the input loop; 's idea of jumping to the print routine would exit that loop but still leaves other bugs. Additional faults are: SI is never initialized so writes go to an unpredictable address; the DOS print service used (INT 21h AH=09) requires a '$' terminator (not NUL); the code never tests for Enter or bounds and thus can overflow the buffer; CX is irrelevant to function 09.

Practical fixes: reserve a fixed input buffer and initialize pointer registers before storing bytes; either use DOS buffered input (INT 21h AH=0Ah) which returns the length in the second byte, or implement a character loop that checks AL==0Dh (CR) to terminate. If AH=09 is kept for output, append a '$' after the entered characters first. When using BIOS INT 16h for raw key reads, echo and backspace handling must be implemented explicitly. Always check the input length to avoid overruns and terminate the program with INT 21h AH=4Ch.

A concise example that uses the DOS buffered-read service and then prints the line (adjust the sizes to match the desired maximum):

org 100h

mov ah, 09h
mov dx, prompt
int 21h

mov dx, namebuf
mov ah, 0Ah
int 21h

mov si, namebuf+2
mov cl, [namebuf+1]
xor ch, ch
add si, cx
mov byte [si], '$'

mov dx, namebuf+2
mov ah, 09h
int 21h

mov ah, 4Ch
int 21h

prompt db 'Enter name: $'
namebuf db 20,0,20 dup(0)

Notes: ensure the data segment is correct for the chosen assembler/linker (COM programs normally run at ORG 100h with DS set to the program segment), and test the build under a real DOS environment or DOSBox.

Recommended Answers

All 2 Replies

what is the problem? What does it do that you don't want it to do? Does it assemble without errors? If not what are the error messages?

I can see that line 18 is a non-conditional jump which will cause an infinite loop.

Ancient Dragon is right you have to find a place to add this;

jmp printstrg

or else your code will never get to line 21

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.