简体   繁体   English

Assembly Imul和Idiv

[英]assembly imul and idiv

Could You please advise what procedure should be followed to solve below: 您能否建议解决以下步骤:

mov ax, 0835 h
mov cv, 005d h
idiv cl

ax = ? 斧=?

Correct answer: 3716 My answer: 0016 (I get it by converting 0835h to 2101 decimal and 005dh to 93 decimal. Then divide 2101/93=22.59 Then conver 22 back to hexadecimal and get 16. Thus AX gets quotient 0016h. 正确答案:3716我的答案:0016(我将0835h转换为1011的2101,将005dh转换为93的十进制。然后除以2101/93 = 22.59,然后将22转换为十六进制,得到16。这样AX得到商0016h。

Also, what about ax value received from code below? 另外,从下面的代码收到的ax值呢?

mov ax, 0084
mov bx, 009C
imul bl

Correct answer: 3070 My answer: 141C (by multiplying in binary) 正确答案:3070我的答案:141C(乘以二进制)

I would very appreciate your help. 非常感谢您的帮助。

Thank You in advance. 先感谢您。

Martin 马丁

To divide a word by a byte (word/byte), the quotient is written in AL and the remainder is written in AH. 为了将一个单词除以一个字节(单词/字节),商以AL表示,余数以AH表示。 So in your example, AX=3716H . 因此,在您的示例中, AX=3716H

For multiplication of two bytes (byte*byte), the result is a word (16 bits). 对于两个字节(byte * byte)的乘法,结果是一个字(16位)。 So in your example, the result is AX=3070 . 因此,在您的示例中,结果为AX=3070

Note that for signed number, the pencil and paper method for multiplication (eg add and shift) and division may not work properly. 请注意 ,对于带符号的数字,用铅笔和纸进行乘法(例如加法和移位)和除法的方法可能无法正常工作。 For example, the correct method for signed multiplication is booth algorithm . 例如,用于符号乘法的正确方法是booth算法 I have to say that pencil and paper method should be modified for signed numbers and the trick is to extend the sign bit. 我不得不说铅笔和纸的方法应该修改带符号的数字,诀窍是扩展符号位。 But, such methods are error prone which is why dedicated algorithms are preferred. 但是,这样的方法容易出错,这就是为什么首选专用算法的原因。

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

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