Author Topic: [SOLVED]using %if conditional: error: symbol not defined before use  (Read 9788 times)

Offline luigi

  • Jr. Member
  • *
  • Posts: 4
hi all.I am a newbie about assembly as trying to learn nasm.
i follow some tutorials throught.also reads nasm manual.i have a few questions.
im on gen 3 corei5 on linux.(latest nasm,kernel and tools)    Also i hate 32bit.(issue on 64)

1-)why this code get this: error: symbol `azz' not defined before use
Code: [Select]
global main
section .text
main:
;some code
%if azz
;some code
%endif

section .data
azz dw 12                     ;or db,dd,dq even i try 012b,012h,0x12,'12'
which type data/value is acceptable for %if conditional. e.g memory-stack data/value  , registers,  immediates etc.

2-)which input method is the best(easy,practice,fastest)  for arithmetic calculations of numerical.(e.g bcd,ascii,hex,binary)
    a-)for keyboard input
    b-)for hardcoded numbers

thank you for help.sory for english.
« Last Edit: February 14, 2014, 12:21:07 PM by luigi »

Offline encryptor256

  • Full Member
  • **
  • Posts: 250
  • Country: lv
  • Win64 .
    • On Youtube: encryptor256
Re: using %if conditional: error: symbol not defined before use
« Reply #1 on: February 13, 2014, 07:14:51 PM »
Hi!

1-)
%if -> requires constant or expression or something that exists.
Try:
"%ifdef azz"
%ifdef -> stands for "ifdefined", it doesn't means it has to be defined, that's the whole purpose.

2-)
I would go for decimal.

Code: [Select]
         number1: dd 123123
         number2: dw 5543
         number3: db 240

dd - stands for define double word, which is 32 bit.
dw - stands for define word, which is 16 bit.
db - stands for define byte, which is 8 bit.

« Last Edit: February 13, 2014, 07:23:05 PM by encryptor256 »
Encryptor256's Investigation \ Research Department.

Offline luigi

  • Jr. Member
  • *
  • Posts: 4
Re: using %if conditional: error: symbol not defined before use
« Reply #2 on: February 13, 2014, 07:25:00 PM »
No.Nasm manuals says %ifdef for purpose that single line macro definitions checks.

Also %if azz  means  %if azz<>0    Correct me if i am wrong.
« Last Edit: February 13, 2014, 07:28:16 PM by luigi »

Offline encryptor256

  • Full Member
  • **
  • Posts: 250
  • Country: lv
  • Win64 .
    • On Youtube: encryptor256
Re: using %if conditional: error: symbol not defined before use
« Reply #3 on: February 13, 2014, 07:30:00 PM »
Also %if azz  means  %if azz<>0    Correct me if i am wrong.

Correct!

No.Nasm manuals says %ifdef for purpose that single line macro definitions checks.

Yes. %ifdef is a single line macro that check's definitions.
Encryptor256's Investigation \ Research Department.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2600
  • Country: us
Re: using %if conditional: error: symbol not defined before use
« Reply #4 on: February 13, 2014, 09:29:31 PM »
Hi Luigi,

I'm not sure I understand what you're trying to do. If some condition, emit "some code" - otherwise don't emit anything. Is "some condition" supposed to be the existence of the variable "azz", or that the contents of the variable is non-zero?

What would make more sense to me is (at runtime) "if contents of [azz] is non-zero, execute some code (else jump over it)".  I don't get why you'd want to (at assemble time) emit some code or not based on a variable - either existence or value . Can you give us more information about what you want this to do?

Best,
Frank


Offline luigi

  • Jr. Member
  • *
  • Posts: 4
Re: using %if conditional: error: symbol not defined before use
« Reply #5 on: February 14, 2014, 08:01:12 AM »
i want to do nothing.i just try to learn "how to using %if" by to experiments.
i wonder why "azz" undefined.
whats the difference/effect (especially for %if) that a variable exist at assembly time or runtime?

Offline encryptor256

  • Full Member
  • **
  • Posts: 250
  • Country: lv
  • Win64 .
    • On Youtube: encryptor256
Re: using %if conditional: error: symbol not defined before use
« Reply #6 on: February 14, 2014, 08:19:35 AM »
i want to do nothing.i just try to learn "how to using %if" by to experiments.
i wonder why "azz" undefined.
whats the difference/effect (especially for %if) that a variable exist at assembly time or runtime?

Well it seems, the problem is, that, you don't know what is preprocessor directives.

%if, %ifdef, .... those are preprocessor directives.
Assembly time.
Run time.

I think, preprocessor directives are managed even, just before Assembly time.


Wrong:
Code: [Select]
section .text

%if azz
;some code
%endif

section .data
azz dw 12                     ;or db,dd,dq even i try 012b,012h,0x12,'12'
Code: [Select]
%if azz
; some code
%endif

Left, Right:
Code: [Select]
%define azz 12
%if azz
; some code
%endif
Code: [Select]
%ifdef azz
; some code
%endif


LRESULT:
Note0: Before somecodefile.asm is assembled, at first, it is preprocessed and no discussion about runtime at all.
Note1: You can manage your code by preprocessor directives.

Encryptor256's Investigation \ Research Department.

Offline luigi

  • Jr. Member
  • *
  • Posts: 4
Re: using %if conditional: error: symbol not defined before use
« Reply #7 on: February 14, 2014, 12:19:09 PM »
Ok.i didn't know that %if belonging to scope of preprocessing .
i see nasm manuals says  "Preprocessor directives all begin with a % sign."
Proprecessor directives always process before assemly.
i chanced my code that you suggested above.Then it run properly.
i understood the issue.
thank you everyone for your replies.