High-level syntax macro simulation for low-level conditional operations

Started by DoomyD, September 14, 2008, 11:44:16 PM

Previous topic - Next topic

DoomyD

I created a macro library that simulates high-level syntax for direct conditional jumps; and I hope you'll find some good use for it :green
It's purpose is to allow the programmer to implement conditional jumps directly after using an instruction which affects the eflags, without the need to create a label for each case.
The macros included are:
  • fIf      <<flag>>
  • fElse
  • fElseIf   <<flag>
  • fEndIf
  • fRepeat
  • fUntil   <<flag>>
  • fWhile   <<flag>>
  • fEndw
  • fBreak
  • fBreakIf   <<flag>>
Here's an example code that utilizes the library, I hope it clears the point:.data
  samplestr db "hello world",0

.code
  mov  edi,offset samplestr
  mov  ecx,lengthof samplestr-1
  mov  eax,'r'
  repne scasb
  fIf  <<z>>
    xor  eax,eax
    inc eax
  fElse
    xor  eax,eax
  fEndIf

[attachment deleted by admin]

Uzarius Futurus

DoomyD,

Nice work, this macro simplyfies the ASM writing yet more then it already is.
I had a quick look at the code and it seems nice, I will test it as soon as I get home.

drizz

can you give a better example? i mean one that actually does something that built in code can't.
this code works just fine:

.if zero?
    xor  eax,eax
    inc eax
.else
    xor  eax,eax
.enid

or "setz al"
The truth cannot be learned ... it can only be recognized.

DoomyD

For example, the opcodes JA, JBE, JG, JGE, GL, GLE, JNA, JNBE, JNG, JNGE, JNL and JNLE would require you to assemble a complex .if
NG, for instance, requires the following combination:zero? || sign? && !overflow? || !sign? && overflow? which assembles to 5 conditional jump instructions, while the macro will generate a single instruction.