简体   繁体   中英

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.

Also, what about ax value received from code below?

mov ax, 0084
mov bx, 009C
imul bl

Correct answer: 3070 My answer: 141C (by multiplying in binary)

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. So in your example, AX=3716H .

For multiplication of two bytes (byte*byte), the result is a word (16 bits). So in your example, the result is 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 . 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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