News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

why does this give me an error ?

Started by hfheatherfox07, January 31, 2013, 08:22:19 PM

Previous topic - Next topic

MichaelW

#30
I think it has to be a memory operand, and I see no way to do that with an immediate value in a single statement. This appears to work, but I think they will work only for the last argument:

    mov eax, esp
    printf("%d\n", eax)
   
    push 04030201h
    invoke Proc4, [esp]
   
    mov eax, esp
    printf("%d\n", eax)

    mov eax, esp
    printf("%d\n", eax)
   
    push 04030201h
    mov eax, esp
    invoke Proc4, [eax]
   
    mov eax, esp
    printf("%d\n", eax)

Well Microsoft, here's another nice mess you've gotten us into.

jj2007

Quote from: MichaelW on February 03, 2013, 03:06:14 PM
I think it has to be a memory operand, and I see no way to do that with an immediate value in a single statement.

JWasm can do it, and it's 4 bytes shorter:

   push 78563412h
   invoke testrc, RGBQUAD PTR [esp]  ; workaround for ML using invoke
   pop edx

   invoke testrc, 78563412h   ; direct - works with JWasm but not with ML

   push 78563412h  ; efficient workaround for ML
   call testrc

For ML, push+call is the only way out.

MichaelW

Yes, the problem for ML appears to be the declared parameter type, in combination with the type checking, that according to some arguments I recall seeing, ML does not do :biggrin:


Proc7 proc arg:DWORD
    push ebx
    lea ebx, arg
    ASSUME ebx:PTR RGBQUAD
    printf("(%d)\t", SIZEOF arg)
    movzx eax, [ebx].rgbBlue
    printf("%d\t", eax)
    movzx eax, [ebx].rgbGreen
    printf("%d\t", eax)
    movzx eax, [ebx].rgbRed
    printf("%d\t", eax)
    movzx eax, [ebx].rgbReserved
    printf("%d\n", eax)
    ASSUME ebx:NOTHING
    pop ebx
    ret
Proc7 endp

invoke Proc7, 04030201h



But it's more code, either way you go.
Well Microsoft, here's another nice mess you've gotten us into.

hfheatherfox07

Quote from: MichaelW on February 03, 2013, 02:09:24 PM
In my test ML 6.15 had problems passing an RGBTRIPLE structure, but I think this could be due entirely to a longstanding bug with passing bytes on the stack. All of the other structures I tested could be accessed from the receiving procedure, so I assume they were passed correctly. I didn't have time for this, but it would be interesting to see if it can handle a very long structure with embedded structures, something like ENHMETAHEADER or DEVMODE.

;==============================================================================
include \masm32\include\masm32rt.inc
;==============================================================================

.data
    rgbt  RGBTRIPLE   <1,2,3>
    align 4
    aceh  ACE_HEADER  <1,2,3>
    acl   ACL         <1,2,3,4,5>
    align 4
    rgbq  RGBQUAD     <1,2,3,4>
    rectl RECTL       <1,2,3,4>
    bm    BITMAP      <1,2,3,4,5,6,7>

.code
;==============================================================================
Proc1 proc arg:RGBTRIPLE
    printf("(%d)\t", SIZEOF arg)
    movzx eax, arg.rgbtBlue
    printf("%d\t", eax)
    movzx eax, arg.rgbtGreen
    printf("%d\t", eax)
    movzx eax, arg.rgbtRed
    printf("%d\n", eax)
    ret
Proc1 endp

Proc2 proc arg:ACE_HEADER
    printf("(%d)\t", SIZEOF arg)
    movzx eax, arg.AceType
    printf("%d\t", eax)
    movzx eax, arg.AceFlags
    printf("%d\t", eax)
    movzx eax, arg.AceSize
    printf("%d\n", eax)
    ret
Proc2 endp

Proc3 proc arg:ACL
    printf("(%d)\t", SIZEOF arg)
    movzx eax, arg.AclRevision
    printf("%d\t", eax)
    movzx eax, arg.Sbz1
    printf("%d\t", eax)
    movzx eax, arg.AclSize
    printf("%d\t", eax)
    movzx eax, arg.AceCount
    printf("%d\t", eax)
    movzx eax, arg.Sbz2
    printf("%d\n", eax)
    ret
Proc3 endp

Proc4 proc arg:RGBQUAD
    printf("(%d)\t", SIZEOF arg)
    movzx eax, arg.rgbBlue
    printf("%d\t", eax)
    movzx eax, arg.rgbGreen
    printf("%d\t", eax)
    movzx eax, arg.rgbRed
    printf("%d\t", eax)
    movzx eax, arg.rgbReserved
    printf("%d\n", eax)
    ret
Proc4 endp

Proc5 proc arg:RECTL
    printf("(%d)\t", SIZEOF arg)
    printf("%d\t", arg.left)
    printf("%d\t", arg.top)
    printf("%d\t", arg.right)
    printf("%d\n", arg.bottom)
    ret
