String 如何在NASM中计算字符串中的字符数?

String 如何在NASM中计算字符串中的字符数?,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; //

我想获取一个输入并显示字符串中有多少个字符的输入。
到目前为止,我能够生成字符串,但我对如何获取输入感到困惑?

您可以使用此函数:

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;
您可以通过以下方式调用该函数:

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,uou可以看到:


但在x86中,我使用了一个4字节(代表字母)的命令行,它非常容易获得更多,但这只是一个快速的实验,我使用了int 16h(键盘)

您可以使用此函数:

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;
您可以通过以下方式调用该函数:

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,uou可以看到:


但是在x86中,我做了一个4字节(字母)的命令行,它很容易得到更多,但这只是一个快速的实验,我用了int 16h(键盘)

inc-count
是无效的NASM语法,你想要
inc-byte[count]
inc-count
是无效的NASM语法,你想要
inc-byte[count]