#A loop in emu8086 full#
Checking to see if a register is empty can be done by comparing it with zero, but a shorter way is to test the register with itself and then decide upon the state of the zero flag (ZF).ĭo note that writing tail comments instead of full line comments gives cleaner and more readable code.Clearing a register is best done by xoring it with itself.
#A loop in emu8086 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 This is my code (assembly x8086, not MIPS, and I'm using emu8086) to display a 32-bits number on screen.