News:

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

Main Menu

Assume with different structures?

Started by LordAdef, March 16, 2025, 02:08:06 PM

Previous topic - Next topic

LordAdef

Hi everyone,

I am trying to compress some code.
I've got a single procedure that I need to invoke from different places, and I need to "assume edi: ptr *different structures", depending from where it's called.

I tried using "equ" but...it doens't work:

before calling:
current_structure equ ptr struct_foo

and in the proc:
assume edi: current_structure

I am using a very poor workaround, but it's very unreliable, I think.

Any ideas?
Alex

NoCforMe

MASM?
So far as I know, ASSUME was only used to control segment register usage in 16-bit code. I've never heard of it being used in the way you propose.

What are you trying to do here? Why not just use EDI with the name of the structure as a pointer?
SOMETHING STRUC
   a DD ?
   b DD ?
   c DD ?
SOMETHING ENDS

; set EDI to point to a structure element,
; then address it thus:
MOV EAX, [EDI].SOMETHING.a
MOV ECX, [EDI].SOMETHING.b
MOV EDX, [EDI].SOMETHING.c
Assembly language programming should be fun. That's why I do it.

sinsi

Or, alternatively
SOMETHING STRUC
   a1 DD ?
   b2 DD ?
   c3 DD ?
SOMETHING ENDS

ASSUME EDI:PTR SOMETHING
MOV EAX, [EDI].a1
MOV ECX, [EDI].b2
MOV EDX, [EDI].c3
        ...
ASSUME EDI:NOTHING

NoCforMe

So all this is to avoid typing 10 characters per statement.
OK.
Assembly language programming should be fun. That's why I do it.

sinsi

Quote from: NoCforMe on March 16, 2025, 02:25:03 PMSo all this is to avoid typing 10 characters per statement.
OK.
It's a PITA to fill a WNDCLASSEX structure - an extra 120 characters. Better things to do :biggrin:

zedd151

Looks cleaner and less messy as well.  :thumbsup:
If it was nested structures though, the other way would prolly be better?
¯\_(ツ)_/¯   :azn:

'As we don't do "requests", show us your code first.'  -  hutch—

sinsi

Sometimes the explicit way is better, you are in no doubt.
  mov eax,[edi].nCount  ;a bit ambiguous
  mov eax,[edi].MYSTRUCT.nCount  ;obvious

A bit hypocritical, but I use the long version by habit - no ASSUME in ML64 :sad:

NoCforMe

Quote from: sinsi on March 16, 2025, 02:27:58 PM
Quote from: NoCforMe on March 16, 2025, 02:25:03 PMSo all this is to avoid typing 10 characters per statement.
OK.
It's a PITA to fill a WNDCLASSEX structure - an extra 120 characters. Better things to do :biggrin:
Ever hear of copy & paste?
Assembly language programming should be fun. That's why I do it.

sinsi

Quote from: NoCforMe on March 16, 2025, 03:13:47 PMEver hear of copy & paste?
:rolleyes: Ever heard of intellisense? Or auto-complete?

Maybe we should wait for Alex to reply, I'm not sure I understood his question.
Let's try and avoid polluting the topic eh?

_japheth

Quote from: LordAdef on March 16, 2025, 02:08:06 PMbefore calling:
current_structure equ ptr struct_foo

and in the proc:
assume edi: current_structure

That's not possible with ASSUME. ASSUME is an assembly-time thing, and the assembler, when assembling your PROC, simply doesn't know in what context your PROC is called. You'd have to differentiate the cases inside the procedure and then use multiple ASSUMES inside it - definitely not a good "solution".
Dummheit, gepaart mit Dreistigkeit - eine furchtbare Macht.

daydreamer

Quote from: sinsi on March 16, 2025, 02:31:46 PMSometimes the explicit way is better, you are in no doubt.
  mov eax,[edi].nCount  ;a bit ambiguous
  mov eax,[edi].MYSTRUCT.nCount  ;obvious

A bit hypocritical, but I use the long version by habit - no ASSUME in ML64 :sad:
Alternative Solution with create a macro and use it multiple times in source saves typing ?
David using macros as production tool predates windows 3.11 copy and paste
Or  built up library of .inc files

my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

jj2007

Hi Alex,
What do you mean with "equ doesn't work"?

LOCAL rc1:RECT, rc2:RECT
...
push esi
push edi
lea esi, rc1
lea edi, rc2
invoke GetWindowRect, hMain, esi ; addr rcw
invoke GetClientRect, hMain, edi ; addr rcc
rcw equ [esi.RECT]
rcc equ [edi.RECT]
print chr$(13, 10)
print str$(rcw.left), 9, "WinRect left", 13, 10
print str$(rcw.top), 9, "WinRect top", 13, 10
print str$(rcw.right), 9, "WinRect right", 13, 10
print str$(rcw.bottom), 9, "WinRect bottom", 13, 10
print str$(rcc.left), 9, "ClientRect left", 13, 10
print str$(rcc.top), 9, "ClientRect top", 13, 10
print str$(rcc.right), 9, "ClientRect right", 13, 10
print str$(rcc.bottom), 9, "ClientRect bottom", 13, 10
pop edi
pop esi

ognil

QuoteAlternative Solution with create a macro and use it multiple times in source saves typing ?
:sad:
In pure MASM64 I use:
It_is_WM_NOTIFY:
                        mov     rax, r9                               ; lParam                   
                        mov     rcx, hEdit
                        cmp     (NMHDR ptr [rax])._code, EN_SELCHANGE ; nphdr->code = EN_SELCHANGE = 702h   
                        jnz     @Ret                                               
                        cmp     (NMHDR ptr [rax]).hwndFrom, rcx       ; nphdr->hwndFrom = hEdit           
                        jnz     @Ret 
"Not keeping emotions under control is another type of mental distortion."

jj2007

                        mov     rax, r9                               ; lParam                   
                        mov     rcx, hEdit
                        cmp     (NMHDR ptr [rax])._code, EN_SELCHANGE

Any good reason not to use NMHDR ptr [r9]?

ognil

QuoteAny good reason not to use NMHDR ptr [r9]?
WndProc           proc
                        cmp     rdx, WM_NOTIFY
                        je      It_is_WM_NOTIFY
I prefer to use registers RCX, RDX, R8 and R9 whenever possible instead of variables and so I need to duplicate R9 in RAX for its use with modification in subsequent code.
I am deeply sorry that using RAX instead of R9 has caused you so much trouble. :badgrin:
"Not keeping emotions under control is another type of mental distortion."