2013-12-17 28 views
0

我想用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 ; 

} 

我真的不知道如何走得更远。

+3

一个空值终止序列我会先写在C,从那么它应该是相当简单的将其转换为ASM。 – Devolus

回答

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 ; 

} 
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 
+0

请格式化你的答案的开始,这很难阅读。 –