-4

i made a code to generate Fibonacci sequence elements based on the number given by user and it works fine but i want to make the user input a number in range of [1-25] and if the user enter any other number, it should gives him like a warning to re-enter a suitable number in this range .. so that i made this part of code to proceed this but i still have the problem that whatever the number is, bigger or less than 25 the code works anyways .. here is the part of my code to implement this :

main proc

mov   ax,@data       ; set up data segment
mov   ds,ax

mov   ah,9              ; send message with instructions for user
mov   dx,offset msg1
int   21h            


call keyin          ;gets user input

SUB AL, 48      ;changes ASCII value into numeric value for further processing
MOV AH,0
MOV num1 , AX       ;saves user input to variable num1

call keyin        ;gets user input

SUB AL, 48      ;changes ASCII value into numeric value for further processing
MOV AH,0
MOV num2 , AX       ;saves user input to variable num2, so now we have both digits


CHECKINPUT:

CMP AX,25
JAE WARNING 
JMP STEP1

WARNING:

mov   ah,09              
mov   dx,offset msg4
int   21h
JMP CHECKINPUT 
  • BTW am using emu8086
  • here is my code if needed

Thanks

Henry K.
  • 7
  • 3
  • "BTW" don't create duplicate user accounts. Anyway, use the emulator to single step the code, you will see the error. – Jester Dec 11 '16 at 00:59
  • Sorry i badly need this code to be finished so i did that ... – Henry K. Dec 11 '16 at 01:12
  • I uses the single step many and many times but i got nothing at last :/ .. any help ! – Henry K. Dec 11 '16 at 01:32
  • 2
    Okay so you know there is a problem with checking the input. Single step the code (or put a breakpoint) at the `cmp ax, 25`. Then check whether `AX` has the correct value. You will see it does not. Then work backwards, see how that got set, and why it's wrong. – Jester Dec 11 '16 at 01:49
  • Still cannot solve the error ,, thanks a lot for you instructions anyways :) – Henry K. Dec 11 '16 at 02:29

1 Answers1

1

You misplaced the check code!
The step1 calculation must be done before the additional check on the number.

STEP1:
    ...
CHECKINPUT:
    mov     ax, input
    CMP     AX,25
    JA      WARNING 

With a valid range of [1,25], you don't give a warning with jae but with ja.

Sep Roland
  • 33,889
  • 7
  • 43
  • 76