flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
revolution 12 Apr 2018, 11:46
I'm not sure what you mean when you say "variables"?
Variables can be registers (EAX, R12, etc.) or they can be memory addresses. fasm doesn't decide for you what to do with values in registers or values in memory. Your code will dictate what happens. fasm only translates your ASCII text into binary code in a one-to-one relationship. You can put as many variable declarations in the .data section as you need. It is just a chunk of memory in RAM. Then your code decides which values to read from RAM into registers, does some computation, and stores values back into memory, or calls an API, or something. |
|||
![]() |
|
Mino 12 Apr 2018, 12:36
Ok, thanks
![]() It's more or less what I expected. But when I talk about variables, I think of this (the term may not be well chosen, sorry): Code: a db 'n' b dw 100 c dd 0.76 ... _________________ The best way to predict the future is to invent it. |
|||
![]() |
|
revolution 12 Apr 2018, 12:46
In the above code a, b, and c are pointers to an area of memory. They can point to values that can change (variables), or they can point to values that don't change (constants). Your code will decide which usage they are intended to have. fasm doesn't know what you will do with them. You might never read them. Or you might accidentally change a constant. Or you might only ever write to them. It could be anything, and fasm will simply encode the instructions for you to do that.
|
|||
![]() |
|
Mino 12 Apr 2018, 13:11
So, if I understood correctly, the "data" section just loads data into memory, and the name we assign to each value represents its location in the RAM (so a large pointer). Hence the use of '[' and ']' if you want to use them to frame the names in order to recover only the pointed value I imagine.
And to do constants, we could do that then: Code: section '.const' data readable ; Without "writeable" ... ? _________________ The best way to predict the future is to invent it. |
|||
![]() |
|
revolution 12 Apr 2018, 13:22
Mino wrote: So, if I understood correctly, the "data" section just loads data into memory, and the name we assign to each value represents its location in the RAM (so a large pointer). Hence the use of '[' and ']' if you want to use them to frame the names in order to recover only the pointed value I imagine. Mino wrote: And to do constants, we could do that then: |
|||
![]() |
|
Mino 12 Apr 2018, 13:58
revolution wrote: If your OS supports section attributes then making it readable only for constants is usually a good idea. What do you mean? Doesn't that fit my example? _________________ The best way to predict the future is to invent it. |
|||
![]() |
|
revolution 12 Apr 2018, 19:16
What I mean is that not all OSes support having sections that can restrict writing. If you use Windows NT or later then it will work fine.
|
|||
![]() |
|
Furs 12 Apr 2018, 19:17
Those aren't variables btw. They don't even exist in the executable. The assembler (Fasm) just replaces them with their address in memory when compiling the source code.
Of course their data exists in memory, but when you say [a], it actually just means something like [1234] in code (i.e. addresses offset 1234, where the data is). Just think of RAM/virtual address as a huge array of bytes. Even the notation makes sense (array[index] is how you access arrays in C, just no name here, since it's implicit). |
|||
![]() |
|
Mino 12 Apr 2018, 19:20
Okay, thanks a lot to you two
![]() |
|||
![]() |
|
rugxulo 12 Apr 2018, 23:23
Mino wrote:
https://en.wikipedia.org/wiki/Data_segment Quote:
It depends on your object format and OS loader. IIRC, old a.out only supported three sections (text, data, bss). Various OSes (e.g. Minix 2.x) would share the code segment among processes so that only the data sections would need to be duplicated, thus saving total used RAM. |
|||
![]() |
|
Mino 13 Apr 2018, 07:37
Ha, I understand even better now, thanks
![]() Concerning the operating system, I (will) compile mainly under Windows, Linux and Mac. The "classics" in a way ^^ . |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.