私はここで GAS アセンブリを初めて使用します。私の目標は、ユーザーが入力した追加された 2 つの数値の合計を表示することです。文字から数値への変換とその逆を使用しましたが、結果は常に間違っています (非数値)。誰かがどこが間違っているか教えてもらえますか? 前もって感謝します。
.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