The MASM Forum

General => The Workshop => Topic started by: Rockphorr on June 09, 2024, 04:51:25 AM

Title: Echo value of offset
Post by: Rockphorr on June 09, 2024, 04:51:25 AM
How to do it ?

See the code and results in attachment.

Regards, Rockphorr.
Title: Re: Echo value of offset
Post by: NoCforMe on June 09, 2024, 04:56:33 AM
I believe you may have invoked the Macro Master's name.
JJ should be along shortly.
Title: Re: Echo value of offset
Post by: HSE on June 09, 2024, 05:50:51 AM
There is no variable declaration, then offset will not work (like error say).

For example:
.data
      Mysome Some {0,0,0,0}
Title: Re: Echo value of offset
Post by: Rockphorr on June 09, 2024, 06:15:17 AM
Quote from: HSE on June 09, 2024, 05:50:51 AMThere is no variable declaration, then offset will not work (like error say).

For example:
.data
      Mysome Some {0,0,0,0}


Post complete working code please. May be it is impossible to write code doing this.
Title: Re: Echo value of offset
Post by: jj2007 on June 09, 2024, 06:18:49 AM
What's the problem? It seems to work:
*** Assemble, link and run VALUE_ASM ***

*** Assemble using UAsm64  ***
@V_size    =    8h
@V_ofs    =    4h
Tmp_File.asm(31) : Error A2099: END directive required at end of file

Quote from: Rockphorr on June 09, 2024, 06:15:17 AMPost complete working code please.

Normally, I agree. But here OP just wants the echos - and they work.

