Visual C++内联汇编 用户输字符串 实现字母大小写转换
发布网友
发布时间:2022-05-09 20:42
我来回答
共1个回答
热心网友
时间:2023-07-20 22:19
#include <stdio.h>
int main()
{
char szStr[128];
gets(szStr);
__asm {
jmp entry
isletter1:
cmp al, 'a'
jl nex
cmp al, 'z'
jg nex
mov ecx, 1
ret
isletter2:
cmp al, 'A'
jl nex
cmp al, 'Z'
jg nex
mov ecx, 1
ret
nex:
mov ecx, 0
ret
entry:
lea edx, szStr
loopStart:
mov al, byte ptr ds:[edx]
test al, al
jz ed
call isletter1
test ecx, ecx
jz test2
sub byte ptr ds:[edx], 'a'-'A'
jmp nextChar
test2:
call isletter2
test ecx, ecx
jz nextChar
add byte ptr ds:[edx], 'a'-'A'
nextChar:
inc edx
jmp loopStart
ed:
}
puts(szStr);
return 0;
}