0

I'm trying to display a message several times.

I used nasm and I used this program :

    MOV cx, 1
    mov  ax, 10
re:
    CMP ax, cx
    JS fin
    mov  dx, texte 
    INC cx
    JMP re
fin:
    Int 21h
    texte: db 'Hello, World !!'
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847

2 Answers2

2

Currently you invoke int 21h only at the bottom. Try to move it into the loop.

Also, it's been a really long time since I last did anything in assembly but you probably also need to prepare some registers to determine what int 21h would do. See more info here: http://spike.scu.edu.au/~barry/interrupts.html#ah09

obe
  • 7,378
  • 5
  • 31
  • 40
1

Couple more things:

  • for int21h to perform output, you need to set AH to 9. You're already using AX to store the loop limit; you'd have to use some other register (BX, SI, DI are currently unused), or a hard-coded limit. Also, int21h function 9 changes the value of AL on output - one more reason not to use AX.
  • The string needs to be terminated with the $ character. That's what int21h/9 expects, not an convention of assembly language in general.
  • And, like obe said, you want the int 21h command before, not after the "jmp re" line.
  • At the "fin" label, you might want to quit the program. The sequence for that is: "mov ah, 4ch/int 21h".
Seva Alekseyev
  • 59,826
  • 25
  • 160
  • 281
  • Or count CX down from 10, instead of using two registers to loop from 1 to 10. Or put the 10 as an immediate operand for CMP. SI and DI are also unused, IDK why you mentioned BX but not them. – Peter Cordes Oct 30 '16 at 02:07
  • Many ways to do this. "LOOP re" command would probably be the easiest. – Seva Alekseyev Oct 30 '16 at 02:48
  • Except that [LOOP is slow](http://stackoverflow.com/questions/35742570/why-is-the-loop-instruction-slow-couldnt-intel-have-implemented-it-efficiently), and not a good habit to teach beginners. They won't find real code that uses it when looking at compiler output, so might as well learn to make loops with cmp/jcc (or dec/jnz). It's simpler just to never mention LOOP in the first place, since it's not useful outside of optimizing for code-size. – Peter Cordes Oct 30 '16 at 02:52