1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Assembly jc instruction?

  1. Oct 11, 2012 #1
    I am getting input from user and convert to int . if input is not valid(has invalid chars etc) i need to ask user
    to re enter the number .

    Code (Text):

    ;get number
     jc displayErroMsg ; If value is not valid then display msg and ask user to re enter the value.
     ;I dunno where I need to put that displayErroMsg: . Also if user will enter invalid input i need to ask re enter the value continiously. I mean not only once
     ;I dunno where to put that label that jc will jump.

  2. jcsd
  3. Oct 12, 2012 #2


    User Avatar
    Science Advisor

    Hey naja and welcome to the forums.

    If you have a label that will be jumped to, the main considerations you need to think about relate to the current context of the execution environment.

    The biggest thing is whether something is a function or in an interrupt.

    If something is in a function, then it means that the stack will be setup in a way to allow it to return back to the last function it called.

    So as an example, consider the following:

    Code (Text):

      // Simple function return 1 in the accumulator
      // Lots of stuff
      JNZ Label3;
      JMP GetOutOfHere;
     // Some conditional part you jumped to
     JMP Label2;

      MOV AX,1;
    So in this example we are in a function that has had a CALL statement and we make sure that the whole function returns back to the previous scope in the right way. It is not a really useful example of any specific function, but the point is to show you how to think about using jump statements within a function call.

    If you have interrupts, then there are even more issues to contend with.

    Pretty much with regards to your question, the assembler should take of sorting out the memory addresses and organizing the output in memory but otherwise, some recommendations would be to put the labels inside the scope of your function to make it easier and to create new labels (like was done above) to break up the code so that you can see that one segment corresponds to one branch and the other corresponds to something completely different.

    This just mimics what you see in high level languages like C with the braces except the labels help you see where the divisions are to identify not only what part of the code is associated with each jump, but what part is not associated with any jumps and is just code.
  4. Oct 12, 2012 #3
    thanks that helped.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook