bob smith
bob smith

Reputation: 55

Questions on mov command in assembly

I have a few issues with using registers and storing data.

  1. Before I read in a character I want a buffer of size 100 that the register ESI points to. Do I use this?

mov esi, 100 to store a buffer for size 100, and then

mov esi, [al]
inc esi

to store the current character I entered into the esi and move it to the next location to store a new character?

I also can't find out how to properly check if a null terminated character is entered. I've tried cmp al, 0xa to check for a new line and cmp eax, -1 to check eof.

Note: I have a function called read_char to read in a character to put into the al register

Upvotes: 0

Views: 418

Answers (1)

Fifoernik
Fifoernik

Reputation: 9899

To define a buffer in NASM you can use buffer times 100 db 0

You get its address with mov esi, buffer

To store the character in AL in it, and raise the address write mov [esi], al inc esi

how to properly check if a null terminated character is entered

The null would be the byte following the character. You need to compare a word for that. Read the character and the following byte, then compare:

mov ax, [esi]
cmp ax, 0x000A

This tests if linefeed was the last item in this zero-terminated string.

Upvotes: 1

Related Questions