assembly 装配检查三个数中最大的

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

我现在正在学习汇编,我有一个很大的问题要解决。(顺便说一句,我使用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
你能帮我吗?

ih99xse1

ih99xse11#

所以,我上了印度教程(我个人觉得很糟糕)。他们说我们可以比较字符串作为数字的替代。但是,可以肯定的是,这并不能正常工作。
另外,我会得到〈10个数字的工作。〉10个数字,我想我很快就会得到它。

section .bss
    result: resb 2
section .data
    num1: db 9
    num2: db 8
    num3: db 7

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: 
    add rcx, '0'
    mov [result], rcx
    mov rax, 1
    mov rdi, 1
    mov rsi, result
    mov rdx, 2

    syscall
    mov rax, 60
    mov rdi, 0

    syscall

相关问题