Hi, I'm again trying to understand some MASM syntax. I found the SEGMENT (https://learn.microsoft.com/en-us/cpp/assembler/masm/segment?view=msvc-170) directive on Microsoft's documentation, so I wrote a test programme to understand all the parameters of this directive.
include \Masm32\include\masm32rt.inc
forTest SEGMENT read write execute
strHW db 'Hello World!', 0
strQuery db 'test.exe', 0
VA EQU $ - offset strCFA
strTest db 260 dup(0)
start:
mov strCFA, 'J'
invoke MessageBox, 0, offset strQuery, offset strF1A, 0
push 0
call ExitProcess
forTest ENDS
end start
This programme returns these errors:
Z:\3\test.asm(3) : error A2008: syntax error : read
Z:\3\test.asm(4) : error A2034: must be in segment block
Z:\3\test.asm(5) : error A2034: must be in segment block
Z:\3\test.asm(6) : error A2034: must be in segment block
Z:\3\test.asm(7) : error A2034: must be in segment block
Z:\3\test.asm(9) : error A2034: must be in segment block
Z:\3\test.asm(10) : error A2034: must be in segment block
Z:\3\test.asm(11) : error A2034: must be in segment block
Z:\3\test.asm(11) : error A2006: undefined symbol : strF1A
Z:\3\test.asm(11) : error A2114: INVOKE argument type mismatch : argument : 3
Z:\3\test.asm(11) : error A2006: undefined symbol : strQuery
Z:\3\test.asm(11) : error A2114: INVOKE argument type mismatch : argument : 2
Z:\3\test.asm(13) : error A2034: must be in segment block
Z:\3\test.asm(14) : error A2034: must be in segment block
Z:\3\test.asm(16) : fatal error A1010: unmatched block nesting : forTest
I suppose the error is that it doesn't recognise READ, WRITE and EXECUTE as valid parameters for the SEGMENT directive. I don't understand how this is happening since it seems to be the correct syntax according to the documentation. Even using the code from this post by jj2007 (https://masm32.com/board/index.php?topic=94.msg22039#msg22039), which has a similar syntax, yields a similar error.
Can anyone help me with this? Thanks in advance!
Edit: execute, not executable
with poasm:.686
includelib user32.lib
MessageBoxA proto stdcall :ptr, :ptr, :ptr, :dword
ExitProcess proto stdcall :dword
forTest SEGMENT read write execute
strF1A db 'Hello World!', 0
strQuery db 'test.exe', 0
; VA EQU $ - offset strCFA
strTest db 260 dup(0)
start:
mov strTest, 'J'
invoke MessageBoxA, 0, offset strQuery, offset strF1A, 0
push 0
call ExitProcess
forTest ENDS
end start
Hello Quan,
Adapting Timo's Poasm example to Masm :
.686
.model flat,stdcall
option casemap:none
MessageBoxA proto stdcall :ptr, :ptr, :ptr, :dword
ExitProcess proto stdcall :dword
_data SEGMENT PARA PUBLIC 'DATA'
strF1A db 'Hello World!', 0
strQuery db 'test.exe', 0
; VA EQU $ - offset strCFA
strTest db 260 dup(0)
_data ENDS
_text SEGMENT PARA PUBLIC 'CODE'
start:
mov strTest, 'J'
invoke MessageBoxA, 0, offset strQuery, offset strF1A, 0
push 0
call ExitProcess
_text ENDS
end start
... but why in the world would you want to use those old-school SEGMENT directives when we have the new simplified ones?
.data
[put initialized data here]
.data?
[uninitialized data]
.code
I just don't see the point. You ain't writing DOS programs here ...
executable is wrong, try execute.
MASM SEGMENT (https://learn.microsoft.com/en-us/cpp/assembler/masm/segment?view=msvc-170)
Quote from: sinsi on June 10, 2025, 08:09:25 AMexecutable is wrong, try execute.
Ah oops, that was an oversight on my part. I changed it to
executable in a vain attempt to fix the issue (suggested by GPT :eusa_boohoo:). In the beginning, and just now, I changed it back to
execute and that didn't fix the problem. The assembler doesn't seem to recognise neither
READ,
WRITE or
EXECUTE.
Quote from: NoCforMe on June 10, 2025, 05:42:07 AM... but why in the world would you want to use those old-school SEGMENT directives when we have the new simplified ones?
Mainly curiosity, because the documentation mentions nothing about the directive being deprecated so it should still work. In my example, I want to make a segment that is readable, writable and executable; and the new, simplified ones don't do that. A few other parameters don't work either, e.g.
ALIGN(n) and the rest of the parameters for Characteristics; and I want to make use of them.
And thanks for the code samples, @TimoVJL and @Vortex. The first one is in PoASM, which I'm not yet familiar with. The second one doesn't seem to address some parameters that is causing the error (
READ,
WRITE,
EXECUTE,
SHARED, etc.) But I appreciate them regardless, and will study them a bit more.
One more thing, these parameters don't work for everyone else right? Just to make sure it's not a problem with my machine.
Quote from: Quan on June 10, 2025, 12:43:37 PMOne more thing, these parameters don't work for everyone else right? Just to make sure it's not a problem with my machine.
If I fix the missing label then it assembles fine with ML 14.44.35208.0
Untitled.png
Quote from: Quan on June 10, 2025, 12:43:37 PMA few other parameters don't work either, e.g. ALIGN(n) and the rest of the parameters for Characteristics; and I want to make use of them.
Well, so far as that one goes, a single
ALIGN directive at the top of your
.code section will accoplish exactly the same thing.
Just wondering why you wanted a segment that had read, write and execute attributes: just curiousity?
Quote from: NoCforMe on June 10, 2025, 01:37:15 PMJust wondering why you wanted a segment that had read, write and execute attributes: just curiousity?
Essentially yes. I'm doing an exercise that's using MASM. And with my style of studying, I like to dig around and explore all the possible options that may be beneficial to my exercise, no matter how useless it might be, because it helps me understand the syntax/language more thoroughly. Here I'm trying to make a section that has all of those attributes, because it is possible when I edit the file manually with, say, CFF Explorer.
Quote from: sinsi on June 10, 2025, 01:35:00 PMIf I fix the missing label then it assembles fine with ML 14.44.35208.0
Untitled.png
Oh, what "missing label" are you talking about?
Also my ML.exe seems to be super outdated compared to yours. And I wasn't aware of a way to update ML.exe, where can I find that?
Microsoft (R) Macro Assembler Version 6.14.8444
Quote from: Quan on June 10, 2025, 02:07:24 PMOh, what "missing label" are you talking about?
Your original code didn't define
strF1AQuote from: Quan on June 10, 2025, 02:07:24 PMAlso my ML.exe seems to be super outdated compared to yours. And I wasn't aware of a way to update ML.exe, where can I find that?
Microsoft (R) Macro Assembler Version 6.14.8444
I use ML from Visual Studio, the free community version.
There is a link to download the tools somewhere on the forum.
Ah right lol, that was supposed to be a test programme for me to understand how this works, so forgive me for all the mixed up labels and hiccups in my code. :mrgreen:
And thanks, I really thought using ML.exe that comes packaged with the MASM32 installer should be good enough, didn't think it would be so out of date. I'll try to get that file and test this again, hopefully it works.
Well now that you've satisfied your curiosity I'd really, really recommend just sticking with the regular simplified segment directives.
In my own programming I've never run into a situation where they didn't work for me, and that includes writing DLLs. Maybe if you were writing Windows device drivers you'd need them, or if you're messing around with old 16-bit DOS code.
Otherwise just use them; it'll simplify your assembly programming.
Quote from: NoCforMe on June 10, 2025, 07:00:05 PMIn my own programming I've never run into a situation where they didn't work for me
Self-modifying code (https://masm32.com/board/index.php?topic=5179.0) is one example.
Quote from: jj2007 on June 10, 2025, 08:20:05 PMQuote from: NoCforMe on June 10, 2025, 07:00:05 PMIn my own programming I've never run into a situation where they didn't work for me
Self-modifying code (https://masm32.com/board/index.php?topic=5179.0) is one example.
True, but how often is that actually used or even needed?
Very rarely is my Guess®™.
Poasm can assemble the code below :
.686
.model flat,stdcall
option casemap:none
MessageBoxA PROTO :DWORD,:DWORD,:DWORD,:DWORD
MessageBox TEXTEQU <MessageBoxA>
ExitProcess PROTO :DWORD
PUBLIC start
_data SEGMENT 'DATA'
message1 db 'This is a test.',0
caption1 db 'Hello',0
_data ENDS
_text SEGMENT 'CODE'
start:
xor eax,eax
invoke MessageBox,eax,ADDR message1,ADDR caption1,eax
invoke ExitProcess,0
_text ENDS
.drectve SEGMENT BYTE 'CONST'
db '-entry:_start'
.drectve ENDS
END
It's preferable to use the simplified directives like .data and .code
QuoteI use ML from Visual Studio, the free community version.
There is a link to download the tools somewhere on the forum.
Yes there was at least One thread with references and links to it here .... somewhere ...
Perhaps we Should provide an easily accessible and findable link to the most appropriate updated version for use with the MASM32 SDK.
Perhaps even Include it, along with any other items that require updating and bringing up to speed as it were in a Contemporary version release of the SDK ???
Quote from: sinsi on June 10, 2025, 04:46:03 PMQuote from: Quan on June 10, 2025, 02:07:24 PMAlso my ML.exe seems to be super outdated compared to yours. And I wasn't aware of a way to update ML.exe, where can I find that?
Microsoft (R) Macro Assembler Version 6.14.8444
I use ML from Visual Studio, the free community version.
There is a link to download the tools somewhere on the forum.
Hi, so I did try out an updated version of
ml.exe and it worked. I did have to do some tweakings with the
\masm32\include\winextra.inc file as mentioned in this topic (https://masm32.com/board/index.php?topic=8852.0). Hopefully that's the only thing I have to do to make it work normally.
Quote from: NoCforMe on June 10, 2025, 07:00:05 PMWell now that you've satisfied your curiosity I'd really, really recommend just sticking with the regular simplified segment directives.
Quote from: Vortex on June 11, 2025, 05:08:27 AMIt's preferable to use the simplified directives like .data and .code
Yea, will do :thumbsup:
Also prefer use
.data? If you have big arrays put them there instead otherwise it makes exe bigger
@Stewart might be good suggestions, it only supports SSE,
Especially ml 6.14 bug that makes it take an eternity when using creating big arrays in. Data section :thumbsup:
I prefer uasm because it supports all SIMD instructions and don't have that ml 6.14 bug
Quote from: daydreamer on June 11, 2025, 05:56:50 PMEspecially ml 6.14 bug that makes it take an eternity when using creating big arrays
Yeah, that bug is a nuisance, but there is a workaround:
include \masm32\include\masm32rt.inc
.data?
Buffersize=16777216 ; 16 MB
MyFatArray LABEL byte
ORG $+Buffersize-1
db ?
EndofArray db ?
.code
start:
mov EndofArray, "e"
mov ecx, Buffersize
mov al, "x"
mov edi, offset MyFatArray
int 3
rep stosb
MsgBox 0, "Buffer filled!", "Hi", MB_OK
exit
end start
Builds in 400 milliseconds with MASM 6.14 (and in 200 milliseconds with UAsm) :cool:
Quote from: jj2007 on June 11, 2025, 06:55:03 PMQuote from: daydreamer on June 11, 2025, 05:56:50 PMEspecially ml 6.14 bug that makes it take an eternity when using creating big arrays
Yeah, that bug is a nuisance, but there is a workaround:
include \masm32\include\masm32rt.inc
.data?
Buffersize=16777216 ; 16 MB
MyFatArray LABEL byte
ORG $+Buffersize-1
db ?
EndofArray db ?
.code
start:
mov EndofArray, "e"
mov ecx, Buffersize
mov al, "x"
mov edi, offset MyFatArray
int 3
rep stosb
MsgBox 0, "Buffer filled!", "Hi", MB_OK
exit
end start
Builds in 400 milliseconds with MASM 6.14 (and in 200 milliseconds with UAsm) :cool:
Cool :thumbsup:
But I always thought using uasm on fastest ssd,vs one of my old 4x rewritable DVD mostly the milliseconds output is depending on drive speed?
Drive speed is irrelevant thanks to the file cache.
Quote from: jj2007 on June 11, 2025, 10:23:50 PMDrive speed is irrelevant thanks to the file cache.
Big assemble project like masmbasic?
Might suspect disk cache speed and size also been also improved over the years,from very old few gb drive to modern several tb drive
Quote from: daydreamer on June 12, 2025, 05:14:17 AMBig assemble project like masmbasic?
37 obj files with a total of 133kBytes, less than five seconds with UAsm. Now time what it needs to write 133kB to disk...
421 ms for 100*2948888 bytes