Assembly JC Instruction for Converting Input to Integer with Error Handling

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 4K views
naja
Messages
3
Reaction score
0
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:
;get number
 jc displayErroMsg ; If value is not valid then display msg and ask user to re enter the value.
 ;I don't know 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 don't know where to put that label that jc will jump.
 
on Phys.org
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:
  // Simple function return 1 in the accumulator
Label1:
  // Lots of stuff
  JNZ Label3;
Label2:
  JMP GetOutOfHere;
Label3:
 // Some conditional part you jumped to
 JMP Label2;

GetOutOfHere:
  MOV AX,1;
  RETF;

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.