0

I need to fill an array with names from user input, but keep out names that are already stored in the array(ex, john,jaina,tom,bob). I got this, but it's not working.

data segment
numbers db 0
names db 220 dup (?)
buffer db 10 dup (?)

code segment
start:
 mov ah, 1;
 int 21h
 mov numbers, ax
 mov cx, numbers
 lea bx, [names]
 names:
       onename: 
        lea si, [buffer]
        mov ah,1;character by character
        int 21h 
        mov [bx], al
        inc bx
        mov [si], al
        inc si
        cmp al, ',' ;end of name
        je compare;
       loop onename
       compare:;buffer with names
       lea di, [names]
            check:
            lea si, [buffer]
            cmp si, di
            jne nextname
            inc si
            inc di
            jmp check
       nextname:
       cmp di, ','
       je check
       inc di
       jmp nextname 
 loop names    

1 Answers1

1
mov ah, 1;
int 21h
mov numbers, ax
  • You don't initialize the counter correctly. DOS function 01h only gives you an ASCII code in AL, but you treat it as a number in AX.
  • You've also defined the variable numbers of type byte but later on you process it as if it were a word.
  • The instruction loop onename should have been jmp onename
  • The label onename must be placed 1 line lower, just under the assignment to SI.
Fifoernik
  • 9,779
  • 1
  • 21
  • 27