汇编语言 - 计算低和低的数量大写字母

时间:2013-12-17 19:28:24

标签: assembly inline-assembly

我正在尝试使用Visual Studio中的内联汇编在C中编写程序。我正在读取一个字符串,需要将变量中的小写字符数和变量中的大写字符数存储起来。以下是我到目前为止的情况:

void FnlUpperLowerCount(char *inStr) {

    int UpCount =  -99;

    int LowCount = -99;

    _asm {

        mov esi, inStr

        mov al, [esi]

    }

    printf("The number of upper case letters   : %d\n",UpCount);

    printf("The number of lower case letters   : %d\n",LowCount);

    return ;

}

我不确定如何更进一步。

2 个答案:

答案 0 :(得分:0)

我不确定我必须使用的确切语法,但我相信它应该是这样的。 我还假设inStr是一个只有字母字符的空终止序列

void FnlUpperLowerCount(char *inStr) {

int UpCount =  0;

int LowCount = 0;

_asm {

    mov esi, inStr

    loop:

    mov al, [esi]

    or al,al

    jz finished

    cmp al,91

    jc capital

    inc LowCount

    jmp cont

    capital:

    inc Upcount

    cont:

    inc esi

    jmp loop

    finished:

}

printf("The number of upper case letters   : %d\n",UpCount);

printf("The number of lower case letters   : %d\n",LowCount);

return ;

}

答案 1 :(得分:0)

mov esi,inStr   ;To start off initialize  esi point to input string
mov edi,outStr  ;edi point to the output string area

incr:
    mov [edi],al
    add edi,1
    add esi,1
    mov al,[esi]
    inc ecx
    jmp contf

startf:

    mov al,[esi]
    mov ecx,0

contf:

    cmp al,7bh
    jl isdone
    jmp incr

greater1:

    cmp al,61h
    jl incr
    sub al,20h
    jmp incr

isdone:

    cmp al,0
    jg greater1

done:

    mov outStr,edi
相关问题