2013-12-17 29 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

請格式化你的答案的開始,這很難閱讀。 –