The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: herman on June 19, 2006, 05:46:10 PM

Title: Beginner problem - GetCL, conditions & statements
Post by: herman on June 19, 2006, 05:46:10 PM
1st... Welcome :bg
2nd...
:'( I made little program using parametrs and I have problem with making condition:

.386

.MODEL FLAT, STDCALL

OPTION CASEMAP:NONE
INCLUDE    \masm32\include\windows.inc
INCLUDE    \masm32\include\user32.inc
INCLUDE    \masm32\include\kernel32.inc
INCLUDELIB \masm32\lib\user32.lib
INCLUDELIB \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib
include \masm32\include\masm32.inc

.DATA
buffer BYTE 128 (0)
lpMsg db "Error",0
lpCaption db "Program fail",0
lpOK db "OK",0
.CODE
start:
INVOKE GetCL,1,ADDR buffer
.IF buffer==2
INVOKE MessageBox,0,lpMsg,lpCaption,MB_ICONERROR             ;statement #1
.ELSE
INVOKE MessageBox,0,ADDR buffer,ADDR lpOK,MB_ICONINFORMATION ; second
INVOKE WinExec,ADDR buffer,SW_SHOW                           ; statement
.endif
INVOKE ExitProcess,0

END start

Masm helper wrote:
Quote
GetCl will retreive the argument specified in the procedure call and return the argument in the buffer specified.(...)
Return values
1 = successful operation
2 = no argument exists at specified arg number
3 = non matching quotation marks
4 = empty quotation marks
So I set condition which compares buffer with 2, because i want to see message when there is no parameter,but (there is problem) when I run my application without parameter it shows "GOOD" message (MessageBox,0,ADDR buffer,ADDR lpOK,MB_ICONINFORMATION) too.

My question: With what I have to compare buffer if I want to execute statement #1? :red

I apologize for my bad english :red
Title: Re: Beginner problem - GetCL, conditions & statements
Post by: SamiP on June 19, 2006, 05:52:24 PM
GetCL return value is returned in eax, so you need to check if eax is 2. If there is argument then the buffer has it, and the return value in eax is 1.


invoke GetCL, 1, ADDR buffer
.if eax == 2
  ;Here show message that no argument exists!
.else
  ;Do what ever
.endif
Title: Re: Beginner problem - GetCL, conditions & statements
Post by: herman on June 19, 2006, 06:26:59 PM
Ok i changed it, but still doesn't work  :(

LOOK (http://img476.imageshack.us/img476/6699/masmeax7om.jpg)
Title: Re: Beginner problem - GetCL, conditions & statements
Post by: stanhebben on June 19, 2006, 06:29:30 PM
You forgot to use ADDR at the first MessageBox.
Title: Re: Beginner problem - GetCL, conditions & statements
Post by: herman on June 19, 2006, 06:41:29 PM
Ohh thanx :red - Unfortunately it doesn't change situation. Notice that shows MsgBox with MB_ICONINFORMATION, but it should show MesgBox with MB_ICONERROR

EDIT:
Ok, wroking :bdg . I put:
.if eax!=1
instead of
.if eax==2
But still don't know why buffer doesn't return 2 if program ran without parametrs :dazzled:
Title: Re: Beginner problem - GetCL, conditions & statements
Post by: hutch-- on June 20, 2006, 01:45:34 AM
Hi herman,

Welcome on board. When you are testing a register that can return multiple values try something like this.


; your GetCL code.

.if eax == 1
  ; ok result
.elseif eax == 2
  ; error
.elseif eax == 3
  ; error
.elseif eax == 4
  ; error
.endif


You can be a bit more efficient depending on what you want to test but this will give you the range of results.
Title: Re: Beginner problem - GetCL, conditions & statements
Post by: SamiP on June 20, 2006, 12:52:53 PM
For me your code works. I just changed from your original code to check if eax == 2 and added the ADDR to first MessageBox line and it displays error message with ICONERROR if the cmdline is empty.

Check full code here


.386
.MODEL FLAT, STDCALL
OPTION CASEMAP:NONE

INCLUDE    \masm32\include\windows.inc
INCLUDE    \masm32\include\user32.inc
INCLUDE    \masm32\include\kernel32.inc
INCLUDELIB \masm32\lib\user32.lib
INCLUDELIB \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib
include    \masm32\include\masm32.inc

.DATA
buffer BYTE 128 (0)
lpMsg db "Error",0
lpCaption db "Program fail",0
lpOK db "OK",0

.CODE
start:
INVOKE GetCL,1,ADDR buffer
.IF eax==2
INVOKE MessageBox,0,ADDR lpMsg, ADDR lpCaption,MB_ICONERROR             ;statement #1
.ELSE
INVOKE MessageBox,0,ADDR buffer,ADDR lpOK,MB_ICONINFORMATION ; second
INVOKE WinExec,ADDR buffer,SW_SHOW                           ; statement
.endif
INVOKE ExitProcess,0
END start

Title: Re: Beginner problem - GetCL, conditions & statements
Post by: GregL on June 20, 2006, 11:32:04 PM

For one thing


.DATA
    buffer    BYTE 128 (0)


needs to be


.DATA
    buffer    BYTE 128 DUP(0)

Title: Re: Beginner problem - GetCL, conditions & statements
Post by: SamiP on June 21, 2006, 07:43:41 AM
I missed that completely, and when I tested it with some parameters, they were so short that they only overwrite lpMsg and/or lpCaption variables and thus everything seemed to be ok.

Title: Re: Beginner problem - GetCL, conditions & statements
Post by: GregL on June 21, 2006, 07:07:51 PM
SamiP,

We have all been there.  :bg