内联汇编跪求解答

yyyegr yyyegr 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
输入字符串,转化大小写。

原代码是这样的:
#include <stdio.h>
int main()
{
char string[128];
gets(string);

_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, string

loopStart:
mov al, byte ptr ds:[edx]
test al, al
jz end
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
end:
}

puts(string);
return 0;
}

可以运行,但是我需要用汇编语言读数,并且后期要循环方便输入多个字符串。
所以我改了下,把gets()函数写进_asm :
#include <stdio.h>
int main()
{
char string[128];
char format[] = "%s";

_asm{

lea eax,string ;
push eax ;
lea eax,format ;
push eax ;
call scanf_s ;
add esp,8 ;

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, string

loopStart:
mov al, byte ptr ds:[edx]
test al, al
jz end
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
end:
lea eax,string;
push eax;
call printf;
add esp,4;
}
return 0;
}

为什么这样就不能打印结果了。。该怎么改。。坐等。。跪谢!
...全文
评论 5
收藏 已收藏
分享
返回顶部
yyyegr
其它技术问题 3,881 成员 9,044 内容