gpt4 book ai didi

assembly - 汇编代码帮助

转载 作者:行者123 更新时间:2023-12-04 06:18:40 25 4
gpt4 key购买 nike

由于各种原因,我正在尝试学习汇编,并且我正在尝试编写一个代码,上面写着 hello bla bla bla
然后读你的名字,打印你的名字,然后说更多 bla bla bla
但它在得到你的名字后不显示文本
我确定它是愚蠢的......对不起......

这是我到目前为止所拥有的:

.section .bss
.lcomm bufname, 256
.section .data
msg1:
.ascii "Hello, please enter your name!\n" # Message to write
len1 = . - msg1 # Length of string

msg2:
.ascii "Good to meet you "
len2 = . - msg2

msg3:
.ascii ". Iam your first assembly program!\n"
len3 = . - msg3

.section .text

.globl _start

_start:
call get_name
get_name:
#should print msg1
mov $4, %eax # system call number (sys_write)
mov $1, %ebx # file descriptor (stdout)
mov $msg1, %ecx # Message to write
mov $len1, %edx # Lenght of message
int $0x80 # Call kernel

#should get user input
mov $3, %eax # System call number (sys_read)
mov $0, %ebx # File descriptor (stdin)
mov $bufname, %ecx # Buffer to store the name
mov $256, %edx # Lenght of buffer
int $0x80

#should print msg2
mov $4, %eax
mov $1, %ebx
mov $msg2, %ecx
mov $len2, %edx
int $0x80

#should print bufname (doesn't)
mov $bufname, %ecx
mov $256, %edx
int $0x80

#should print msg3 (doesn't)
mov $msg3, %ecx
mov $len3, %edx
int $0x80

call exit
exit:
mov $1, %eax
mov $0, %ebx
int $0x80

编译我使用
as Jes.s -o Jes.o
ld Jes.o -o Jes

这是我得到的输出
$ ./Jes
Hello, please enter your name!
renato
Good to meet you

它应该显示
Good to meet you renato. Iam your first assembly program!

为什么这是错误的?
非常感谢您的时间!

最佳答案

问题是,当您调用中断( int )时,寄存器可能会被覆盖。这不像在为您保存和恢复寄存器的情况下进行函数调用。您需要在所有 int 之前放置这些行的重复项调用:

mov $4, %eax        # system call number (sys_write)
mov $1, %ebx # file descriptor (stdout)

关于assembly - 汇编代码帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6880652/

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