Assembly JC Instruction for Converting Input to Integer with Error Handling

AI Thread Summary
To convert user input to an integer with error handling in assembly, a label for error messaging must be strategically placed within the function's scope. When invalid input is detected, the program should jump to this label to display an error message and prompt the user to re-enter the value continuously. It's crucial to consider the execution context, particularly if the code is within a function or interrupt, as this affects how jumps are managed. Organizing code with clear labels can help delineate different branches and improve readability, similar to structures in high-level languages. Properly structuring these elements ensures the program can handle user input effectively while maintaining flow control.
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.
 
Physics news 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.
 
thanks that helped.
 

Similar threads

Replies
3
Views
1K
Replies
1
Views
5K
Replies
6
Views
3K
Replies
9
Views
4K
Replies
3
Views
2K
Replies
6
Views
4K
Replies
2
Views
12K
Back
Top