The MASM Forum

General => The Campus => Topic started by: SixOfOnes on June 16, 2014, 07:38:07 AM

Title: About PUSHCONTEXT and POPCONTEXT directives
Post by: SixOfOnes on June 16, 2014, 07:38:07 AM
I've been loking for some information about the use of these keywords: PUSHCONTEXT and POPCONTEXT. Which is exactly the facilities they bring? Maybe you can share your knowkledge or give some examples. I will appreciate it so much! Thanks in advance.
Title: Re: About PUSHCONTEXT and POPCONTEXT directives
Post by: qWord on June 16, 2014, 10:29:37 AM
These directives are used to save assembler settings like the radix or register assumptions. For more details search for MASM programmers guide or take a look in MASM32.chm that comes with the MASM32 SDK.
foo struct
xy DWORD ?
foo ends
pushcontext assumes
;...
assume edx: ptr foo
mov [edx].xy,0
;...
popcontext assumes

.radix 10
foo2 = 123
pushcontext radix
.radix 16
%echo foo2=@CatStr(%foo2)h
popcontext radix
%echo foo2=@CatStr(%foo2)
Title: Re: About PUSHCONTEXT and POPCONTEXT directives
Post by: Gunther on June 16, 2014, 09:35:12 PM
I'm not sure if that's really necessary.

Gunther
Title: Re: About PUSHCONTEXT and POPCONTEXT directives
Post by: qWord on June 16, 2014, 10:28:13 PM
Quote from: Gunther on June 16, 2014, 09:35:12 PM
I'm not sure if that's really necessary.
It is definitely necessary in context to macros. Also it allows a more relaxed usage of the ASSUME directive.
Title: Re: About PUSHCONTEXT and POPCONTEXT directives
Post by: Gunther on June 17, 2014, 02:03:15 AM
Hi qWord,

Quote from: qWord on June 16, 2014, 10:28:13 PM
It is definitely necessary in context to macros. Also it allows a more relaxed usage of the ASSUME directive.
No offense. But macros are the main area of ​​application, I think. I haven't seen it in other circumstances.

Gunther
Title: Re: About PUSHCONTEXT and POPCONTEXT directives
Post by: hutch-- on June 17, 2014, 09:36:09 AM
ASSUME is sometimes useful with structures.


    ASSUME eax:PTR RECT
    mov eax, lpRct
    mov [eax].left,   10
    mov [eax].top,    12
    mov [eax].right,  14
    mov [eax].bottom, 16
    ASSUME eax:nothing
Title: Re: About PUSHCONTEXT and POPCONTEXT directives
Post by: jj2007 on June 17, 2014, 10:10:18 AM
The point here is that a macro inserts code somewhere. If the coder uses ASSUME before the macro, and the macro uses ASSUME, too, then we have a conflict - the macro's ASSUME overrides, hidden to the coder, the original ASSUME.

This is where PUSHCONTEXT and POPCONTEXT can be used. But a better technique (IMHO) is using local equates:

include \masm32\include\masm32rt.inc

PrintRect MACRO pRect
LOCAL MyRect
  MyRect equ [ebx.RECT]
  echo mr = MyRect   ; echoes mr = ??0019, i.e. a unique name
  push ebx
  mov ebx, offset TheRect
  print str$(MyRect.left), " "
  print str$(MyRect.top), " "
  print str$(MyRect.right), " "
  print str$(MyRect.bottom),13, 10
  pop ebx
ENDM

.code
TheRect   RECT <12, 34, 56, 78>
start:
  PrintRect offset TheRect
  inkey "ok"
  exit
end start
Title: Re: About PUSHCONTEXT and POPCONTEXT directives
Post by: Gunther on June 17, 2014, 07:08:47 PM
Jochen,

Quote from: jj2007 on June 17, 2014, 10:10:18 AM
This is where PUSHCONTEXT and POPCONTEXT can be used. But a better technique (IMHO) is using local equates:

I agree with you, but ultimately it's a matter of taste.

Gunther