Questions on mov command in assembly

时间:2016-02-03 02:43:19

标签: unix assembly nasm cpu-registers

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

1 个答案:

答案 0 :(得分:1)

要在NASM中定义缓冲区,您可以使用buffer times 100 db 0

您的地址为mov esi, buffer

要将字符存储在AL中,并提高地址写mov [esi], al inc esi

  

如何正确检查是否输入了空终止字符

null将是字符后面的字节。你需要比较一个单词。读取字符和后面的字节,然后比较:

mov ax, [esi]
cmp ax, 0x000A

此测试是否换行是此零终止字符串中的最后一项。