English 中文(简体)
我如何利用多复制的标志延伸?
原标题:how do I use the sign extension from multiplication?

我现在就开始读书,我一米在签字延期的使用方面完全消失。 我的理解是,如果你在安特遣部队中具有价值,而且联军的价值如何使安爱国军的价值倍增,其结果是DX:AX,但我如何进入和使用上部分? 这对我没有任何意义。

问题回答

在你没有32个轨道登记册的8086个地方,请在<代码>后添加32个轨道,例如<>+x, si/adc dx, di to doDX:AX= DI:SI。 这正是你如何以比最广的登记册大的分类工作。

但通常,当一个登记册范围足够广时,你并不首先要把数量分成多个登记册。 Since You re written 32-bit Code>, no t Recsed this DX:AX separate problem in first place by not using mul r/m16.

相反,只使用32条轨道操作器,用于imul r, r/m。 或与汇编者一样,即3-operand即时形式。 (对预期目的地宽度的微量投入或信号延伸)。

之后,你甚至不再强迫使用EDX:EAX,而如果你只想使用32x32 =>,就根本不销毁EDX;32比乘数,而不是32x32 =>64比特。 (完全多半取决于签字,因此只剩下 im,而不是其他形式的未签字 m)。

例如:

  movsx   edx, word ptr [esp+4]    ; sign-extend a signed 16-bit stack arg
  movzx   ecx, word ptr [esp+8]    ; zero-extend an unsigned 16-bit arg to 32-bit
  imul    edx, ecx                 ; edx = i16 * (int)u16
  imul    edx, [esp+12]            ; and multiply by a 32-bit stack arg, edx *= i32

  mov  eax, 123
  imul ecx,  eax, 456            ; ecx = eax*456, leaving EAX unmodified.

  add   edx, ecx

  lea   eax, [edx + edx*4 + 789]   ; eax = edx * 5 + 789 ; more math using the power of 32-bit addressing modes.

BTW,正如Michael在评论中指出的,你可以做这样的事情,把DX: 宇宙航空研究开发机构合并成一个在EDX的32轨。

   shl edx, 16
   mov dx, ax

如果你知道紧急部队的16位高位轨道为零,则请使用<代码>or edx, eax,而不是部分注册的牧羊人。 为什么海湾合作委员会使用部分登记册?

16bit registers preserve unsigned numbers in the range 0000h..FFFFh. The result of adding or subtracting such numbers may overflow this range by one bit, this bit is mediated by CarryFlag.
For instance FFFFh + FFFFh = CF + FFFEh.

The situation is different with multiplication: it may overflow by sixteen bits,
for instance FFFFh * FFFFh = FFFE0001h.
This is why another register (hardwired as DX) is used to hold the upper 16 bits of the result.

即便是旧的16名轨道处理员8086,也可使用传统的16个轨道登记册添加32个轨道号码,但每项作业都需要2个机器指示,而且必须考虑到CarryFlag。 32个轨道号的下调用了<代码>ADD UB<>>>,上限用了<代码>ADCONEBB。

举例来说,请计算(a*b)+(c*d),a,b,c,d分别为16bit number 000Ah,000Bh,000Ch,000Dh。

MOV AX,000Ah ;
MOV CX,000Bh ; Let CX=000Bh
MUL CX       ; Let DX:AX= a * b = 0000:006Eh
MOV SI,AX  ; Save temporary result DX:AX
MOV DI,DX  ;   into another pair DI:SI.
MOV AX,000Ch
MOV CX,000Dh
MUL CX     ; Let DX:AX = c * d = 0000:009Ch
; Add the temporary result DI:SI to DX:AX.
ADD AX,SI  ; Let AX = 009Ch + 006Eh = 010Ah. CF = 0.
ADC DX,DI  ; Let DX = 0000h + 0000h + CF = 0. CF = 0.

Result of (a*b)+(c*d), which is 0000:010Ah, is now in DX:AX, CF=0.

We may also treat 16bit value as a signed integer in the range -32768..+32767, i.e. 8000h..7FFFh. Intel CPU 8086 couldn t multiply signed numbers, the instruction IMUL was introduced with 80186 and later. In the absence of IMUL we have to convert each number to its absolute value, perform the unsigned multiplication and, if exactly one of multiplicant was negative, convert the unsigned product to its negative value.
Conversion between a negative value and its absolute (positive) value is provided by the instruction NEG. To negate 32bit number in two joined 16bit register CarryFlag must be taken into account again:

; Negate DX:AX
NEG DX
NEG AX
SBB DX,0

; Negate DX:AX
NOT AX
NOT DX
ADD AX,1
ADC DX,0

然而,过去30年提出的所有英特尔/亚MD处理器可直接计算与<条码>IMUL签署的多复制件。 因此,正如Peter Cordes在其评论中所建议的那样,你可以更好地利用。





相关问题
How can I do a CPU cache flush in x86 Windows?

I am interested in forcing a CPU cache flush in Windows (for benchmarking reasons, I want to emulate starting with no data in CPU cache), preferably a basic C implementation or Win32 call. Is there a ...

What are the names of the new X86_64 processors registers?

Where can I find the names of the new registers for assembly on this architecture? I am referring to registers in X86 like EAX, ESP, EBX, etc. But I d like them in 64bit. I don t think they are the ...

How do I disassemble raw 16-bit x86 machine code?

I d like to disassemble the MBR (first 512 bytes) of a bootable x86 disk that I have. I have copied the MBR to a file using dd if=/dev/my-device of=mbr bs=512 count=1 Any suggestions for a Linux ...

32bit application access to 64bit registry

I have an OS Shell written in 32bit that is replacing the Explorer.exe of a Vista machine. I run a utility which is also written in 32bit, which allows to switch between the Explorer shell and My ...

Left Shift Overflow on 68k/x86?

I heard that the Motorola 68000 and Intel x86 architectures handle overflow from left shifting differently. Specifically the 68k LSL vs. the Intel SAL/SHL assembly instructions. Does anyone know the ...

Translate a FOR to assembler

I need to translate what is commented within the method, to assembler. I have a roughly idea, but can t. Anyone can help me please? Is for an Intel x32 architecture: int secuencia ( int n, ...

热门标签