# How To Work With Variables In FASM

GentleMen,
I am a Absolute Begginer To Assembly
And My Question Is.
How do we declare Variables In FASM
[code]
Var1 dw 10h ; If this is how it is declared than

Mov AX , Var1 ; What is wrong with this Statement
Mov Var1, AX ; And This

Now In Emulater It is Written That Var1 Should Be
Written As [Var1] To Make It Work in FASM
But I Am ConFussed :-
Var1 Is a Variable And Is A Name Given TO A Memory
Location SO that Memory Location Is It`s Address Too
Or Not?
Like in C
int Var1 = 1;
int Var2 ;
int *Var3 ;

Var2 = Var1 ; WOuld Mean 1 Is Copied In Var2
Not The address Of Var1
Var3 = &Var1 ; Would Mean Putting The Address Of
Var1 In Var3;
Where as
Var2 = *&Var1; Would Again Put 1 In Var2 Because It Can Be Read
; As Value Inside The Address Of Var1
; So In C I know how to get Address Of a Variable
; And The Value In It .

But How Do You Do That In Fasm
Mov AX, Var1 ;Should Mean Var1`s Address Or The Value Var1 Is Holding
and
Mov Ax,[Var1];Should Mean The Value Inside The Address Of Var1
; Or
;Should It Mean The Value Var1 Is Holding Consider
;It To Be An Address And What Is Inside That Address
;Copy It TO AX

[/code]

Many Thanks

• [b][red]This message was edited by IDK at 2005-11-2 11:20:8[/red][/b][hr]
There isn't such a thing as variables in asm.
var1 is the address defined somewhere and
[var1] is the data stored at that address.

this program will compile:
[code]
org 100h ;this tells the compiler where the addresses will start at...
mov [var1],1 ;var1 now contains 1
mov ax,var1 ;ax now contains the address of var1
mov ax,[var1] ;ax now contains the data located at var1 = 1
inc ax ;ax++
mov [var1],ax ;var1 now holds 2

mov ax, 4C00h ;terminate program
int 21h

var1: db 0 ;declare a byte, that is at positioned at var1
;and contains 0

[/code][code]
Mov Ax,[Var1];Should Mean The Value Inside The Address Of Var1
; Or
;Should It Mean The Value Var1 Is Holding Consider
;It To Be An Address And What Is Inside That Address
;Copy It TO AX

Those two things above is the same...
[/code]

[grey]The one and only [b]Niklas Ulvinge[/b][/grey] [white]aka [b]IDK[/b][/white]

• [b][red]This message was edited by shaolin007 at 2005-11-3 7:42:57[/red][/b][hr]
[red]
There isn't such a thing as variables in asm.
[/red]

[green]
You could say that about any language really but to be true to form you could define a variable in FASM like so in a uninitialized area.

[code]
------------------------------------------------------------
section '.bss' readable writeable

X dd ?; X is of size double word no value assigned yet
------------------------------------------------------------
C Code:

long x;

[/code]

[code]
--------------------------------------------------------------------
section '.data' readable writeable

X dd FF00FF00h ;X is given a value but this could also be
changed so this could be construed as a variable
too because the value could change if written
to the address of X.
--------------------------------------------------------------------
C Code:

long x=0xFF00FF00;
----------------------------------------------------------------
X dd FF00FF00h ;X is a constant here and can't be changed.
----------------------------------------------------------------
C Code:

const long x=0xFF00FF00;

[/code]
[/green]

• : [b][red]This message was edited by shaolin007 at 2005-11-3 7:42:57[/red][/b][hr]
: [red]
: There isn't such a thing as variables in asm.
: [/red]
:
: [green]
: You could say that about any language really but to be true to form you could define a variable in FASM like so in a uninitialized area.
:
: [code]
: ------------------------------------------------------------
: section '.bss' readable writeable
:
: X dd ?; X is of size double word no value assigned yet
: ------------------------------------------------------------
: C Code:
:
: long x;
:
: [/code]
:
: [code]
: --------------------------------------------------------------------
: section '.data' readable writeable
:
: X dd FF00FF00h ;X is given a value but this could also be
: changed so this could be construed as a variable
: too because the value could change if written
: to the address of X.
: --------------------------------------------------------------------
: C Code:
:
: long x=0xFF00FF00;
: ----------------------------------------------------------------
: section '.data' readable
: X dd FF00FF00h ;X is a constant here and can't be changed.
: ----------------------------------------------------------------
: C Code:
:
: const long x=0xFF00FF00;
:
: [/code]
: [/green]
:
:
Youre right, but I think of data as memmory in asm and as variables or arrays of variable in higher languages... That's why I can't program good pointers...

