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
  • In cmp di, ',' you're comparing a pointer with a character. That won't work. Commented Feb 28, 2016 at 21:57

1 Answer 1

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.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.