Pretty simple program I got here, using TASM and 8086, it basically waits for a user input and prints out whatever was inputed.

.model small

.stack 100h

.code

start:

mov ah, 01h ; keyboard input subprogram
int 21h ; read character into al
mov dl, al

mov ah, 2h ; display subprogram
int 21h ; display character in dl
mov ax, 4c00h ; return to ms-dos
int 21h

jmp start

end start

The problem is it only does it once. For fun sake I want it to loop forever so I added the jmp start, however it still only does it once, it doesn't loop. Can somebody please explain what I'm missing?
Posted on 2009-10-11 18:50:01 by dre
The sequence mov ax, 4c00h -> int 21h kind of means exit program. Therefore it never goes to your jmp start.

try this:


.model small
.stack 100h
.code

start:

beginloop:
mov  ah, 01h  ; keyboard input subprogram
int  21h    ; read character into al
mov  dl, al

; new stuff here
cmp al, 0dh ; carriage return
jz exit

mov  ah, 2h  ; display subprogram
int  21h    ; display character in dl
jmp beginloop

exit:
mov  ax, 4c00h ; return to ms-dos
int  21h

end start


Added a check for carriage return. so if you enter a return it jumps to exit any other char it will go back to beginloop.
Posted on 2009-10-11 19:01:35 by JimmyClif
Thanks...out of curiosity why wouldn't sticking the jmp start before the mov ax, 4c00h do the trick?

edit: just tested, the code you posted still only does it once.
Posted on 2009-10-11 19:07:06 by dre
What JimmyClif did was add a jump before the exit routine and makes use of the carriage return that appears when you hit enter to cause the program to exit. What JimmyClif did was correct as you really shouldn't ever have a program that doesn't have a way out. But if you are just playing around, remove the exit code from your program and let it go wild.. just don't ever do that in a "real" program.

.model small

.stack 100h

.code

start:

mov  ah, 01h  ; keyboard input subprogram
int  21h    ; read character into al
mov  dl, al

mov  ah, 2h  ; display subprogram
int  21h    ; display character in dl

; exit to dos routine removed.

jmp start

end start
Posted on 2009-10-11 19:58:54 by Synfire
Thanks for the reply, unfortunately it still stops after one character input.
Posted on 2009-10-11 20:18:01 by dre
Not sure what's happening on your end then.. I just coded up the equivalent in NASM and tossed it through DosEmu and it worked as expected.

	BITS 16
ORG 100h

Start: Mov Ah, 01h
Int 21h

Mov Dl, Al
Xor Ax, Ax
Mov Ah, 2h
Int 21h
Jmp Start
Posted on 2009-10-11 21:29:44 by Synfire
As much as it annoyed me farting around in debug... here's a screenshot:
Attachments:
Posted on 2009-10-11 21:34:39 by JimmyClif
Wow so weird..I just put jmp start in between every line following the start: label and it still executes the exact same way. It's as if it doesn't recognize the jmp command or something lol.

EDIT: Just tested by typing in gibberish into random parts of my program to see if an error would be generated and it compiles perfectly and runs the way it has been for the last several hours. I'm guessing something has gone wrong with the compiler or the compilation process. Does anybody know what is going on here?  Does something like that happen often?

EDIT 2: Just created a new notepad and copied and pasted and it's working now...very weird how that happened. Thanks guys!
Posted on 2009-10-11 23:22:41 by dre
I'm not sure what compiler you are using, but I get similar issues some times when working with 'gmake'. It, for some reason or another, won't want to update the object file and I have to forcefully 'rm -rf *.o' to get a clean build.
Posted on 2009-10-12 00:04:02 by Synfire
Try this code:

.model small
.stack 100h

.code

start:

mov  ah, 01h  ; keyboard input subprogram
int  21h    ; read character into al
mov  dl, al

mov  ah, 2h  ; display subprogram
int  21h    ; display character in dl

; exit to dos routine removed.
cmp al,0dh
je exit
jg start

exit: mov ax,4c00h
      int 21h

end start
Posted on 2009-10-13 16:23:52 by web4