【发布时间】:2022-12-02 21:40:32
【问题描述】:
我现在正在学习汇编,我有一个非常大的问题要解决。 (顺便说一句,我使用 x86_64 nasm 程序集)
到目前为止,我已经做到了
section .bss
result: resb 10
section .data
num1: db '22'
num2: db '33'
num3: db '44'
section .text
global _start
_start:
mov cl, [num1]
cmp cl, [num2]
jg _check_third_num
mov cl, [num2]
_check_third_num:
cmp cl, [num3]
jg _exit
mov cl, [num3]
_exit:
mov [result], rcx
mov rax, 1
mov rdi, 1
mov rsi, result
mov rdx, 10
syscall
mov rax, 60
mov rdi, 0
syscall
我想它按我预期的那样工作,但输出不正确。
所以,我基本上是这样编译的
$ nasm -f elf64 hello.asm -o hello.o
$ ld -o hello hello.o
$ ./hello
我得到这个输出4,而不是我希望的44。
那你能帮我吗?
【问题讨论】:
-
比较逻辑是否有缺陷,或者只是输出?
-
你的数字是字符串,所以你的比较已经是错误的,因为它只比较第一个数字,这是你将在最后打印的数字,因为这是你加载到
cl中的唯一内容。 -
即使我将其更改为数字,它也无法按我预期的那样运行
-
你需要相比作为二进制数读入变量/寄存器但是输出作为十进制数字字符串。
-
所以最好丢弃所有不相关的代码部分并调整标题。