Build: 16-bit

I am still new to the assembly, and still do not know many teams in the assembly. I want to do division in 16-bit register. I want to print its contents. I know that I need to convert the contents of the register to ASCII for printing, but again, my problem is separation. Please help me.

For example, the content of cx is 2012 (integer). What should I do?

mov ax, cx mov bx, 1000 idiv bx 

The above code is incorrect, right?

+4
source share
2 answers

Edit: I noticed that this is a signed idiv , the answer has been edited accordingly.

The above code is incorrect in one aspect: ax not decrypted with dx:ax .

Just add cwd (convert word to double word) to idiv bx and then correct. The factor will be in ax , and the remainder will be in dx .

+3
source

Check this link (idiv search)

The idiv command divides the contents of a 64-bit integer EDX: EAX (constructed by viewing EDX as the most significant four bytes and EAX as the least significant four bytes) with the specified operand value. The factor division result is stored in EAX, while the remainder is placed in EDX. Syntax idiv idiv

Examples

idiv ebx - split EDX: EAX content into EBX content. Put the ratio in EAX and the remainder in EDX. idiv DWORD PTR [var] - split the contents of EDX: EAS into a 32-bit value stored in the var memory location. Put the ratio in EAX and the remainder in EDX.

Of course, since you are using 16-bit, cut all the specified bit-values ​​in half and discard the E of each register, and it is exactly the same

+4
source

Source: https://habr.com/ru/post/1433813/


All Articles