Assembly JC Instruction for Converting Input to Integer with Error Handling

In summary, the user is getting input from the user and converting it to an integer. If the input is not valid, the program needs to ask the user to reenter the value. If the value is not valid, the program displays an error message and asks the user to reenter the value.
  • #1
naja
3
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
  • #2
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.
 
  • #3
thanks that helped.
 

FAQ: Assembly JC Instruction for Converting Input to Integer with Error Handling

What is an "Assembly jc instruction"?

An "Assembly jc instruction" is a type of assembly language instruction used for conditional branching in a program. It allows the program to jump to a different location in the code based on the outcome of a previous comparison or operation.

What does the "jc" in "Assembly jc instruction" stand for?

The "jc" in "Assembly jc instruction" stands for "jump if carry". This means that the instruction will only jump to the specified location if the carry flag is set.

How is an "Assembly jc instruction" different from other branching instructions?

An "Assembly jc instruction" is different from other branching instructions because it is specifically used for conditional branching. Other branching instructions, such as "jmp" (jump) and "call" (call subroutine), do not require a condition and will always jump to the specified location.

What is the syntax for using an "Assembly jc instruction"?

The syntax for using an "Assembly jc instruction" is as follows:
jc label

Where "label" is the location in the code that the instruction will jump to if the carry flag is set.

What are some common use cases for "Assembly jc instruction"?

"Assembly jc instruction" is commonly used in error handling and looping in programs. It can also be used for implementing decision-making logic and controlling program flow based on certain conditions.

Similar threads

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