News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

menu output to console

Started by Xor Stance, April 09, 2005, 02:34:49 AM

Previous topic - Next topic

Xor Stance

I tried my best to read the Win32API reference, I suggest to add "MG_OK". Can you guys help me please?

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

WinMain proto :DWORD,:DWORD,:DWORD,:DWORD

.DATA
msg1 db "Choose one:",0
msg2 db "What's your name",0
msg3 db "What's your age?",0

.DATA?
buffer db 100 dup(?)

.CONST
IDM_NAME "name" equ 1
IDM_MENU "age" equ 2

Start:

invoke StdOut,ADDR msg1
invoke StdIn,ADDR buffer,100

WinMain proc uMsg:UINT, wParam:WPARAM
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG

mov eax,wParam
.IF ax==IDM_NAME

invoke StdOut,ADDR msg2,ADDR MG_OK
invoke StdIn,ADDR buffer,100

.ELSEIF ax==IDM_AGE

invoke StdOut,ADDR msg2
invoke StdIn,ADDR buffer,100,ADDR MG_OK

.ENDIF
.ELSE
invoke DefWindowProc,uMsg,wParam
.ENDIF

invoke ExitProcess,0
WndProc endp
End Start


Xor Stance

Is it on the includes? or might I need to include it? It sounded kind like a joke but it's serious too.
I mean that I needed to put as a constant the menus but I need to define a variable as a integer, then after he types his name.
Since I'm not quite familiar with masm syntax, somehow how should it be. I'm trying my best! and the include files I read, I somehow
understand some but it's too complicated on how to use it, I wanted to learn first from console then later to Windows; just I kinda
suck on this stuff, I haven't take that much time but I know from console will be fast.

MichaelW

I cannot tell what you are trying to do with this code. When I attempt to assemble it, as posted, I get 13 errors.


C:\masm32\My\_TRY\xor.asm(19) : error A2008: syntax error : name
C:\masm32\My\_TRY\xor.asm(20) : error A2008: syntax error : age

The problem code is:

(19) IDM_NAME "name" equ 1
(20) IDM_MENU "age" equ 2


The proper syntax for EQU is:
Quote
symbol EQU expression

The symbol must be a unique name. The expression can be an integer, a constant expression, a one- or two- character string constant (four-character on the 80386/80486), or an expression that evaluates to an address.


C:\masm32\My\_TRY\xor.asm(22) : error A2108: use of register assumed to ERROR
C:\masm32\My\_TRY\xor.asm(37) : error A2108: use of register assumed to ERROR
C:\masm32\My\_TRY\xor.asm(42) : error A2108: use of register assumed to ERROR

These errors are a side effect of the missing .CODE directive the should precede Start.


C:\masm32\My\_TRY\xor.asm(24) : error A2006: undefined symbol : StdOut
C:\masm32\My\_TRY\xor.asm(25) : error A2006: undefined symbol : StdIn
C:\masm32\My\_TRY\xor.asm(34) : error A2006: undefined symbol : StdOut
C:\masm32\My\_TRY\xor.asm(35) : error A2006: undefined symbol : StdIn
C:\masm32\My\_TRY\xor.asm(39) : error A2006: undefined symbol : StdOut
C:\masm32\My\_TRY\xor.asm(40) : error A2006: undefined symbol : StdIn

These errors are because your includes do not include:
include \masm32\include\masm32.inc
includelib \masm32\lib\masm32.lib


C:\masm32\My\_TRY\xor.asm(27) : error A2111: conflicting parameter definition

This error is because you WinMain procedure declaration does not match the prototype.


C:\masm32\My\_TRY\xor.asm(43) : fatal error A1011: directive must be in control block

And this error is due to a misplaced .ELSE.

When you solve these problems, you will uncover some additional errors, but they are essentially more of the same.

You might take a look at the example Vortex posted here:

http://www.masmforum.com/simple/index.php?topic=1094.0
eschew obfuscation

thomasantony

Hi,
   You haven't included masm32.inc and masm32.lib to use StdOut. Are you using a GUI app or is it linked as a console app. If it is a console app it cannot usually have a window or a menu. If it is a GUI App, you need to get a console first using AllocConsole.

Thomas :U
There are 10 types of people in the world. Those who understand binary and those who don't.


Programmer's Directory. Submit for free

Xor Stance

I got tire for now, what I wanted that the user displays to elect "name or age" after that if he/she inputs name he will have to put his name,
I fix some but them I got more than I do.

.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\masm32.inc
includelib \masm32\lib\masm32.lib

WinMain :DWORD,:DWORD,:DWORD,:DWORD

.DATA
msg1 db "Choose one:",0
msg2 db "What's your name",0
msg3 db "What's your age?",0

.DATA?
buffer db 100 dup(?)
CommandLine LPSTR?

.CONST
IDM_NAME equ "Name" 
IDM_MENU equ "Age"

.CODE
Start:

invoke StdOut,ADDR msg1
invoke StdIn,ADDR buffer,100

WinMain proc wParam:WPARAM, CmdLine:LPSTR, CmdShow:DWORD

LOCAL wc:WNDCLASSEX
LOCAL msg:MSG

mov eax,wParam
.IF ax==IDM_NAME

invoke StdOut,ADDR msg2,ADDR
invoke StdIn,ADDR buffer

.ELSEIF ax==IDM_AGE

invoke StdOut,ADDR msg2
invoke StdIn,ADDR buffer

.ENDIF
invoke wParam
.ENDIF

invoke ExitProcess,0
End Start



Xor Stance

Does masm supports most Win32API? So I founded new things like "GetStdHandle" in console apps. I know that some like declaring the numbers
of byte it's not necessary how the Win32API tells it. 

thomasantony

#6
Hi,
 Understand what your code does before posting it ::) . You don't have a window then why do you have a WndProc? Who will set the values of wParam? ::) . Read Iczelion's tuts first. I will give some pointers on your problem.
1. Display a list like :
 A. Name
 B. Age
 Choose:
2. Use Stdin
3. Check if input is 'A', then display question and get name from user else do the stpes to get the age

BTW, StdOut calls GetStdHandle and then WriteFile. As of the numbers use the constants in windows.inc

Thomas
There are 10 types of people in the world. Those who understand binary and those who don't.


Programmer's Directory. Submit for free

Xor Stance

I just forgot about WndProc and and wParam, the thing is that does it requires the command line in console? I knew that it was code from the windows and I thought some instructions could be use in the console. When I declare before I declare .IF which instruction should be use if it's
in Eax register? mov eax,wParam was before, I guess it will be move the 16-bits on eax?

Xor Stance

.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\masm32.inc
includelib \masm32\lib\masm32.lib

.DATA
msg1 db "Choose one:",0
msg2 db "What's your name",0
msg3 db "What's your age?",0

.DATA?
buffer db 100 dup(?)

.CONST
NAME equ "Name" 
AGE equ "Age"

.CODE
Start:

invoke StdOut,ADDR msg1
invoke StdIn,ADDR buffer,100

mov eax,ax
.IF ax==NAME

invoke StdOut,ADDR msg2
invoke StdIn,ADDR buffer,100

.IF NAME=='A'

.ELSEIF ax==AGE

.ELSE

stpes==AGE

nvoke StdOut,ADDR msg3
invoke StdIn,ADDR buffer

.ENDIF
.ENDIF

invoke ExitProcess,0
End Start

(29) : error A2008: syntax error NAME
(34) : error A2008: syntax error NAME
(36) : fatal error A1011: directive must be in control block

roticv

mov eax,ax
What are you trying to do? Move value in 16bit register to a 32bit register? If so, use movzx or movsx and not mov.


.IF NAME=='A'

.ELSEIF ax==AGE

.ELSE

stpes==AGE


NAME is a constant.


Xor Stance

.DATA
msg1 db "Choose one:",0
msg2 db "What's your name",0
msg3 db "What's your age?",0

.DATA?
buffer db 100 dup(?)

.CONST
NAME equ "Name" 
AGE equ "Age"

.CODE
Start:

invoke StdOut,ADDR msg1
invoke StdIn,ADDR buffer,100

movsx eax,ax
.IF ax==NAME

invoke StdOut,ADDR msg2

invoke StdIn,ADDR buffer,100

.ELSEIF ax=='A'

.ELSEIF stpes==ax

.ENDIF

.IF ax==AGE

nvoke StdOut,ADDR msg3
invoke StdIn,ADDR buffer

.ENDIF


I give up for now, I'm going to continue with C and Icze. I kept with 2 errors with this code.

thomasantony

Hi,
   Here is a piece of code


; do all the includes and data etc.
.data
msg1   db "A. Name",13,10
          db "B. Age",13,10
          db "Choose: ",0
.code
start:
    invoke STDOut,ADDR msg1
    invoke STDIn,ADDR Buffer,100
    movzx eax,byte ptr[Buffer]   ; take first byte from buffer
    .if eax=='A'
          invoke Stdout,ADDR msg2
    .else
          invoke StdOut,ADDR msg3
    .endif
    invoke StdIn,ADDR Buffer,100
    invoke StdOut,ADDR buffer

end start


Thomas
     :U
There are 10 types of people in the world. Those who understand binary and those who don't.


Programmer's Directory. Submit for free

Xor Stance


sluggy

Xor,
your code shows that you do not understand some of the fundamentals of programming, let alone understand asm. I would suggest that you learn some basics (like string comparison) before doing any more, you can't solve more complex bugs when your code is full of simple ones.