assembly 比较两个输入的数字[重复]

ikfrs5lh  于 2022-12-04  发布在  其他
关注(0)|答案(1)|浏览(164)

此问题在此处已有答案

Code executes condition wrong?(2个答案)
1小时前关闭。
我正在尝试比较两个输入值,并返回较大的值。我是新的组装,希望有人能帮助解决和解释我的错误。感谢您的耐心。

.586
.MODEL FLAT

INCLUDE io.h
.STACK 4096

.DATA
number1 DWORD ?
number2 DWORD ?

prompt2 BYTE "Enter first number", 0
prompt3 BYTE "Enter second number", 0

sum BYTE 11 DUP (?), 0
outcome BYTE "The greater value is:", 0
equal BYTE "The two inputs are equal", 0
string BYTE 40 DUP (?)

.CODE
_MainProc PROC

; Ask the user for the first number and store it in the EAX register
input prompt2, string, 40
atod string
mov eax, number1

; Ask the user for the second number and store it in the EBX register
input prompt3, string, 40
atod string
mov ebx, number2

; Compare the values in EAX and EBX and jump to the appropriate code
cmp eax, ebx
jg greater
jmp less

; If EAX is greater than EBX, print the value in EAX
greater:
dtos eax, sum
output outcome, sum

; If EAX is less than or equal to EBX, print the value in EBX
less:
dtos ebx, sum
output outcome, sum

_MainProc ENDP
END

需要返回两个输入数字中的最大值。

7qhs6swi

7qhs6swi1#

是的,下面是一个如何使用.586指令编写代码的示例:

.586

; Define labels for the different sections of the code
greater:
less:

; Ask the user for the first number and store it in the EAX register
input prompt2, string, 40
atod string
mov eax, number1

; Ask the user for the second number and store it in the EBX register
input prompt3, string, 40
atod string
mov ebx, number2

; Compare the values in EAX and EBX and jump to the appropriate code
cmp eax, ebx
jg greater
jmp less

; If EAX is greater than EBX, print the value in EAX
greater:
dtos eax, sum
output outcome, sum

; If EAX is less than or equal to EBX, print the value in EBX
less:
dtos ebx, sum
output outcome, sum

在此代码中,.586指令位于文件的开头,它告诉汇编程序使用带有Pentium Pro指令扩展的x86指令集。此指令通常在编写32位系统的汇编代码时使用。
代码的其余部分类似于上一个示例,在该示例中,我们要求用户输入两个数字,使用cmp和jg指令对它们进行比较,并打印较大的值。

相关问题