我目前正在忙於在彙編(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
您在調試時看到了什麼? – zmbq
當我調試je得不到執行,所以程序移動到下一個cmpl。在這裏它不會被再次擊中,從而達到執行(無條件)執行的調用退出。 – Gooey
當您從鍵盤輸入「1」時,該值爲31h或49十進制,而不是1. –