Clearing a register is best done by xoring it with itself.
IS EMU8086 32 BIT CODE
I'll don't use it in the below code because popping directly in the DX register is a bit shorter still. When converting the remainder into a character (through adding 30h) it's shorter to do it while the remainder is still in the AL register.There's also no point in moving the quotient back and forth in another register.Why should you first move the remainder to another register, when all you want to do is just push it on the stack?.This also avoids having to check for CX being zero before starting outputting with DOS. You know that you'll need at the very least 1 character to print (even if the input was 0), and so a Repeat-Until-loop is better. Choosing a While-loop is not the best choice.Let's first concentrate on the 16 bit version. thank you very much: Written by Dang Manh Truong Here is my code, please give me some feedback on aesthetics, code optimization. Now you just have to divide r_low + r_high_redundant and add in to the quotient, then you get the results. R_high * 2^16 = q_high_redundant * 10 + r_high_redundant (0 A = A_high * 2^16 + A_low = (q_high*2^16 + q_low + q_high_redundant)*10 + r_low + r_high_redundant Note that r_high is from 0 to 9, so to divide r_high * 2^16 by 10, we simply need to perform the calculations and then store the results in a lookup table! The result: So I decided to deal with the high and low parts of the 32-bit number separately: Let A be the number in question, we now divide by 10:Ī = q*10 + r (0 A_high * 2^16 = (q_high*2^16)*10 + r_high * 2^16. So there is no straightforward way to use the div command for division with 32-bit numbers (actually there are some solutions but I find them to be complicated). However the problem is that on x8086 processors, all the registers are 16-bits. Of course the basic algorithm is as follows: Input: Number Then these unused bits are filled with the copies of signed bit and clear CF and OF flags to zero.This is my code (assembly x8086, not MIPS, and I'm using emu8086) to display a 32-bits number on screen. If the product of multiplier and multiplicand produce result that fits into the destination register DX and AX with some of the bits left unused. The only difference between two is one deals with the multiplication of unsigned numbers and the other deals with signed operands. The operation of MUL and IMUL instructions are same. When the operand is a byte, it is multiplied with AL register and when it is a word, it is multiplied with AX register. The operands can be positive or negative. The IMUL instruction allows the multiplication of two signed operands. 8086 Singed Multiplication Instruction (IMUL) The multiplication of two operands give E0D0 which is stored to AX register. Now in this case the data at offset address 20 is 0108h so the operands are DA and 0108. MOV RES+2,DX Copy DX in upper 2 bytes of RES MOV RES,AX Copy AX in lower 2 bytes of RES MUL 20 Load 2nd operand from effective address 20+VAR_2 RES DW 2 DUP(?) Reserves 8 bytes of uninitilized data space to RES offset You can do this either by subtracting AH from AH or by loading AH with 0.