arraysassemblycountx86-16tasm

I have an indexing problems


I need to write names from keyboard and then display them, one on each line. They should be displayed with an index before of them. For example if I write the names elena and maria the should be displayed as 1.elena 2.maria

I tried adding a counter variable but I have some errors when I try to run the program in DosBox. Can someone help me? Here is my clean label that is outputting the names:

 lista:
  mov  dx, offset nume
print_names:
push dx
  mov  dl, 13          ; carriage return
  mov  ah, 02h
  int  21h
  mov  dl, 10          ; linefeed
  mov  ah, 02h
  int  21h
  pop  dx
  mov dx, offset index
  mov ah, 9
  int 21h
  inc byte ptr index
  mov  dx, offset nume
  mov  ah, 09h
  int  21h
  ; (*)
  add  dx, 5 + 1
  cmp  dx, numePointer ; check if the current name is the last one
  jb   print_names
  jmp  bucla           ; return to main loop

Solution

  • The addition is destroying the DX pointer for the name to be displayed!
    Why did you put the additional code between proc endp?
    punct db '.' ,10, '$' does not need the 10. Should be punct db '.$' or even better, combine it with index like in index db '?.$'.
    And still better, combine the newline with it too:

    lista:
      mov  dx, offset nume
    print_names:
      push dx                        ; (1)
      mov  dx, offset numeIndex
      mov  ah, 09h
      int  21h
      inc  byte ptr [numeIndex + 2]  ; "1" -> "2" -> "3" ...
      pop  dx                        ; (1)
    
      mov  ah, 09h
      int  21h
      add  dx, 5 + 1
      cmp  dx, numePointer ; check if the current name is the last one
      jb   print_names
      jmp  bucla           ; return to main loop
    
      ...
    
    numeIndex db 13, 10, 49, 46, 36