News:

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

Main Menu

Macro for checking previous instructions

Started by jj2007, July 22, 2013, 06:48:49 AM

Previous topic - Next topic

jj2007

I'd like to have a macro that tells me the content of the previous byte in the code section, like this:

include \masm32\include\masm32rt.inc

mytest MACRO
  if [$-1] eq 90   ; error A2094: operand must be relocatable
   echo NOP
  else
   echo not a nop
  endif
ENDM

.code
start:
   db 90   ; nop
   mytest   ; tell me if the previous instruction is a nop
   exit

end start


That should be possible for the assembler, but what I tried just throws errors. Any ideas?

Thanks, jj

qWord

Quote from: jj2007 on July 22, 2013, 06:48:49 AMThat should be possible for the assembler
I'm afraid this is not possible with MASM.
MREAL macros - when you need floating point arithmetic while assembling!

jj2007

That's what I suspected. Bad luck :(
Thanks, qWord.

dedndave

  if [$-1] eq 90   ; error A2094: operand must be relocatable

it's an assembly-time conditional, as i'm sure you know
they have to be resolved on the first pass (i.e., before the value of the byte is known)

you can do it with a run-time conditional, but that's probably not what you want

jj2007

Quote from: dedndave on July 22, 2013, 08:12:08 AMthey have to be resolved on the first pass (i.e., before the value of the byte is known)

Right. Would be difficult indeed...

japheth

Quote from: qWord on July 22, 2013, 07:55:51 AM
I'm afraid this is not possible with MASM.

True. However, FASM can do it - it has LOAD and STORE directives. STORE is needed because FASM's ORG directive works fairly differently than MASM's.

GoneFishing

Hi Jochen!
I didn't try to write such a macro but next lines worked for me ( I checked it in Olly)

.code
start:
   db 90   ; nop
   mov eax,$-1
   fn MessageBox,0,uhex$([eax]),"AL=90?",MB_OK
   exit

end start



sinsi


GoneFishing

ATTENTION! : Execute it in debugger
I used Olly. All worked well.


mytest MACRO
       mov eax,$-1
       mov eax,[eax]
       EXITM <eax>
ENDM

    .code

start:

db 0cch  ; hardcoded BreakPoint
db 90h   ; not NOP ;)
fn MessageBox,0,uhex$(mytest()),"AL=90?",MB_OK
exit


sinsi:
        did you mean that opcode 90h performs some operation inside the register ?

jj2007

Quote from: vertograd on July 23, 2013, 12:21:45 AM
sinsi:
        did you mean that opcode 90h performs some operation inside the register ?

No, he's just teasing me. I had used 90d, it should be 90h :P

In the meantime, I've solved the problem with runtime instructions; see last attachment, search inside the *.asm file for 22.7.13

Thanks to everybody :icon14: