Original Post
I have been learning assembly and i quite like it, it's a nice way of programming. However, i have come across a problem. Here is my code:
It is supposed to ask the user to enter something, and if the user enterd 1 character, exit the program. If they dont it prints a message and asks for it again.
I think the problem lies in my if statements, but thats all i know.
I am using FASM and all it's windows macros if it helps
include 'win32ax.inc' ;The windows **** that i need.data InputHandle DD ? ;This will store the input handle from windows OutputHandle DD ? ;This will store the output handle from windows NumberOfCharactersRead DD ? ;How many characters were read from the console NumberOfCharactersWritten DD ? ;How many characters were written to the console UserInput DB ? ;What the user actully typed in WrongNumberOfCharactersString DB 'You must only enter 1 character!' ;The string that will be displayed when the user doesnt enter the right number of characters EndlineCharacter DB 13 ;This is the ASCII code for a new line.code Main: invoke AllocConsole ;Init the console invoke GetStdHandle,STD_INPUT_HANDLE ;Put the input handle into eax mov [InputHandle],eax ;Store the input handle in a varible invoke GetStdHandle,STD_OUTPUT_HANDLE ;Put the output handle into eax mov [OutputHandle],eax ;Store the output handle in a varible jmp GetUserInput ;Go and get the user input GetUserInput: invoke ReadConsole,[InputHandle],UserInput,1,NumberOfCharactersRead,0 ;Get the input mov eax,[NumberOfCharactersRead] ;Move how many characters the user enterd into eax in preperation for the if statement mov ebx,1 ;Move how many characters the user was supposed to enter into edx for the if statement cmp eax,ebx ;later jg TooManyCharacters ;If the user enterd too many characters jump to a label jmp ExitProgram ;If the user did everything right, exit the program TooManyCharacters: invoke WriteConsole,[OutputHandle],EndlineCharacter,1,NumberOfCharactersWritten,0 ;Go to a new line invoke WriteConsole,[OutputHandle],WrongNumberOfCharactersString,31,NumberOfCharactersWritten,0 ;Write the error message invoke WriteConsole,[OutputHandle],EndlineCharacter,1,NumberOfCharactersWritten,0 ;Go to a new line jmp GetUserInput ;Try and get the user input again ExitProgram: invoke ExitProcess,0 ;Exit the program.end MainIt is supposed to ask the user to enter something, and if the user enterd 1 character, exit the program. If they dont it prints a message and asks for it again.
I think the problem lies in my if statements, but thats all i know.
I am using FASM and all it's windows macros if it helps