我一直很难弄清楚这一点。所以我使用的是内联汇编,我基本上是在尝试将用户使用 Scanf 键入的数字与数字“20 美元”进行比较。
但我认为这是比较位置而不是实际价值。
这是我所拥有的:
asm(
"main: \n"
" \n"
"push $msg \n"
"call _printf \n"
"add $4, %esp \n"
" \n"
"push $gus \n"
"push $fmt \n"
"call _scanf \n"
"add $8, %esp \n"
" \n"
"movl $20, %eax \n"
"movl $gus, %ebx \n"
"cmp %eax, %ebx \n"
"jg lower \n"
"jl higher \n"
" \n"
"lower: \n"
"push $lss \n"
"call _printf \n"
"add $4, %esp \n"
"jmp next \n"
" \n"
"higher: \n"
"push $gtr \n"
"call _printf \n"
"add $4, %esp \n"
"jmp next \n"
" \n"
"next: \n"
"jmp main \n"
"ret \n"
" \n"
".section .data \n"
"msg: .asciz \"Please enter your guess: \" \n"
"gtr: .asciz \"Higher! \" \n"
"lss: .asciz \"Lower! \" \n"
// "crr: .asciz \"Please enter your guess: \" \n"
"fmt: .asciz \"%d\" \n"
".double 100 \n"
".byte 0 \n"
"gus: .double 100 \n"
".byte 0 \n"
);
是的,我知道这段代码确实没有实际使用的意义。我写这篇文章的目的实际上只是为了弄清楚如何比较。
但我的问题是,在:
"movl $20, %eax \n"
"movl $gus, %ebx \n"
"cmp %eax, %ebx
它应该将 20 与“gus”或用户输入的“guess”进行比较。但无论他们输入什么,它总是说“Lower”。