Proc5 endp

Proc6 proc arg:BITMAP
    printf("(%d)\t", SIZEOF arg)
    printf("%d\t", arg.bmType)
    printf("%d\t", arg.bmWidth)
    printf("%d\t", arg.bmHeight)
    printf("%d\t", arg.bmWidthBytes)
    movzx eax, arg.bmPlanes
    printf("%d\t", eax)
    movzx eax, arg.bmBitsPixel
    printf("%d\t", eax)
    printf("%d\n\n", arg.bmBits)
    ret
Proc6 endp

;==============================================================================
start:
;==============================================================================
    invoke Proc1, rgbt
    invoke Proc2, aceh
    invoke Proc3, acl
    invoke Proc4, rgbq
    invoke Proc5, rectl
    invoke Proc6, bm

    inkey
    exit
;==============================================================================
end start


(3)     3       0       3
(4)     1       2       3
(8)     1       2       3       4       5
(4)     1       2       3       4
(16)    1       2       3       4
(24)    1       2       3       4       5       6       7


I con NOT compile this why ?

Error:
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

Assembling: main.asm
main.asm(18) : error A2008: syntax error : (
main.asm(20) : error A2008: syntax error : (
main.asm(22) : error A2008: syntax error : (
main.asm(24) : error A2008: syntax error : (
main.asm(29) : error A2008: syntax error : (
main.asm(31) : error A2008: syntax error : (
main.asm(33) : error A2008: syntax error : (
main.asm(35) : error A2008: syntax error : (
main.asm(40) : error A2008: syntax error : (
main.asm(42) : error A2008: syntax error : (
main.asm(44) : error A2008: syntax error : (
main.asm(46) : error A2008: syntax error : (
main.asm(48) : error A2008: syntax error : (
main.asm(50) : error A2008: syntax error : (
main.asm(55) : error A2008: syntax error : (
main.asm(57) : error A2008: syntax error : (
main.asm(59) : error A2008: syntax error : (
main.asm(61) : error A2008: syntax error : (
main.asm(63) : error A2008: syntax error : (
main.asm(68) : error A2008: syntax error : (
main.asm(69) : error A2008: syntax error : printf
main.asm(70) : error A2008: syntax error : printf
main.asm(71) : error A2008: syntax error : printf
main.asm(72) : error A2008: syntax error : printf
main.asm(77) : error A2008: syntax error : (
main.asm(78) : error A2008: syntax error : printf
main.asm(79) : error A2008: syntax error : printf
main.asm(80) : error A2008: syntax error : printf
main.asm(81) : error A2008: syntax error : printf
main.asm(83) : error A2008: syntax error : (
main.asm(85) : error A2008: syntax error : (
main.asm(86) : error A2008: syntax error : printf
_
Assembly Error
Press any key to continue . . .
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

herge


Hi Everbody:

You can get to the CL.EXE from C++ Microsoft 2008
Start C++
Tools
Command prompt

Regards herge
Regards herge
Read "Slow Death by Rubber Duck"
for chemical Laughs.

qWord

MREAL macros - when you need floating point arithmetic while assembling!

hfheatherfox07

Quote from: MichaelW on February 01, 2013, 04:51:42 PM
This is what I used for the above, but note that it depends on your having an appropriate PSDK installed:

set file="test"
set PATH=C:\Program Files\Microsoft Visual C++ Toolkit 2003\bin;%PATH%
set INCLUDE=C:\Program Files\Microsoft SDK\include;C:\Program Files\Microsoft Visual C++ Toolkit 2003\include;%INCLUDE%
set LIB=C:\Program Files\Microsoft SDK\lib;C:\Program Files\Microsoft Visual C++ Toolkit 2003\lib;%LIB%

cl /W4 /Fa %file%.c

: cl /W4 /O2 /G6 /FA %file%.c

: cl /W4 %file%.c /link advapi32.lib

pause



@MichaelW
I am sorry for asking , I know this is the masm forum and not C , but I can not get an answer anywhere!
If I want to add a resource file to that How do I do that?

Also I have used your Buid.Bat for C++ and I get an error but it still buids , Why?
The second example it will not build  :biggrin:

Batch files are so plentyfull for masm but non that work for .c and .cpp

If you have time ....thank you!
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

MichaelW

I had no working examples to test, so I selected:

\Program Files\Microsoft SDK\Samples\multimedia\gdi\Fonts\FontView

And (eventually) I was able to build and link everything without error using this batch file:

set PATH=C:\Program Files\Microsoft Visual C++ Toolkit 2003\bin;C:\Program Files\Microsoft SDK\bin;C:\MASM32\bin;%PATH%
set INCLUDE=C:\Program Files\Microsoft SDK\include;C:\Program Files\Microsoft Visual C++ Toolkit 2003\include;%INCLUDE%
set LIB=C:\Program Files\Microsoft SDK\lib;C:\Program Files\Microsoft Visual C++ Toolkit 2003\lib;%LIB%

cl /W4 /c fontview.c
pause
cl /W4 /c tools.c
pause
cl /W4 /c status.c
pause
cl /W4 /c dialogs.c
pause
cl /W4 /c display.c
pause
rc fontview.rc
pause
cvtres /MACHINE:IX86 /OUT:rsrc.obj fontview.res
pause
link fontview.obj tools.obj status.obj dialogs.obj display.obj rsrc.obj user32.lib gdi32.lib
pause


There are probably more compact/easier ways to do this (without nmake), but I went for individual command lines with pauses between them because I was expecting more errors than I encountered.

Note that cvtres.exe was not included with the PSDK or VC Toolkit 2003, and I could not see any way complete the build without it, so I used the copy in the MASM32\bin directory.

I have not done much C++, but here is a sampling of the command lines that I have used, successfully for at least most of them:

cl /c /FA /O2 /D "WIN32" /D "_CONSOLE" /ML /W4 /EHsc /TP test.cpp

cl /FA /O2 /D "WIN32" /D "_CONSOLE" /ML /W4 /EHsc /TP test.cpp

cl /c /FA /O2 /W4 /MD testlib.cpp /link EXPORT:Test /NODEFAULTLIB

cl /FA /O1 /ML /W4 /EHs /TP test.cpp

cl /FA /O2 /LD /D "WIN32" /D "_CONSOLE" /ML /W4 /EHsc /TP cinout.cpp

Well Microsoft, here's another nice mess you've gotten us into.

hfheatherfox07

Thanks MichaelW

Still have trouble with one of the cpp but....

My original question to this thread ...I have found the full source and that code works ....
But the source is the graphics for a trainer , is that allowed ? even though there is no trainer stuff inside...
Cool graphics
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

hfheatherfox07

Also I found out why I was getting the error:

: error LNK2019: unresolved external symbol __imp__MessageBoxA@16 refer
enced in function _WinMain@16


have to add :
#pragma comment(lib,"user32.lib");
under  #include <windows.h>

So:
#include <windows.h>
#pragma comment(lib,"user32.lib");  :biggrin:

Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

hfheatherfox07

Quote from: MichaelW on February 06, 2013, 04:56:24 PM

Note that cvtres.exe was not included with the PSDK or VC Toolkit 2003, and I could not see any way complete the build without it, so I used the copy in the MASM32\bin directory.


I found cvtres.exe  in PSDK(Microsoft Platform SDK) \bin\win64
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

hfheatherfox07

Thank again MichaelW :greenclp:
:biggrin:

Here is another C example compiling exe and dll  use Batch File :biggrin:
So now to try to compile some cpp with rsrc using batch file
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

hfheatherfox07

I need a little help with this .cpp
I can not seem to ad the about dialog and the commands for the menu ...this should be straight forward :(
Lesson is included ...if anybody has time ...it is all compiled except those ...
745 AM going to bed 

Thank You
Your code and your skills will be assimilated. Your programming language is irrelevant.
We are the ASM Borg and you will become part of us. Compile and be assembled.

MichaelW

To compile a CPP source I think your command line will need to include as a minimum /TP, /ML or /MD (or /MT if the app is multithreaded), and /EHsc or similar. I had to experiment with the options to determine what my app needed, and I probably included some that I did not need. Also, some of the command lines I posted were used to create libraries/DLLs. I use a batch file like this to get a short listing of the options for CL and LINK:

cl /? > clcmd.txt
link /? > linkcmd.txt
pause


Well Microsoft, here's another nice mess you've gotten us into.

MichaelW

I can build the DrawLite app with this batch file:

set PATH=C:\Program Files\Microsoft Visual C++ Toolkit 2003\bin;C:\Program Files\Microsoft SDK\bin;C:\MASM32\bin;%PATH%
set INCLUDE=C:\Program Files\Microsoft SDK\include;C:\Program Files\Microsoft Visual C++ Toolkit 2003\include;%INCLUDE%
set LIB=C:\Program Files\Microsoft SDK\lib;C:\Program Files\Microsoft Visual C++ Toolkit 2003\lib;%LIB%

cl /c /ML /W4 /EHs /TP main.cpp
pause
cl /c /ML /W4 /EHs /TP MainWindow.cpp
pause
cl /c /ML /W4 /EHs /TP AboutDialog.cpp
pause
rc resource.rc
pause
cvtres /MACHINE:IX86 /OUT:rsrc.obj /MACHINE:IX86 resource.res
pause
link main.obj MainWindow.obj AboutDialog.obj rsrc.obj user32.lib gdi32.lib
pause


With a few warnings and no errors, but the window procedure in the MainWindow source does only the absolute minimum, so the app is mostly non-functional.

Note that I made no attempt to minimize the CL command lines.

Well Microsoft, here's another nice mess you've gotten us into.