简体   繁体   English

大会伊姆尔签署

[英]Assembly imul signed

thx for help my question is about ax value received from code below? 寻求帮助我的问题是关于从下面的代码接收到的斧头值?

mov al,22h
mov cl,0fdh
imul cl
  • Actual machine result: ff9a 实际机器结果: ff9a
  • What I expected: 00:9a (by multiplying in binary) 我所期望的: 00:9a (通过乘以二进制数)

The first number is 22h so its 34 decimal its already unsigned the second number is fd in binary its goes like 11111101 so its signed that mean its like -3 第一个数字是22h,因此它的34个十进制数已经是无符号的,第二个数字是fd二进制,它像11111101一样,所以它的带符号意味着它像-3

so 22* -3 its 66; 所以22 * -3是66 and -66 on signed 9a 在签名的9a上为-66

so why there is ff at the beginning 那为什么一开始会有ff

imul cl does AX = AL * CL , producing a full 16-bit signed product from 8-bit signed inputs. imul cl执行AX = AL * CL imul cl ,从而从8位带符号输入生成完整的16位带符号乘积。

Why did you expect the upper byte to be zero? 您为什么期望高位字节为零? That makes no sense for signed or unsigned. 对于签名或未签名,这没有任何意义。

0x009a as a signed 2's complement 16-bit integer represents +154 . 0x009a作为带符号2的补码16位整数表示+154

0xff9a as a signed 2's complement 16-bit integer represents 0xff9a - 0x10000 = -102 . 0xff9a作为有符号2的补码16位整数表示0xff9a - 0x10000 = -102 This is the correct result for -3 * 34 . 这是-3 * 34的正确结果。 The number is in the -128..127 range for 8-bit signed, so the upper 8 bits ( 0xff ) are just the 2's complement sign extension of the lower 8 bits. 对于8位有符号,该数字在-128..127范围内,因此高8位( 0xff )只是低8位的2的补码扩展


its already unsigned 它已经未签名

No, it's signed positive. 不,它是积极的。 signed vs. unsigned is a question of how you interpret the bits. 有符号与无符号是关于如何解释位的问题。 In a signed interpretation, a number can be positive, negative, or zero. 在带符号的解释中,数字可以为正,负或零。 A number with the sign bit = 0 is non-negative, though. 但是,符号位= 0的数字是非负数。

This is just expected behavior in twos complement. 这只是预期的行为。 Starting from the full representation of 102 (the absolute value of the decimal result of your two operands, 34 and -3) we have in 16 bits: 从102的完整表示(两个操作数34和-3的十进制结果的绝对值)开始,我们有16位:

0000 0000 0110 0110
1111 1111 1001 1001 #Flip bits
1111 1111 1001 1010 #Add 1
  f    f    9    a

I'm guessing you just ignored the upper byte, since you properly converted the lower one. 我猜您只是忽略了高位字节,因为您正确转换了低位字节。 Remember the result and output register is a set size, and you can't ignore any part of it in the arithmetic. 记住结果和输出寄存器是一个设定的大小,在算术运算中您不能忽略它的任何部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM