我正在尝试为评论中的公式编写汇编语言代码。我遇到了麻烦,因为指向数组的指针是 64 位寄存器,我应该将最终结果存储在 32 位寄存器中,所以我显然缺少对寄存器如何工作的一些基本了解。我包含了我尝试的解决方案,但是当我尝试使用一个参数是 64 位寄存器而另一个参数是 32 位的 movl 或 subl 时出现错误。我也不确定我的推理是否正确。任何帮助,将不胜感激。
# WRITEME: At this point, %r12 and %rbx are each pointers to two arrays
# of 3 ints apiece, a0 and a1. Your job is to write assembly language code
# in the space below that evaluates the following expression, putting the
# result in register %esi (the 32 bit form of register %rsi):
#
# (a1[0]-a0[0]) * (a1[0]-a0[0]) +
# (a1[1]-a0[1]) * (a1[1]-a0[1]) +
# (a1[2]-a0[2]) * (a1[2]-a0[2])
#
#
# It is possible to do this using 11 instructions. You need to use extra
# registers, of course. Since you are not calling any functions, you have a
# lot of choices. %r12 and %rbx are already occupied, but you could use
# %r13d through %r15d (32 bit forms of %r13 through r15) safely, and also
# %eax, %ecx, %edx and of course %esi, since that is where the result will
# be stored.
###########
# Your code here
movl $0, %esi
movl %rbx, %eax #errors here
subl %r12, %eax #and here
imull %eax, %eax
movl 4(%rbx), %ecx
subl 4(%r12), %ecx
imull %ecx, %ecx
movl 8(%rbx), %edx
subl 8(%r12), %edx
imull %edx, %edx
movl %eax, %esi
addl %ecx, %esi
addl %edx, %esi