CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 27

Threaded View

  1. #16
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    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:

    Code:
          MOV AX,
          MOV BX,
          DEC BX
          CMP AX,BX
          JC  NEXT
          JMP EXIT
    NEXT  CMP AX,0
          JG  COND1
          JMP ELSE1
    COND1 CMP BX,0
          JLE POWER
    ELSE1 DEC AX
          INC BX
          CMP AX,BX
          JC  COND2
    POWER MOV AX,BX
          MUL BX
          JMP EXIT
    COND2 CMP AX,0                  
          JNE COND3
          JMP ELSE2
    COND3 CMP BX,0      
          JNE COND4
          JMP ELSE2
    COND4 MOV AX,1
          JMP EXIT
    ELSE2 AND AX,BX
          MOV CL,3
          SHR AX,CL
          MOV BX,AX
    EXIT  HLT
    After all, I'd say you made a good start to it. However, the code still contains quite some bugs.

    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 05:09 PM. Reason: Typos
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured