News:

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

What am I doing wrong?

Started by julioposa2, September 08, 2010, 11:38:18 AM

Previous topic - Next topic

julioposa2

Hi,

I have found a strange behavior in masm32, and that happens when using offset subtraction in the parameters passed in an invoke instruction.

For example:
invoke MySub, OFFSET label1 - OFFSET label2

generates different code to:
push OFFSET label1 - OFFSET label2
call MySub


The difference is that the pushed value in the first example is not correctly calculated by masm32. Using equates does not fix the issue.

Am I doing something wrong or is this a bug?

Thank you very much in advance

Vortex

Hi julioposa2,

Welcome to the forum.

Running the test code below, I cannot see any problem. Would you please post here your code so we can reproduce the issue?


.386
.model flat,stdcall
option casemap:none

include     \masm32\include\windows.inc
include     \masm32\include\kernel32.inc
include     \masm32\include\msvcrt.inc

includelib  \masm32\lib\kernel32.lib
includelib  \masm32\lib\msvcrt.lib


MySub       PROTO :DWORD

.data

label1  db 'abcd',0
label2  db 'efgh',0

message db 'eax = %X',13,10,13,10,0

.data?

.code

start:

    invoke  MySub,OFFSET label1 - OFFSET label2

    push    OFFSET label1 - OFFSET label2
    call    MySub

    invoke  ExitProcess,0

MySub PROC param:DWORD

    invoke  crt_printf,ADDR message,param
    ret

MySub ENDP

END start


The ouput is :


eax = FFFFFFFB

eax = FFFFFFFB

julioposa2

Hi Vortex, thank you very much for your prompt reply.

I think the issue only happens when referencing labels from inside the code. I was unable to reproduce the problem with your code, but modify it in this way and tell me the results:
.386
.model flat,stdcall
option casemap:none

include     \masm32\include\windows.inc
include     \masm32\include\kernel32.inc
include     \masm32\include\msvcrt.inc

includelib  \masm32\lib\kernel32.lib
includelib  \masm32\lib\msvcrt.lib


MySub       PROTO :DWORD

.data

label1  db 'abcd',0
label2  db 'efgh',0

message db 'eax = %X',13,10,13,10,0

.data?

.code

start:
    jmp cls
cls:
    invoke  MySub,OFFSET cls - OFFSET start

    push    OFFSET cls - OFFSET start
    call    MySub

    invoke  ExitProcess,0

MySub PROC param:DWORD

    ;invoke  crt_printf,ADDR message,param
    ret

MySub ENDP

END start


The value pushed in the invoke sentence is 0Ah, while the value pushed in the manual push sentence is 2.

Best regards

clive

Appears to be a phase error between passes in MASM 6.15

MASM 10.00 doesn't even like your syntax, prefering


    mov eax,OFFSET cls - OFFSET start
    invoke  MySub,eax
It could be a random act of randomness. Those happen a lot as well.

julioposa2

Thank you, I thought I was getting mad  :P

What masm version do you refer to? I download from this page the masm32 package version 10 and the ml assembler that comes within it is version 6.14.8444

Regards

clive

I typically use MASM 6.15 for most general 16 and 32-bit code, I'd probably use something else for SSE2,3,4 code.

Microsoft (R) Macro Assembler Version 6.15.8803
Microsoft (R) Macro Assembler Version 10.00.30319.01
It could be a random act of randomness. Those happen a lot as well.

julioposa2

Thanks.
I though the v10 package from the main page contained all components up to date. Why is the 6.14 version still packaged in it?
Is the latest version publicly available anywhere?

Thanks

clive

Quote from: julioposa2
I though the v10 package from the main page contained all components up to date. Why is the 6.14 version still packaged in it?
Is the latest version publicly available anywhere?

Probably licencing issues, I bought my earlier versions. Plus the new version probably breaks some of the older libraries or macros. All the MASM 6.1x versions are quite serviceable.

Microsoft has MASM 10.00 posted on their website for download, perhaps with another package. Try Google or Bing?
It could be a random act of randomness. Those happen a lot as well.

Vortex

Hi julioposa2,

I use the same version 6.14.8444

julioposa2

Confirmed that the same issue happens in ml version "6.15.8803".
Tested also in 8.x and 10.x and ml refuses to assemble those instructions as commented by Clive.

Vortex, do you reproduce the issue with the offsets in the code section as I suggested before?

Thanks

japheth

It's clearly a Masm v6 bug. It happens when a jump instruction is between the two code labels.

Masm v8+ is better, because at least it complains and doesn't silently produce wrong code. As for the PUSH, there exists a workaround for Masm v8:


     PUSHD label2 - label1   ;using PUSHD makes Masm v8 accept the expression


Vortex

Hi julioposa2 ,

I can reproduce the issue. Here is the result :


eax = A

eax = 2

TASMUser

Quote from: julioposa2 on September 08, 2010, 01:45:07 PM
Hi Vortex, thank you very much for your prompt reply.

I think the issue only happens when referencing labels from inside the code. I was unable to reproduce the problem with your code, but modify it in this way and tell me the results:
.386
.model flat,stdcall
option casemap:none

include     \masm32\include\windows.inc
include     \masm32\include\kernel32.inc
include     \masm32\include\msvcrt.inc

includelib  \masm32\lib\kernel32.lib
includelib  \masm32\lib\msvcrt.lib


MySub       PROTO :DWORD

.data

label1  db 'abcd',0
label2  db 'efgh',0

message db 'eax = %X',13,10,13,10,0

.data?

.code

start:
    jmp cls
cls:
    invoke  MySub,OFFSET cls - OFFSET start

    push    OFFSET cls - OFFSET start
    call    MySub

    invoke  ExitProcess,0

MySub PROC param:DWORD

    ;invoke  crt_printf,ADDR message,param
    ret

MySub ENDP

END start


The value pushed in the invoke sentence is 0Ah, while the value pushed in the manual push sentence is 2.

Best regards

You are using two different segment declarations: ".code" and ".data". MASM/TASM will take such declarations very seriously.
Try to put constants into the ".code" segment.

japheth

Quote from: TASMUser on September 08, 2010, 09:04:33 PM
You are using two different segment declarations: ".code" and ".data". MASM/TASM will take such declarations very seriously.
True. However, nobody did claim that Masm/Tasm will ignore those declarations. Anyway, it's off-topic, because the two labels are in the very same segment.

Quote from: TASMUser on September 08, 2010, 09:04:33 PM
Try to put constants into the ".code" segment.
The labels (="relocatable constants") are in the .code segment already.

Vortex

Poasm Version 6.00.4 creates the correct code :


eax = 2

eax = 2