Tell me more ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I'm learning x86 assembly in school and have to make a program that prints a string one character at a time. Unfortunately, I can't figure out how to move the location of the next letter I need to print into DL. I've tried just incrementing DL in the loop but that just increments the ascii value of the first letter instead of moving it forward to the next letter. Here's what I have so far:

title prntstr.asm                   

.model small
.386

.data
greeting byte "Hello There! This is DOS.$" greeting_len = ($-greeting)

.code

main PROC
mov ax,@data
mov ds,ax

mov ecx,greeting_len

start_loop:

mov dl,greeting 
mov ah,6
int 21h

loop start_loop

mov ah,4ch
int 21h

main ENDP END main

Can anyone let me know what I have to add inside the loop to get DL to the next memory location?

share|improve this question
3  
This site is for code reviews. "How do I do this?" questions should be asked on stackoverflow. – sepp2k Feb 15 '11 at 5:55
1  
Why close, why not just move? – Felix Dombek Oct 16 '11 at 8:26

closed as off topic by sepp2k, Michael K, Mark Loeser, Robert Cartaino Feb 17 '11 at 14:52

Questions on Code Review Stack Exchange are expected to relate to code review request within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

1 Answer

The main problem is that the instruction

mov dl, greeting

copies the contents of the byte at address greeting to DL. The next time around you want to copy the contents of greeting+1, then greeting+2, etc.

The way you do this is to use another register to hold the current address and then load DL indirectly through that register. Let's say you want to use the SI register. Before you start the loop, you would set up SI to hold the address of greeting:

lea si, greeting

then in the loop, load dl using the address in SI and increment SI so that it's prepared to receive the next character:

mov dl, [si]
inc si

That should take care of your immediate problem. You may have another problem because of the int 21h instruction. When you make a DOS call, there is no guarantee that any of the registers will have their values preserved, so you may need to PUSH any registers you don't want disturbed onto the stack before the call and POP them off afterwards.

share|improve this answer
Thanks for the help, I got it working using what you said. I didn't have any problem with the registers changing but I'll keep that in mind next time. And sorry bout posting this here instead of stackoverflow, I didn't know it existed until now – user1715 Feb 15 '11 at 22:30
If your OS supports the undocumented INT 29h, then you could do the lea si, greeting followed by a lodsb/int 29h sequence... – Brian Knoblauch Mar 4 '11 at 21:21