.Net won't allow pointers exept if you tell the compiler to, by marking the code as unsafe

[grey]The one and only [b]Niklas Ulvinge[/b][/grey] [white]aka [b]IDK[/b][/white]

• : Youre right, but I think of data as memmory in asm and as variables or arrays of variable in higher languages... That's why I can't program good pointers...

[green]
Why, you do it all the time in assembly. I have seen your code and you seem to do that alright to me. Pointers are unavoidable in assembly. One way or another your going to use at least one. If you ask me, they are easier in assembly since you can see the guts of it working.
[/green]

• : : Youre right, but I think of data as memmory in asm and as variables or arrays of variable in higher languages... That's why I can't program good pointers...
:
:
: [green]
: Why, you do it all the time in assembly. I have seen your code and you seem to do that alright to me. Pointers are unavoidable in assembly. One way or another your going to use at least one. If you ask me, they are easier in assembly since you can see the guts of it working.
: [/green]
:
:
:
I haven't done anything in any language since I started with assembly, except some C#, wich doesn't allow pointers

Now I see why all programmers need to program in assembly at least once in their lifetime. After I got my current project finnished and got something to program I start doing it in C...

[grey]The one and only [b]Niklas Ulvinge[/b][/grey] [white]aka [b]IDK[/b][/white]

• : : : Youre right, but I think of data as memmory in asm and as variables or arrays of variable in higher languages... That's why I can't program good pointers...
: :
: :
: : [green]
: : Why, you do it all the time in assembly. I have seen your code and you seem to do that alright to me. Pointers are unavoidable in assembly. One way or another your going to use at least one. If you ask me, they are easier in assembly since you can see the guts of it working.
: : [/green]
: :
: :
: :
: I haven't done anything in any language since I started with assembly, except some C#, wich doesn't allow pointers
:
: Now I see why all programmers need to program in assembly at least once in their lifetime. After I got my current project finnished and got something to program I start doing it in C...
:
: [grey]The one and only [b]Niklas Ulvinge[/b][/grey] [white]aka [b]IDK[/b][/white]
:
:
[green]
I haven't touched C much in 3 years or so but going back and doing it is leaps and bounds better compared to when I didn't know any assembly. Now when I program in C, I know how the stack is being utilized and how everything or mostly everything is organized in memory. Right now I can't do much of either since I'm going to school for electrical engineering, real busy! :-(
[/green]

• : [green]
: I haven't touched C much in 3 years or so but going back and doing it is leaps and bounds better compared to when I didn't know any assembly. Now when I program in C, I know how the stack is being utilized and how everything or mostly everything is organized in memory. Right now I can't do much of either since I'm going to school for electrical engineering, real busy! :-(
: [/green]
:
:
I also got some school, but now it's a holiday here in sweden, so I got a lot of time to program :-)

[grey]The one and only [b]Niklas Ulvinge[/b][/grey] [white]aka [b]IDK[/b][/white]

• Sir Mr.IDK And Sir Mr.Shaolin

Thankyou For Your TIme
While YOu Sir GO tO School
All I do Is Shift Positions On My bed.
Any time It Begans To ache In One Position.
But Then !!!!....

Soon I will Be Bothering YOu
with Many More Questions About Assembly
I hope It DOes NOt Ache You anywhere.Specially the head!!!
Thankyou once again.
Now i know at least how to start In Assembly
• : Sir Mr.IDK And Sir Mr.Shaolin
:
: Thankyou For Your TIme
: While YOu Sir GO tO School
: All I do Is Shift Positions On My bed.
: Any time It Begans To ache In One Position.
: But Then !!!!....
:
: Soon I will Be Bothering YOu
: with Many More Questions About Assembly
: I hope It DOes NOt Ache You anywhere.Specially the head!!!
: Thankyou once again.
: Now i know at least how to start In Assembly
:
[green]
[/green]

• : : Sir Mr.IDK And Sir Mr.Shaolin
: :
: : Thankyou For Your TIme
: : While YOu Sir GO tO School
: : All I do Is Shift Positions On My bed.
: : Any time It Begans To ache In One Position.
: : But Then !!!!....
: :
: : Soon I will Be Bothering YOu
: : with Many More Questions About Assembly
: : I hope It DOes NOt Ache You anywhere.Specially the head!!!
: : Thankyou once again.
: : Now i know at least how to start In Assembly
: :
: [green]
: Glad to help.
: [/green]
:
:
:
Me to

[grey]The one and only [b]Niklas Ulvinge[/b][/grey] [white]aka [b]IDK[/b][/white]