开发者

Assembly input validation

On my assembly program I request several integer input's from the user. However even if I enter a character, string or nothing at all, the program continues with execution.

How can i validate whether the user actually entered an integer and not something else.

Answer can be Assemb开发者_开发技巧ly syntax agnostic


In this particular case using MIPS. The system call that performs the service "InputDialogIn" returns in register $a1 a status value, depending on the input.

  • 0: OK status
  • -1: Input cannot be parsed
  • -2: Cancel was chosen
  • -3: OK button selected, yet, no data input onto field

Therefore using the value in op beq to $zero, validates the input successfully.

Note: Instruction/Syscall 51 "InputDialogIn", is exclusive to MARS simulator.


There's a simple way to learn how this can be done - write that validation function in C and compile to assembler and try to map C constructs to what you see (GCC -S option, various -fdump-XXX switches allow to annotate assembler code).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