誰かが私が次のプログラムの何が悪いのかを見つけるのを手伝ってもらえますか?「プログラミングをゼロから」を読んでいて、例をx86-64アセンブリに変換しようとしています。次のプログラムは、データセットの中で最大の数を見つけます。しかし、アセンブル、リンク、および実行すると、0になります。これは明らかに最大数ではありません。32ビットのレジスタ/命令では正常に動作しますが、64ビットでは動作しません。
# PURPOSE: This program finds the largest value in a set of data.
#
#
# VARIABLES: %rax holds the current value. %rdi holds the largest
# value. %rbx holds the current index. data_items is the
# actual set of data. The data is terminated with a 0.
#
.section .data
data_items:
.long 76, 38, 10, 93, 156, 19, 73, 84, 109, 12, 21, 0
.section .text
.globl _start
_start:
movq $0, %rbx
movq data_items(, %rbx, 4), %rax
movq %rax, %rdi
loop_start:
cmpq $0, %rax # Have we reached the end?
je loop_end
incq %rbx # Increment the index.
movq data_items(, %rbx, 4), %rax # Load the next value.
cmpq %rdi, %rax # Is new value larger?
jle loop_start
movq %rax, %rdi # New val is larger, store
# it.
jmp loop_start
loop_end:
# The largest value is already in %rdi and will be returned as
# exit status code.
movq $60, %rax
syscall