There are [] operations which are similar to dereferencing in high-level languages. So does that mean that every variable and register name is just a pointer or are pointers a high-level languages idea and have no use in Assembly?
Is every variable and register name just a pointer in NASM Assembly?
711 views Asked by CrazyMan AtThere are 2 answers
Brendan
On
Assembly language doesn't have variables, pointers or type checking. It has addresses and registers (and no type checking).
A variable (e.g. in C) is a higher level thing - a way to abstract the location of a piece of data so that you don't have to care if the compiler felt like putting it in a register or in memory. A variable also has a type; which is used to detect some kinds of bugs, and used to allow the compiler to automatically convert data to a different type for you.
A pointer (e.g. in C) is a variable (see above). The main difference between a pointer and a "not pointer" is the type of data it contains - for a pointer the variable typically contains an address, but a pointer is not just an address, it's the address of something with a type. This is important - if it was just an address then the compiler wouldn't know how big it is, couldn't detect some kinds of bugs, and couldn't automatically convert data (e.g. consider what would happen for int foo = *pointer_to_char; if the compiler didn't know what type of data the pointer points to).
Related Questions in POINTERS
- What does: "char *argv[]" mean?
- Memory allocated for pointer to string literals
- change the value of double pointer with indirection(dereference) operator cause segmentation fault
- Unexpected result when assigning and printing pointer value of two-dimensional array with its name
- The character array data changes when I use it inside for loop. I do not understand why does it change, the data ")" becomes "("
- char * gives garbage value when pointing to a variable of a function in C
- What is correct way to copy struct instance with fields in Go?
- PHP FFI: How to pass PHP class object to C++
- How to make a single slider with three pointer
- rac dangling pointer crash。
- Is casting "pointer to array of type" to "pointer to type" defined?
- C++: How to implement a pointer to another class as a member?
- What is the purpose of (int *) p here?
- Initialize a structure pointer to NULL, then try to change its members
- Could an unitialized pointer be a NULL pointer?
Related Questions in ASSEMBLY
- Is there some way to use printf to print a horizontal list of decrementing hex digits in NASM assembly on Linux
- How to call a C language function from x86 assembly code?
- Binary Bomb Phase 2 - Decoding Assembly
- AVR Assembly Clock Cycle
- Understanding the differences between mov and lea instructions in x86 assembly
- ARM Assembly code is not executing in Vitis IDE
- Which version of ARM does the M1 chip run on?
- Why would %rbp not be equal to the value of %rsp, which is 0x28?
- Move immediate 8-bit value into RSI, RDI, RSP or RBP
- Unable to run get .exe file from assembly NASM
- DOSbox automatically freezes and crashes without any prompt warnings
- Load function written in amd64 assembly into memory and call it
- link.exe unresolved external symbol _mainCRTStartup
- x86 Wrote a boot loader that prints a message to the screen but the characters are completely different to what I expected
- running an imf file using dosbox in parallel to a game
Related Questions in NASM
- Is there some way to use printf to print a horizontal list of decrementing hex digits in NASM assembly on Linux
- scanf in x64 NASM results in segfault
- Seeking for the the method for adding the DL (data register) value to DX register
- Unable to run get .exe file from assembly NASM
- link.exe unresolved external symbol _mainCRTStartup
- x86 Wrote a boot loader that prints a message to the screen but the characters are completely different to what I expected
- Why do register arg values need to be re-assigned in NASM after an int 0x80 system call?
- Why does shr eax, 32 not do anything?
- Behavior of the adress 0x7e00 in different sectors and their alternatives
- No BIOS output from sector 1
- kernel.asm:60: error: comma, colon, decorator or end of line expected after operand
- New to Assembly, trying to get a loop working
- x86 BIOS stage 1 boot code halting after loop from interrupt
- Calling CreateWindowEx from x64 assembly
- Setting up Segment Registers, x86
Related Questions in CONCEPTUAL
- Multiprocessing/ Threading / asyncio for PyQt6 and python-can
- In a loop what's the best practice to get input (cli) with validation, that also resumes like this?
- Should I have most of my code in the with statement? Python
- What type of datastructure does 'collections.defaultdict(set)' create?
- Finding the right approach for creating an accumulated information table
- Unable to add a generic concrete type to a list of generic interface
- Time complexity of the following two programs?
- Conceptual workflow for python app API store data for reporting usage
- Shopware 6 administration: on create new product, price cannot be null
- Why is the "multiple .c files + linker" workflow is preferred over "multiple .h files included in one .c file"?
- What do files actually contain, and how are they "read"? What is a "format" and why should I worry about them?
- Technical concept for a timeline-scheduler
- How to start a process with multiple threads right from the beginning?
- Best way to store date in a CDM (Conceptual Data Model)?
- Is every variable and register name just a pointer in NASM Assembly?
Related Questions in LANGUAGE-CONCEPTS
- What type of datastructure does 'collections.defaultdict(set)' create?
- How do you 'catch' Email addresses inside a log file?
- How does the nlp object work in spacy library?
- What Is The Purpose Of A Record Struct?
- Rust equivalent of concurrent code written in Go?
- When is a variable in a nested scope destroyed from the memory?
- Is every variable and register name just a pointer in NASM Assembly?
- When overloading a parent method, why did PHP8.1 change towards deprecating incompatible return types?
- What is AsyncStorage *for*?
- Java import wildcard accessibility for nested static classes
- An exercise about Java constructors
- What's the idea behing W-, P- and I-files?
- Add new concepts to the WordNet using NLTK python API OR attach other concepts banks to WordNet
- Why does the value of i not increment for i=i++; statement?
- Why is memory utilization continuiously increasing when using dependency injection in a C# console application?
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Popular Tags
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Pointers are a useful concept in asm, but I wouldn't say that symbol names are truly pointers. They're addresses, but they aren't pointers because there's no storage holding them (except metadata, and embedded into the machine code), and thus you can't modify them. A pointer can be incremented.
Variables are a high-level concept that doesn't truly exist in assembly. Asm has labels which you can put at any byte position in any section, including
.data,.text, or whatever. Along with directives likedd, you can reserve space for a global variable and attach a symbol to it. (But a variable's value can temporarily be in a register, or for its whole lifetime if it's a local variable. The high-level concept of a variable doesn't have to map to static storage with a label.)Types like integer vs. pointer also don't really exist in assembly; everything is just bytes that you can load into an integer, XMM, or even x87 FP register. (And you don't really have to think of that as type-punning to integer and back if you use
eaxto copy the bytes of afloatfrom one memory location to another, you're just loading and storing to copy bytes around.)But on the other hand, a pointer is a low-enough level concept still be highly relevant in assembly. We have the stack pointer (RSP) which usually holds a valid address, pointing to some memory we're using as stack space. (You can use the RSP register to hold values that aren't valid addresses, though. In that case you're not using it as a pointer. But at any time you could execute a
pushinstruction, ormov eax, [rsp], and cause an exception from the invalid address.)A pointer is an object that holds the address of another object. (I'm using "object" in C terms here: any byte[s] of storage that you can access, including something like an
int. Not objected as in object-oriented programming.) So a pointer is basically a type of integer data, especially in assembly for a flat memory model where there aren't multiple components to it. For a segmented memory model, a seg:off far pointer is a pair of integers.So any valid address stored anywhere in register or memory can usefully be thought of as a pointer.
But no, a symbol defined by a label is not a pointer. Conceptually, I think it's important to think of it as just a label. A pointer is itself an object (some bytes of storage), and thus can be modified. e.g. increment a pointer. But a symbol is just a way to reference some fixed position.
In C terms, a symbol is like a
char symbol[], not achar *symbol = NULL;If you use baresymbol, you get the address. Likemov edi, symbolin NASM syntax. (Ormov edi, OFFSET symbolin GNU .intel_syntax or MASM. See also How to load address of function or label into register for practical considerations like using RIP-relative LEA if 32-bit absolute addresses don't work.)You can deref any symbol in asm to access the bytes there, whether that's
mov eax, [main]to load the first 4 bytes of machine code of that function, ormov eax, [global_arr + rdi*8]to index into an array, or any other x86 addressing mode. (Caveat: 32-bit absolute addresses no longer allowed in x86-64 Linux? for that last example).But you can't do
arr++; that makes no sense. There is no storage anywhere holding that address. It's embedded into the machine code of your program at each site that uses it. It's not a pointer. (Note that Carr[4] = 1compiles to different asm depending onchar *arr;vs.char arr[], but in asm you have to manually load the pointer value from wherever it's stored, and then deref it with some offset.)If you have a label in asm whose address you want to use in C, but that isn't attached to some bytes of storage, you usually want to declare it as
extern const char end_of_data_section[];or whatever.So for example you can do
size_t data_size = data_end - data_start;and get the size in bytes as a link-time constant, if you arranged for those symbols to be at the end/start of your.datasection. With a linker script or withglobal data_end/data_end:in your NASM source. Probably at the same address as some other symbol, for the start.