【发布时间】:2018-01-29 23:10:30
【问题描述】:
我有一个小型汇编程序,当我将它除外时,它不会跳转到标签。我怀疑这是由于 ASCII 值和整数之间的比较造成的。
section .bss
nvalue: resb 4
value: resb 4
section .data
inputPromptNValue db 'Enter a integer: '
inputPromptNValueLen equ $-inputPromptNValue
inputPrompt db 'Enter an integer: '
inputPromptLen equ $-inputPrompt
msg db 'msg one', 0xa
msgLen equ $-caseOneMsg
section .text
global _start
_start:
;prompt user
mov eax, 4
mov ebx, 1
mov ecx, inputPrompt
mov edx, inputPromptLen
int 80h
;read and store the user input
mov eax, 3
mov ebx, 0
mov ecx, nvalue
mov edx, 5
int 80h
;
mov ecx, nvalue
or ecx, 0x30
cmp ecx, 0x1 ; <--- this part isn't working
je someLabel ; <---
;.... more labels
someLabel:
;other instructions here
这个想法是基于用户输入的某个整数(0-9),将选择一个选项(将跳转到某个标签)。
当用户输入值“1”时,我希望上面的标签 (someLabel) 会被跳转到。我该怎么做才能得到这种行为?
【问题讨论】:
-
评论你的代码。很明显
or ecx, 0x30毫无意义。此外,字符是 1 个字节,但您正在处理 4 个字节。最后,学习使用调试器。 -
(foo | 0x30) == 1总是错误的...您的意思是使用'1'(1的 ASCII 代码)而不是整数1?那个 OR 仍然没有意义。 -
是的。我的错误部分是使用整数 1 而不是 1 的 ASCII 码。这基本上是我的第一个汇编程序,所以我并没有真正意识到出了什么问题。感谢您的 cmets。