0
我是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
你試過用gdb調試你的代碼嗎?如果你不是爲什麼? –