我是 GAS 组件的新手,我的目标是显示用户输入的两个数字的总和。我使用 char 到数字的转换,反之亦然,结果总是错误的(非数字)。有人能告诉我哪里错了吗?提前致谢。
.section .data
prompt_str1:
.ascii "Enter first number: "
str1_end:
.set STR1_SIZE, str1_end-prompt_str1
prompt_str2:
.ascii "Enter second number: "
str2_end:
.set STR2_SIZE, str2_end-prompt_str2
.section .bss
.lcomm input1 2
.lcomm input2 2
.lcomm ans 1
.macro write str,str_size
movl $4, %eax
movl $1, %ebx
movl \str, %ecx
movl \str_size, %edx
int $0x80
.endm
.macro writenum str
movl $4, %eax
movl $1, %ebx
movl \str, %ecx
int $0x80
.endm
.macro read buff, buff_size
movl $3, %eax
movl $0, %ebx
movl \buff, %ecx
movl \buff_size, %edx
int $0x80
.endm
.section .text
.globl _start
_start:
write $prompt_str1, $STR1_SIZE
read $input1, $2
write $prompt_str2, $STR2_SIZE
read $input2, $2
subl $0x30, input1
subl $0x30, input2
movl $input1, %eax
addl $input2, %eax
movl %eax, ans
addl $0x30, ans
writenum $ans
exit:
movl $1, %eax
movl $0, %ebx
int $0x80