0

Im using NASM

I'd like to compare the first character of a string in assembly to see if its blank.

            mov byte [NAME], 40
            lea dx, [NAME]
            mov ah, 0ah
            int 21h

            cmp [NAME],""
            je somewhere

This doesnt work.. any advice?

1 Answer 1

2

For starters, the int21/0ah puts the actual contents at NAME+2 since at NAME you specify the buffer length and at NAME+1 the actual length is returned. All of this is of course documented.

The cmp should use a size specification and also simple quotes. As such, cmp byte [NAME+2], ' ' could work.

Sign up to request clarification or add additional context in comments.

3 Comments

i used NAME times 43 db "$", so will it be cmp byte [NAME +2], '$' ?
@user3079563: What are you trying to achieve with cmp byte [NAME +2], '$'? If you wanto to check if the character is a space, compare against ' ', not '$'. If you want to check if nothing was written to the buffer, check the byte at [NAME+1] (number of characters actually read, excluding CR)
if [NAME] holds the buffer len, and the system call doesn't clobber that, @user3079563 should just have the length byte in the data section, and leave out the mov byte [NAME], 40 instruction, right?

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.