May 4th, 2013, 11:23 AM
Re: A few questions about exception handling
You should have posted your code within code tags. Even more than most other languages, assembly language code is particularly unreadable without them. With code tags (and after some additional shifting around to improve column alignment), your code looks like this:
After all, I'd say you made a good start to it. However, the code still contains quite some bugs.
NEXT CMP AX,0
COND1 CMP BX,0
ELSE1 DEC AX
POWER MOV AX,BX
COND2 CMP AX,0
COND3 CMP BX,0
COND4 MOV AX,1
ELSE2 AND AX,BX
The IMO most obvious one first: All your jumps are forward, so there's no loop at all in your code.
The DEC instruction in your rendition of the first line of the C++ code should be after the CMP, since the C++ code demands post-decrement.
The JC instruction you use for your first conditional jump is for unsigned integers while your variables are signed. (More specifically, that instruction explicitly names the flag to check, but it's technically identical to the unsigned JB instruction.) All your other conditional jumps are correct - regarding their signedness. They need a thorough re-check regarding the overall jump structure, though.
Just to mention a few. Most of that should be relatively easy to spot by doing some debugging in your emulator. To make your code runnable in the emulator, simply give the registers initial values in the first two lines of your assembly code. The C++ code doesn't demand any specific initial values, so you may pick any values you like, but a clever choice of values may simplify spotting problems while debugging. It may not be the best choice to initialize both to 0.
Finally, your question is completely unrelated to the subject of this thread. You should better have posted that in your other thread on that subject that already exists. Don't take the fact that you now got substantial help here as an encouragement to do further hijacking of unrelated threads. You just got that help because now you've posted your code. Please post further questions regarding this topic in the other thread. (And perhaps a moderator can move these off-topic posts to the other thread, simplifying life for us and potential readers of the threads. )
Last edited by Eri523; May 4th, 2013 at 06:09 PM.
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!