NASM - The Netwide Assembler
NASM Forum => Using NASM => Topic started by: luigi on February 13, 2014, 07:10:45 PM
-
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
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.
-
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.
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.
-
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.
-
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.
-
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
-
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?
-
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:
section .text
%if azz
;some code
%endif
section .data
azz dw 12 ;or db,dd,dq even i try 012b,012h,0x12,'12'
%if azz
; some code
%endif
Left, Right:
%define azz 12
%if azz
; some code
%endif
%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.
-
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.