views:

41

answers:

2

Hello everybody, I'm stuck writing my program Here's what I wanted it to do:

  1. display a welcome message inside a console
  2. Wait for the user to imput a number from 0 to 9]
  3. compare that number to 0
  4. display a message if it is, else exit

Here is what I currently have:

.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib
include \masm32\include\masm32.inc
includelib \masm32\lib\masm32.lib

.data
capt db "SCHiM says: ",0
txt       db "Enter a number 0-9:",0

.data?

data db ?

.code

start:


call AllocConsole

push offset txt
call StdOut

push 1
push offset data
call StdIn

mov al, data

cmp al, 0h
jz eqzero

invoke ExitProcess, NULL

eqzero:

push offset capt
call StdOut
push offset data
call StdOut

endloop:
jmp endloop

invoke ExitProcess, NULL
end start 

The program assembles & links perfectly without any warnings or errors But cmp always returns 1, if I print the value in data (with StdOut) it shows me the exact value I've put in. So why isn't it working?

Thanks in advance

+1  A: 

You are probably moving the address of data to al somehow. Try mov al, [data] to get the value stored at data.

Jens Björnhager
No, in MASM the original notation is correct.
atzz
Your solution has no effect, my program still doesn't take the jumpI've also run it though ollydbg (a debugger)I see this line, somehow the value stored in al is 01 instead of 000040101B |. A0 30304000 MOV AL,BYTE PTR DS:[403030]ps: I'm sorry for the horrible format of my posts, I'm not used to the way stackoverflow wraps it's text
Rick
+1  A: 

Try this:

cmp al, '0'

-or-

cmp al, 48

Why? Because you are interested in character '0', not numeric 0. Character '0' is encoded as 48 in most encodings.

atzz
Thank you!!, that worked #solved#
Rick
@Rick Don't forget to accept answer.
Jens Björnhager
@Jens Bjornhager, Done
Rick