News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

About PUSHCONTEXT and POPCONTEXT directives

Started by SixOfOnes, June 16, 2014, 07:38:07 AM

Previous topic - Next topic

SixOfOnes

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.

qWord

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)
MREAL macros - when you need floating point arithmetic while assembling!

Gunther

I'm not sure if that's really necessary.

Gunther
You have to know the facts before you can distort them.

qWord

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.
MREAL macros - when you need floating point arithmetic while assembling!

Gunther

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
You have to know the facts before you can distort them.

hutch--

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

jj2007

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

Gunther

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
You have to know the facts before you can distort them.