1

考虑带符号的数字(如+, -),编写一个代码摘录,检查是否:

[EAX]*[ESI + 4*EBX]%[EDX + 3] |ECX%[EDX + 3]小于或等于[EBX + 20],如果为真,则代1EAX

这是我到目前为止所拥有的,但我无法弄清楚如何将其与以下内容进行实际比较[EBX + 20]

 MOVSX EAX, [input1]
 MOVSX ESI, [input2]
 MOVSX EBX, [input3]
 MOVSX EDX, [input4]
 IMUL EBX, 4
 ADD ESI,EBX
 IMUL EAX, ESI
 ADD EDX, 3
 IDIV ECX, EDX
 OR EDX, ECX
 IDIV EAX, EDX

此代码缺少与 的比较EBX + 20,并将1其放入EAX. 我也可以解释%IDIV吗?

通过回答这个问题,您可以帮助我的整个系统编程课程(选修课)。预先感谢!

4

1 回答 1

-1

请注意,IDIV 不能将 ecx 除以任何东西。它仅适用于 EAX:EDX 对。这样,您无需将 EDX 用于其他任何事情。

汇编语言中的方括号表示括号中的地址所指向的内存。在任务方面,只有 ecx 被它的值使用。所有其他寄存器都包含一些内存地址,并且必须从内存中读取值。

另外我假设所有寄存器在输入上都有正确的值:

compare:
         mov    eax, [eax]         ; eax = [eax]
         imul   eax, [esi+4*ebx]   ; eax = [eax]*[esi+4*ebx]
         mov    esi, edx           ; use esi instead of edi: esi = edx

         cdq              ; convert 32bit eax to 64bit eax:edx needed for division.

         idiv   [esi+3]   ; the remainder is in edx
         mov    edi, edx  ; store it in edi in order to use edx later.

         mov    eax, ecx  ; we can divide only eax:edx

         cdq

         idiv   [esi+3]   ; the second remainder is in edx

         or     edi, edx

         mov    eax, 0          ; prepare for the output value
         cmp    edi, [ebx+20]
         jg     end             ; edi is greater than [ebx+20]
         inc    eax             ; edi is less or equal than [ebx+20] so make eax = 1
end:
         retn
于 2013-11-05T14:21:59.150 回答