assembly - invoke error when trying to exit program -


i have code

restart:             mov edx, offset prompt5             call writestring             mov edx, 0               mov edx , offset buffer             call readstring             cmp edx, 'n'  or 'n'             je exit             cmp edx, 'y'  or 'y'             je readinput             jne restart 

this code ask user enter either y or y yes. if enter y or y program start beginning, if user enter else beside y or y , n or n. if user enter n or n program exits.

why invoke error on je exit line

thank in advance helping

you can't compare 2 values @ same time. when cmp al, 'y' or 'y' assembler calculate bitwise or of 'y' , 'y', 'y'. instruction becomes equivalent of cmp al, 'y'.

if want compare against both of values, need each comparison separately.

cmp al,'y' je l1 cmp al,'y' je l1 

assuming l1 label want jump if user enters y or y. i'm basing on modified code in answer - not original code in question.

then, 'restart' case, don't need use jne - can use unconditional jmp. if you've reached point in code, you've failed match of other conditions, know character not equal y, y, n or n - no more testing required.

update

i should add i'm assuming functions writechar , crlf preserve al register. because if readchar returns read character in al, writechar or crlf end overwriting else, code never going work.

if al not being preserved, save temporarily on stack doing this:

call readchar push eax call writechar call crlf pop  eax cmp  al,'n' ...etc 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -