开发者

Assembly Language Multiplication

having a bit of trouble understanding assembly multiplication. Can anyone help break down the process of these steps:

开发者_开发知识库
mov  ax,[p1000]; p1000 = +1000    ax = 03e8
imul [n100];     n100 = -100
                 _____________
                      -100,000

dx:ax = fffe 7960   (dx = fffe, ax = 7960) cf = 1

I'm not sure how to deduce that the answer is -100,000 from dx:ax. I've tried calculating it like so:

dx = (15 * 16^3) + (15 * 16^2) + (15 * 16) + 14 = 65,534

ax = (7 * 16^3) + (9 * 16^2) + (6 * 16) = 31,072

dx + ax = 96,606

I may be approaching this the wrong way, so please correct me if I am wrong.


imul [n100]; 

will multiply and leave the result in dx:ax

Now, dx:ax = fffe 7960. This is a 32 bit quantity with the upper 16bits in dx and the lower 16bits in ax. Since the the MSB of this overall 32bit signed quantity is 1, it's a negative number and we need the two's compliment to find magnitude.

FFFE 7960 <-- our number
0001 869F <-- 1's compliment in hex
0001 86A0 <-- 2's compliment in hex
...0001 1000 0110 1010 0000 <-- 2's compliment in binary

Convert that to decimal as usual (sum of all) (1*2^{bit_position}) ... we get the magnitude as ..

100,000.

Now recall that it's a negative signed number, (MSB = 1) so putting the sign and magnitude together we get ... -100,000 :)


In two's complement encoding, 0xfffe:7960 (a negative number since the topmost bit is set to 1) is -(0x1:0000:0000-0xfffe:7960) or -0x1:86a0 which equates to -100,000 in decimal.

You don't add the 16-bit ax and dx registers together to get the value, you treat them as a single 32-bit value.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