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
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
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
So all this is to avoid typing 10 characters per statement.
OK.
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:
Looks cleaner and less messy as well. :thumbsup:
If it was nested structures though, the other way would prolly be better?
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:
Quote from: sinsi on March 16, 2025, 02:27:58 PMQuote 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?
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?
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".
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
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
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
mov rax, r9 ; lParam
mov rcx, hEdit
cmp (NMHDR ptr [rax])._code, EN_SELCHANGE
Any good reason not to use NMHDR ptr [r9]?
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:
Thanks guys for helping me out.
QuoteWhat do you mean with "equ doesn't work"?
Hi JJ,
I was trying to change the equ according to the structure, and use it in the ASSUME. Example below
QuoteAlternative Solution with create a macro and use it multiple times in source saves typing ?
QuoteAlternative Solution with create a macro and use it multiple times in source saves typing ?
Hey Daydreamer! Hi Ognil,
Yes, and I was in fact using macros for that. The point in these cases is, I want to control the size of the project.
QuoteThat'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".
Hey Japheth! Yep, it's a shame... I was really hoping for a magic tool from you gurus! But, you made it clear why my equ would never work
QuoteA bit hypocritical, but I use the long version by habit - no ASSUME in ML64
Hi Sinsi, I am still on 32bits... and didn't know that. Porting will be an extra hassle
QuoteI've never heard of it being used in the way you propose.
Hi NotCforMe, well, you can point to a structure, if that is what you mean
To clarify, a pseudo code:
caller_1 proc
assume esi: ptr structure_1
...
current_structure equ structure_1 <--
invoke target_proc
ret
caller_1 endp
caller_2 proc
assume esi: ptr structure_2
...
current_structure equ structure_2 <--
invoke target_proc
ret
caller_2 endp
target_proc proc
assume esi: current_structure <--- As Japheth has already explained, my idea doesn't work
....
ret
target_proc endp