Author Topic: Conditionals outside of macros  (Read 15879 times)

mcamember

  • Guest
Conditionals outside of macros
« on: August 23, 2007, 03:39:31 PM »
I have a question about run-time conditional programming,
that is,  outside of  macros.

NASM won't compile the following code. It reports an error
of undefined (internal address) symbol.

if eax ,>, 0
  inc ebx
else
  if eax ,==, 0 ;<----------------
     inc ecx
  endif
endif

NASM seems unwilling to allow an 'if/endif' construction
beneath an 'else' statement.

Is there a statement corresponding to the macro '%elif'
to be used in run-time conditionals ?
(Using just 'elif' doesn't work.)

Or, is it possible somehow to code 'if/endif' beneath an 'else'
Thanks in advance.
Austin

nobody

  • Guest
Re: Conditionals outside of macros
« Reply #1 on: August 24, 2007, 03:28:26 AM »
The only conditionals Nasm knows are the ones the CPU knows - jcc, jncc, loop, etc. If you want to use "if", "else" and all, you'll have to provide a macro. Nasm64developer has written a set, available on the "downloads" page under "contributions"...

We can do conditional assembly:

%if 0
mov eax, 42 ; this won't be assembled
%endif

but not at runtime. You want:

cmp eax, 0
jng skipebx
inc ebx
jmp done ; don't do the "else" clause

skipebx:
test eax, eax ; (shorter than cmp eax, 0)
jnz done
inc ecx

done:
...

... or use macros...

Best,
Frank

mcamember

  • Guest
Re: Conditionals outside of macros
« Reply #2 on: August 24, 2007, 12:21:42 PM »
Thanks again Frank.
For anyone else reading this, the macros written by
Nasm64developer are not listed directly under Contributions
on the top page of the Download section.
You'll need to take the link to "View older releases from the Contributions package >>"