The CodeSize macro (https://www.jj2007.eu/MasmBasicQuickReference.htm#Mb1221) works in a similar fashion.
Title: Re: Echo value of offset
Post by: HSE on June 09, 2024, 06:20:14 AM
Quote from: Rockphorr on June 09, 2024, 06:15:17 AMPost complete working code please. May be it is impossible to write code doing this.

:biggrin: Just paste that 2 lines before .code
Title: Re: Echo value of offset
Post by: Rockphorr on June 09, 2024, 07:21:14 AM
;=======[ STRUCTURE ]===============
Some\
STRUC
Some_Data_0\
BYTE ?
Some_Data_1\
BYTE ?
Some_Data_2\
WORD ?
Some_Method\
DWORD ?
Some\
ENDS


;======[ MACRO ]====================
@Value MACRO name:req, expression:req
 .RADIX 10h
 %ECHO @CatStr (<name>,< = >,%expression,<h>)
 .RADIX 0Ah
  ENDM

.386
.MODEL FLAT


.DATA
      Mysome Some {0,0,0,0}


.CODE


@Value @V_size,Size(Some)

@Value @V_ofs,OFFSET( (Some PTR[0]).Some_Method )



results:

Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.
 Assembling: value.asm
@V_size =       8h
value.asm(37) : error A2027: operand must be a memory expression
 @CatStr(1): Macro Called From
  @Value(2): Macro Called From
   value.asm(37): Main Line Code
@V_ofs  =       0h
value.asm(37) : error A2088: END directive required at end of file
Title: Re: Echo value of offset
Post by: Rockphorr on June 09, 2024, 07:36:56 AM
Quote from: jj2007 on June 09, 2024, 06:18:49 AM*** Assemble, link and run VALUE_ASM ***

*** Assemble using UAsm64  ***

Quote from: Rockphorr on June 09, 2024, 06:15:17 AMPost complete working code please.

Normally, I agree. But here OP just wants the echos - and they work.

The CodeSize macro (https://www.jj2007.eu/MasmBasicQuickReference.htm#Mb1221) works in a similar fashion.

I use ml of masm32 from masm32.com instead your UAsm64
Title: Re: Echo value of offset
Post by: HSE on June 09, 2024, 07:43:26 AM
 :biggrin: it's a lot more simple that your idea:
;=======[ STRUCTURE ]===============
Some\
STRUC
Some_Data_0\
BYTE ?
Some_Data_1\
BYTE ?
Some_Data_2\
WORD ?
Some_Method\
DWORD ?
Some\
ENDS


;======[ MACRO ]====================
@Value MACRO name:req, expression:req
 .RADIX 10h
 %ECHO @CatStr (<name>,< = >,%expression,<h>)
 .RADIX 0Ah
  ENDM

.386
.MODEL FLAT

.code

@Value @V_size,Size(Some)
@Value @V_ofs,Some.Some_Method

end
Title: Re: Echo value of offset
Post by: Rockphorr on June 09, 2024, 07:49:09 AM
Quote from: HSE on June 09, 2024, 07:43:26 AM:biggrin: it's a lot more simple that your idea:
;=======[ STRUCTURE ]===============
Some\
STRUC
Some_Data_0\
BYTE ?
Some_Data_1\
BYTE ?
Some_Data_2\
WORD ?
Some_Method\
DWORD ?
Some\
ENDS


;======[ MACRO ]====================
@Value MACRO name:req, expression:req
 .RADIX 10h
 %ECHO @CatStr (<name>,< = >,%expression,<h>)
 .RADIX 0Ah
  ENDM

.386
.MODEL FLAT

.code

@Value @V_size,Size(Some)
@Value @V_ofs,Some.Some_Method

end

ups, it was my fault,
Your code works fine!
Thanx!!!
Title: Re: Echo value of offset
Post by: NoCforMe on June 09, 2024, 07:59:15 AM
Strange; I got it to assemble OK (but not link):
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

 Assembling: value.asm
@V_size =       8h
@V_ofs  =       4h
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

LINK : error LNK2001: unresolved external symbol _WinMainCRTStartup
value.exe : fatal error LNK1120: 1 unresolved externals
Title: Re: Echo value of offset
Post by: jj2007 on June 09, 2024, 08:37:28 AM
Quote from: Rockphorr on June 09, 2024, 07:36:56 AMI use ml of masm32 from masm32.com instead your UAsm64

UAsm is a Masm32 clone, 100% compatible. And at least a factor 3 faster.
Title: Re: Echo value of offset
Post by: Rockphorr on June 09, 2024, 08:50:05 AM
Quote from: NoCforMe on June 09, 2024, 07:59:15 AMStrange; I got it to assemble OK (but not link):
Microsoft (R) Macro Assembler Version 6.14.8444
Copyright (C) Microsoft Corp 1981-1997.  All rights reserved.

 Assembling: value.asm
@V_size =       8h
@V_ofs  =       4h
Microsoft (R) Incremental Linker Version 5.12.8078
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

LINK : error LNK2001: unresolved external symbol _WinMainCRTStartup
value.exe : fatal error LNK1120: 1 unresolved externals


Couse this obj has no code inside. Link did not find any label of code.
Title: Re: Echo value of offset
Post by: NoCforMe on June 09, 2024, 09:05:35 AM
Yes, exactly.
I didn't mean to bring this up to further muddy the waters.
So did you get everything to work OK?
Title: Re: Echo value of offset
Post by: zedd on June 09, 2024, 10:29:57 AM
Quote from: NoCforMe on June 09, 2024, 09:05:35 AMSo did you get everything to work OK?
Maybe I am a little slow, but I don't understand what this piece of code is actually supposed to do...  :undecided:
As is, it seems not very useful as a program since the object file has no code. Am I missing some key point to this?

Maybe it would be more useful to show an example of how/where it would be used.
Title: Re: Echo value of offset
Post by: NoCforMe on June 09, 2024, 10:49:28 AM
He's trying show offsets into a structure for its members (hence the echo). That's all.
Title: Re: Echo value of offset
Post by: zedd on June 09, 2024, 11:04:36 AM
Quote from: NoCforMe on June 09, 2024, 10:49:28 AMHe's trying show offsets into a structure for its members (hence the echo). That's all.
It just seemed weird to me. So, I had to ask.
Title: Re: Echo value of offset
Post by: NoCforMe on June 09, 2024, 11:53:24 AM
Well, it might have been kinda a dumb question.
But the say the really dumb question is the one you don't ask.
Title: Re: Echo value of offset
Post by: Rockphorr on June 09, 2024, 03:44:13 PM
Quote from: NoCforMe on June 09, 2024, 09:05:35 AMYes, exactly.
I didn't mean to bring this up to further muddy the waters.
So did you get everything to work OK?



Quote from: sudoku on June 09, 2024, 10:29:57 AM
Quote from: NoCforMe on June 09, 2024, 09:05:35 AMSo did you get everything to work OK?
Maybe I am a little slow, but I don't understand what this piece of code is actually supposed to do...  :undecided:
As is, it seems not very useful as a program since the object file has no code. Am I missing some key point to this?

Maybe it would be more useful to show an example of how/where it would be used.


All your questions are fine. I think that most of masm directive should generate more information.
For example, proc should generate proto to output inc_file.
I make this macro to avoid sharing  full structure in module, instead i use this macro to create const definition.

value.asm
;=======[ STRUCTURE ]===============
Some\
STRUC
...
Some_Method\
DWORD ?
Some\
ENDS


;======[ MACRO ]====================
@Value MACRO name:req, expression:req
 .RADIX 10h
 %ECHO @CatStr (<name>,< = >,%expression,<h>)
 .RADIX 0Ah
  ENDM

.386
.MODEL FLAT

.code


@Value @V_ofs,Some.Some_Method

end


ml value.asm >log.txt

Copy from log.txt to some.inc following line and use it in another module.

some.inc

@V_ofs = 4h


Title: Re: Echo value of offset
Post by: NoCforMe on June 10, 2024, 04:18:26 AM
Not every assembly-language program need generate any code at all.

Here's a tool I wrote to tell me which constants were not defined in our own windows.inc:
;====================================================
;NotInWindowsInc.asm
;
; Tool to go through a list of symbolic constants and output
; those which are NOT defined in MASM32's windows.inc.
;====================================================
.nolist
include \masm32\include\masm32rt.inc
.list

$ce macro arg1, arg2
ifndef &arg1
% echo &arg1 EQU &arg2
endif
endm

echo Constants NOT defined in MASM32 include files:

$ce IMAGE_FILE_MACHINE_UNKNOWN, 0
$ce IMAGE_FILE_MACHINE_AM33, 1d3H
$ce IMAGE_FILE_MACHINE_AMD64, 8664H
$ce IMAGE_FILE_MACHINE_ARM, 1c0H
$ce IMAGE_FILE_MACHINE_ARMNT, 1c4H
$ce IMAGE_FILE_MACHINE_EBC, 0ebcH
$ce IMAGE_FILE_MACHINE_I386, 14cH

; . . . many more entries here . . .

END

which simply echoes all those undefined constants so I can put them in a file, NotInWindowsInc.inc.
Title: Re: Echo value of offset
Post by: zedd on June 10, 2024, 04:27:09 AM
Thanks for the clarification for the 'uninitiated'.
My idea of echo was only

"value of offset  value of offset  value of offset  value of offset  value of offset"
aside from using 'echo' on the command line.  :smiley:
So basically its a macro 'thing'?
Would have been more apparent (what it does), if used in an example for 'macro noobz' like me.  :tongue:
Title: Re: Echo value of offset
Post by: NoCforMe on June 10, 2024, 04:44:03 AM
Quote from: sudoku on June 10, 2024, 04:27:09 AMMy idea of echo was only
"value of offset  value of offset  value of offset  value of offset  value of offset"
Bada-BOOMP! (bada-boomp)  [bada-boomp) ...
Title: Re: Echo value of offset
Post by: Rockphorr on June 11, 2024, 03:09:01 AM
Quote from: HSE on June 09, 2024, 07:43:26 AM:biggrin: it's a lot more simple that your idea:
;=======[ STRUCTURE ]===============
Some\
STRUC
Some_Data_0\
BYTE ?
Some_Data_1\
BYTE ?
Some_Data_2\
WORD ?
Some_Method\
DWORD ?
Some\
ENDS


;======[ MACRO ]====================
@Value MACRO name:req, expression:req
 .RADIX 10h
 %ECHO @CatStr (<name>,< = >,%expression,<h>)
 .RADIX 0Ah
  ENDM

.386
.MODEL FLAT

.code

@Value @V_size,Size(Some)
@Value @V_ofs,Some.Some_Method

end

Can I ask you what compiller do you use ?
Title: Re: Echo value of offset
Post by: Rockphorr on June 11, 2024, 03:13:36 AM
Quote from: jj2007 on June 09, 2024, 08:37:28 AM
Quote from: Rockphorr on June 09, 2024, 07:36:56 AMI use ml of masm32 from masm32.com instead your UAsm64

UAsm is a Masm32 clone, 100% compatible. And at least a factor 3 faster.


Can you post the link to it ?
Title: Re: Echo value of offset
Post by: NoCforMe on June 11, 2024, 03:18:24 AM
Quote from: Rockphorr on June 11, 2024, 03:09:01 AMCan I ask you what compiller do you use ?
Assembler, not compiler. (Does a similar job but let's not confuse ourselves with wrong terms here.)
Title: Re: Echo value of offset
Post by: Rockphorr on June 11, 2024, 03:22:39 AM
Quote from: NoCforMe on June 11, 2024, 03:18:24 AM
Quote from: Rockphorr on June 11, 2024, 03:09:01 AMCan I ask you what compiller do you use ?
Assembler, not compiler. (Does a similar job but let's not confuse ourselves with wrong terms here.)


Ok, let's talk about what assembler.
Title: Re: Echo value of offset
Post by: NoCforMe on June 11, 2024, 03:34:20 AM
So are you having problems with ml?
Title: Re: Echo value of offset
Post by: Rockphorr on June 11, 2024, 03:43:01 AM
Quote from: NoCforMe on June 11, 2024, 03:34:20 AMSo are you having problems with ml?

Problems come when using on bounds... Now my problem is solved. I want to try another assembler and compare.
Title: Re: Echo value of offset
Post by: NoCforMe on June 12, 2024, 06:10:10 AM
Quote from: Rockphorr on June 11, 2024, 03:43:01 AMProblems come when using on bounds...
Bounds? as in array bound checking?
Just curious.
Title: Re: Echo value of offset
Post by: Rockphorr on June 12, 2024, 07:42:19 PM
Quote from: NoCforMe on June 12, 2024, 06:10:10 AM
Quote from: Rockphorr on June 11, 2024, 03:43:01 AMProblems come when using on bounds...
Bounds? as in array bound checking?
Just curious.


As bounds of assembler abilities. A default solution is the immediate value, but i need to get that from the expression of offsets.
Title: Re: Echo value of offset
Post by: TimoVJL on June 12, 2024, 11:32:00 PM
Quote from: Rockphorr on June 12, 2024, 07:42:19 PM
Quote from: NoCforMe on June 12, 2024, 06:10:10 AM
Quote from: Rockphorr on June 11, 2024, 03:43:01 AMProblems come when using on bounds...
Bounds? as in array bound checking?
Just curious.


As bounds of assembler abilities. A default solution is the immediate value, but i need to get that from the expression of offsets.
masm isn't high level language, just with macro language additions.
Title: Re: Echo value of offset
Post by: Rockphorr on July 15, 2024, 12:02:44 AM
Quote from: TimoVJL on June 12, 2024, 11:32:00 PM
Quote from: Rockphorr on June 12, 2024, 07:42:19 PM
Quote from: NoCforMe on June 12, 2024, 06:10:10 AM
Quote from: Rockphorr on June 11, 2024, 03:43:01 AMProblems come when using on bounds...
Bounds? as in array bound checking?
Just curious.


As bounds of assembler abilities. A default solution is the immediate value, but i need to get that from the expression of offsets.
masm isn't high level language, just with macro language additions.


Yes it is. By the assembly we write code as we need, but we also need to solve addresses and expressions automatic.
Title: Re: Echo value of offset
Post by: NoCforMe on July 15, 2024, 04:27:48 AM
Quote from: Rockphorr on July 15, 2024, 12:02:44 AMYes it is [a high-level language]. By the assembly we write code as we need, but we also need to solve addresses and expressions automatic.

It's a mid-level language then: certainly higher than punching in raw opcodes in binary, but nowhere near as high level as, say, C++, where all kinds of calculations (addresses, array indices, structure selectors) are done for you behind the scenes.
Title: Re: Echo value of offset
Post by: Rockphorr on July 15, 2024, 07:22:57 AM
Any way, we enjoy by the lea instruction  :biggrin:  :biggrin:  :biggrin:  :biggrin:
Title: Re: Echo value of offset
Post by: daydreamer on July 15, 2024, 05:07:02 PM
Quote from: NoCforMe on July 15, 2024, 04:27:48 AMIt's a mid-level language then: certainly higher than punching in raw opcodes in binary, but nowhere near as high level as, say, C++, where all kinds of calculations (addresses, array indices, structure selectors) are done for you behind the scenes.
For asm programmers:
More freedom howto code ,but responsible for code adresses right or its buggy code instead of compiler automatically codes byte,word,dword/real4,qword/real8 arrays right
Ofcourse i could use masm way to code struct arrays if i want or take care of itself with manually code it