【发布时间】:2016-09-19 20:11:06
【问题描述】:
这是我想要实现的目标:
a_x*b_x + a_y*b_y + a_z*b_z
我正在尝试在汇编中创建一个执行上述计算的 MACRO。
我的所有号码都使用WORDs。这是我的代码:
dotProduct MACRO A_X,A_Y,A_Z,B_X,B_Y,B_Z ;a.b (a dot b) = a_x*b_x + a_y*b_y + a_z*b_z
mov ah, A_X
mov al, B_X
imul ax
mov answer, ax
mov ah, A_Y
mov al, B_Y
imul ax
add answer, ax
mov ah, A_Z
mov al, B_Z
imul ax
mov answer, ax
output answer
ENDM
answer BYTE 40 DUP (0)
但我收到以下错误:
Assembling: plane_line.asm
plane_line.asm(101) : error A2070: invalid instruction operands
crossProduct(1): Macro Called From
plane_line.asm(101): Main Line Code
plane_line.asm(101) : error A2070: invalid instruction operands
crossProduct(2): Macro Called From
plane_line.asm(101): Main Line Code
plane_line.asm(101) : error A2070: invalid instruction operands
crossProduct(4): Macro Called From
plane_line.asm(101): Main Line Code
plane_line.asm(101) : error A2070: invalid instruction operands
crossProduct(5): Macro Called From
plane_line.asm(101): Main Line Code
plane_line.asm(101) : error A2070: invalid instruction operands
crossProduct(6): Macro Called From
plane_line.asm(101): Main Line Code
plane_line.asm(101) : error A2070: invalid instruction operands
crossProduct(8): Macro Called From
plane_line.asm(101): Main Line Code
plane_line.asm(101) : error A2070: invalid instruction operands
crossProduct(9): Macro Called From
plane_line.asm(101): Main Line Code
plane_line.asm(101) : error A2070: invalid instruction operands
crossProduct(10): Macro Called From
plane_line.asm(101): Main Line Code
plane_line.asm(101) : error A2070: invalid instruction operands
crossProduct(12): Macro Called From
plane_line.asm(101): Main Line Code
我认为这与我处理寄存器的方式有关。
我应该怎么做呢?
【问题讨论】:
-
MASM 不会让您将字加载到字节寄存器中(如 al 或 ah)。
-
那么将我的
WORDs 加载到寄存器中并将它们相乘的正确方法是什么? -
顺便说一句,a cross product 与点积不同。您在宏中的评论甚至说“点积”。你应该重命名你的宏。
-
我解决了这个问题。谢谢。对计算部分有帮助吗?
-
您的输入是否必须为 WORD 大小?或者你真的需要做 16b * 16b => 32b (因为你使用的是
imul axinstead ofimul byte ptr [B_X])。实际上,当您执行imul ax时,您正在对一个 16 位数字进行平方,在 DX:AX 中产生结果,我确定这不是您想要的。