使用32位汇编x86。如果我的情况属实,我该如何跳转到标签?

问题描述 投票:0回答:1

我正在学习装配,我对它很新。我正在做一个基本的总和程序,当它完成后,我有一个提示,询问我是否愿意“继续:y / n”。当我调用readChar(在AL寄存器中存储),并调用JE(跳转相等)命令时,没有任何反应。它似乎不会将字符输入记录到寄存器中。它没有跳转到我的“L2”标签并继续逐行。知道为什么吗?

INCLUDE Irvine32.inc

.data
firstPrompt BYTE "Enter first 16 bit unsigned integer: ", 0
secondPrompt BYTE "Enter second 16 bit unsigned integer: ", 0
reenterPrompt BYTE "The number must be between 0 and 65,535 ", 0
continuePrompt BYTE "Continue: y/n:", 0
sumPrompt BYTE "Sum = ", 0
arr BYTE 5 DUP (?), 0

.code
main PROC  

L1:
     mov edx, OFFSET firstPrompt
     call writeString
     call readInt
     cmp eax, 0
     jl falseCase
     cmp eax, 65535
     ja falseCase
     mov bx, ax ;bx = first int
L2:
     mov edx, OFFSET secondPrompt
     call writeString
     call readDec ;ax = second int
     cmp ebx, 65535 
     jl falseCase
     cmp bx, 0
     jae trueCase
trueCase: ;if true, sum both intergers, print the sum and prompt to continue
     add ax, bx
     mov edx, OFFSET sumPrompt
     call writeString
     call writeDec
     call crlf
     mov edx, OFFSET continuePrompt
     call writeString
     call readChar
     cmp al, 'y'
     or al, 'Y'
     call crlf
     je L2
falseCase:
     mov edx, OFFSET reenterPrompt
     call writeString
     call crlf
     jmp L1
assembly x86 irvine32
1个回答
0
投票

or是一个按位OR运算,根据结果为零设置ZF。在你用cmp阅读它之前,它正在破坏je的旗帜结果

我想你正试图检查al'y'还是'Y'。由于这些值仅在一个位位置不同,因此可以通过忽略该位来检查两者(无条件地设置或清除它)。

例如or al, 0x20强制小写(如果它是Y),然后cmp al, 'y'根据al - 'y'设置FLAGS(即如果它们相等则设置ZF)。

What is the idea behind ^= 32, that converts lowercase letters to upper and vice versa?

© www.soinside.com 2019 - 2024. All rights reserved.