Assembly JC Instruction for Converting Input to Integer with Error Handling

Click For Summary
SUMMARY

The discussion focuses on using the JC (Jump if Carry) instruction in assembly language to handle user input conversion to an integer with error handling. The user seeks guidance on implementing a loop that prompts for re-entry of a valid number if the input contains invalid characters. Key recommendations include placing error handling labels within the function's scope and organizing code segments to clarify the flow of execution, similar to high-level languages like C.

PREREQUISITES
  • Understanding of assembly language syntax and structure
  • Familiarity with the JC (Jump if Carry) instruction
  • Knowledge of function calls and stack management in assembly
  • Basic concepts of error handling in programming
NEXT STEPS
  • Research how to implement loops in assembly language for continuous input validation
  • Learn about error handling techniques in assembly, focusing on user input
  • Explore the use of labels and jumps in assembly for structured programming
  • Study the differences between function calls and interrupts in assembly language
USEFUL FOR

Assembly language programmers, software developers working on low-level input handling, and anyone interested in implementing robust error handling in assembly code.

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 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 9 ·
Replies
9
Views
4K
  • · Replies 3 ·
Replies
3
Views
6K
  • · Replies 3 ·
Replies
3
Views
3K
Replies
5
Views
2K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 2 ·
Replies
2
Views
12K