【发布时间】:2020-03-12 00:55:47
【问题描述】:
我想接受一个输入并用字符串中有多少个字符来显示输入。 到目前为止,我能够生成字符串,但我对如何获取输入感到困惑?
【问题讨论】:
标签: string count character nasm
我想接受一个输入并用字符串中有多少个字符来显示输入。 到目前为止,我能够生成字符串,但我对如何获取输入感到困惑?
【问题讨论】:
标签: string count character nasm
你可以使用这个功能:
count db 0; (or resb 1), this is the place where will stay the result
count_string:
lodsb; // load char( letter )
cmp al, 0x00; // check string end; cause 0x00 its not a letter or number, 0 is 30h in ascii
jz done; // count done
inc byte [count]; adds 1 to count register
jmp count_string; // check next char
done:
ret; // exit function
你可以这样定义一个字符串:
data:
; or in the section .data
string DB "This is my string", 0; 0 means the end of the string
你可以这样调用函数:
mov si, string; move the string pointer to register
call count_string;
如果你在 Windows 或 ubuntu 等操作系统中使用 nasm,你可以观看:https://www.youtube.com/watch?v=VAy4FGHDx1I
但在 x86 中我做了一个 4 字节(用于字母)命令行,它真的很容易获得更多,但这只是我使用 int 16h(键盘)的快速实验
【讨论】:
inc count 不是有效的 NASM 语法,您需要 inc byte [count]