gpt4 book ai didi

assembly - 在命令行中传递参数,汇编编程

转载 作者:行者123 更新时间:2023-12-02 19:24:00 26 4
gpt4 key购买 nike

让我简单解释一下:)。

我通过使用EBP寄存器和ebx寄存器来接近参数10,因为它的堆栈结构包含EBP(基址寄存器),返回地址,参数#,参数1,参数2...因为我不' t 使用本地寄存器。我可以看到参数已正确输入,因为我可以使用调用 print_string 打印它。但是,由于 < while: > 代码行,似乎字符串 10 似乎没有被读取,因为推荐行在涉及到它时什么也没做。我会温和地询问从哪里开始编写代码。谢谢阅读。

输入:./atoi 10
结果:10

%include "asm_io.inc"

segment .data

segment .bss
input resw 1

segment .text
global main
main:
enter 0,0
pusha
mov ebx, [ebp+12]
mov eax, [ebx+4]
; call print_string
dump_stack 1,2,4
mov ebx, 0
mov ecx, 10
while:
cmp al, 0x0a
je print
sub eax, 0x30
mov [input], eax
mov eax, ebx
mul ecx
add eax, [input]
mov ebx, eax
jmp while
print:
mov eax, ebx
call print_int
call print_nl

popa
mov eax, 0
leave
ret

最佳答案

您的while循环未读取任何字符!您可以使用 mov dl,[eax] 检索这些内容。
正如您从下面的代码中看到的,不需要使用临时输入变量。

  xor   ebx, ebx            ;Result
while:
movzx edx, byte ptr [eax] ;Read 1 character
test dl, dl ;Test for end of string
jz print ;End found
sub dl, 0x30 ;Go from character to value [0,9]
imul ebx, 10 ;Result x10
add ebx, edx ;Add new digit
inc eax ;To next character
jmp while

关于assembly - 在命令行中传递参数,汇编编程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37640742/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com