1
我只是剛開始學習x86架構的彙編語言。我正在做一些基於條件分支的練習。在這個時候,我已經介紹了JMP,JZ和JNZ就分支代碼而言。這是練習的link。第5點說,如果輸入爲0
,則程序被鎖定。這很公平,因爲dec eax
會導致eax
寄存器保持0xffffffff
。我需要解決這個問題。這是我想出的 - 添加虛擬指令add eax, 0h
只是爲了檢查這是否導致zero-flag
被設置,並且如果設置跳轉到代碼中的某個位置,該位置打印出所需的值並退出程序。無論如何要停止在這個彙編代碼中的代碼重複
start:
; The program begins here:
call read_hex
add eax, 0h; my code
jz lb2; my code
mov ecx,1
lb1:
add ecx,ecx
dec eax
jnz lb1
mov eax,ecx
jmp lb3
lb2:
inc eax
call print_eax
; Exit the process:
push 0
call [ExitProcess]
lb3:
call print_eax
; Exit the process:
push 0
call [ExitProcess]
多數民衆贊成讓我難受的事情是,我在LB2和LB3重複代碼,我不太清楚,如果有解決這個辦法。