【发布时间】:2012-06-05 10:34:38
【问题描述】:
我目前正忙于在装配 (AT&T) 中做一个小测验(到目前为止有固定的问题)。
我设计了一个小菜单,要求输入 1 2 或 3
问题是我的 cmpl 没有做它的工作,我不知道为什么。
无论输入是什么,它都会退出。
下面是我的一些代码:
.text
menu: .asciz "Please select an option: 1 - Start the quiz! 2 - Highscores 3 - Quit\n"
input: .asciz "%i"
.global main
main:
call menushow
menushow:
push $menu
call printf
addl $4,(%esp)
leal -4(%ebp), %eax
pushl %eax
pushl $input
call scanf
popl %eax
popl %eax # the number that has been entered is now in eax
cmpl $1,%eax #1 entered?
je qone #show question 1
cmpl $2,%eax #2 entered??
je showHighScores #show current highscores
call quit #something else? (3, 99 w/e) then we quit
【问题讨论】:
-
调试时看到了什么?
-
当我调试 je get 没有执行所以程序向下移动到下一个 cmpl。在这里它没有再次被击中,因此它达到了调用退出,它被执行(无条件地)。
-
当您从键盘输入“1”时,该值为 31h 或 49 十进制,而不是 1。