flat assembler
Message board for the users of flat assembler.
Index
> Main > Indexing data with a base address |
Author |
|
revolution 25 Sep 2015, 01:42
In 32-bit code you can use any register as a base, or an index, or both. The index can be multiplied by 1,2,4 or 8. And an offset can be included also.
Code: mov eax,[ebx + ecx*4 + 0x1000] Last edited by revolution on 25 Sep 2015, 02:16; edited 1 time in total |
|||
25 Sep 2015, 01:42 |
|
Logos 25 Sep 2015, 02:12
Thanks! That was very informative.
Looks like x86 assembler is a bit like a black art. When I have searched for information on x86 assembler on the internet, I have never found any information like that. Where could I have found that information? Is there any web page or document? |
|||
25 Sep 2015, 02:12 |
|
revolution 25 Sep 2015, 02:16
Both Intel and AMD provide the CPU instruction set references on their respective websites. Those are the canonical references. But even the fasm download has the instructions explained in the fasm.pdf file. And hundreds of other websites have the CPU instruction set(s) explained in various ways and to various levels of detail and precision.
|
|||
25 Sep 2015, 02:16 |
|
Logos 25 Sep 2015, 17:49
Is the static offset a signed 32bit value?
I have looked at many different sites, and never seen any example on using two registers combined for an address. And I have not seen any site talking about that you can use any register as a address. To me it looks like, most sites refer to very old information on how to program in assembler. Where can I find the fasm.pdf file? I Looked for it, but could not find any file named like that. But I finally found it. It's only in the 'flat assembler 1.71.39 for Windows' archive, not in the Linux, dos, or Unix archives on the download page. And it's not talked about in the fasm.pdf file. The only thing I can find about it, is the following somewhat misleading quotes from that file... Quote:
It's also stated in that document that... Quote:
...followed by examples. But none of them talks about combining register, or adding a static offset. |
|||
25 Sep 2015, 17:49 |
|
JohnFound 25 Sep 2015, 18:12
You probably read the old DOS tutorials, that target the first 8088/8086 processors in real mode. The assembly language for 32/64 bit protected mode is much more powerful and flexible.
Anyway, download and read the Inter reference. As revolution said, It is the canonical reference. Although it is a long read - several thousands pages. Also, try to search explicitly assembly for Windows/Linux programming tutorials. They describe exactly what you need. Also, try to read the example programs in the FASM package and the code posted in this forum. |
|||
25 Sep 2015, 18:12 |
|
ACP 26 Sep 2015, 08:17
This a bit old but not bad introduction to x64 architecture: http://www.cs.cmu.edu/~fp/courses/15213-s07/misc/asm64-handout.pdf
It is shorter than Intel manuals so it may be good starting point. |
|||
26 Sep 2015, 08:17 |
|
Tomasz Grysztar 26 Sep 2015, 12:48
ACP: I'm not sure whether pointing to a document that uses the gas syntax is a good idea here.
To OP: fasm's manual itself recommends reading the Intel Architecture Software Developer's Manual, because fasm's documentation contains only cursory information about the x86 architecture - it focuses on defining the syntax options for every instruction, because this is the information that may be specific to an assembler (some syntax options vary between the different assemblers), while it assumes that the programmer has the basic knowledge of the architecture from elsewhere (like said Intel manual). About the addresses it only says in section 1.2.1 that "the address (also any numerical expression, but it may contain registers) should be enclosed in square brackets or preceded by ptr operator". For details on what kind of numerical expression containing register is allowed you need the knowledge about the specific processor architecture (and the official manual from Intel is the best source of it). Note that fasm may allow expressions containing registers to be more complex that the ones defined by architecture, as long as they are algebraically equivalent, for example "inc byte [(eax+2)*3]" is going to be assembled into "inc byte [eax+eax*2+6]". Because the Intel manuals in their current iteration have grown into thousands of pages that may be overwhelming for a beginner (especially when a knowledge about the instruction sets like MMX/SSE, x86-64 or AVX may not be needed for someone that just want to start with basic x86 programming), I would recommend reading the old 80386 manual from 1986. This is the document that I used myself when writing the very first version of fasm, and it contains a lot of the useful information, while not being as overwhelming as the modern ones. You can find the addressing through base, index and displacement explained nicely in section 2.5.3.2, "Effective-Address Computation". |
|||
26 Sep 2015, 12:48 |
|
ACP 26 Sep 2015, 14:41
Tomasz Grysztar wrote: ACP: I'm not sure whether pointing to a document that uses the gas syntax is a good idea here. Fair point but since the discussion was about the instruction set not FASM itself I allowed myself to post the link as I find the document useful even if example code is using different syntax. There are many other publications that are - unfortunately - using gas instead of FASM syntax so I guess there is nothing wrong when newbies discover it sooner than later. |
|||
26 Sep 2015, 14:41 |
|
JohnFound 26 Sep 2015, 16:08
Well, the children, as a rule, know about the pornography, but this does not means that the parents should pointing them to the best porno sites. Are they?
|
|||
26 Sep 2015, 16:08 |
|
ACP 26 Sep 2015, 18:13
JohnFound wrote: Well, the children, as a rule, know about the pornography, but this does not means that the parents should pointing them to the best porno sites. Are they? I don't thing your example apply here. There are many assemblers and while we probably all agree that FASM is superior you still can find useful code using different syntax. Learning to read code in a different syntax is useful and part of education process while pointing porn sites isn't. Secondly I will be more than happy to read similar - to the one I've pointed in good faith - FASM-centric paper. I'm not aware of such but I'm sorry if I'm wrong and I will be more than glad to read it. |
|||
26 Sep 2015, 18:13 |
|
Logos 26 Sep 2015, 22:08
I think that it would be appropriate to add a few more lines, in the examples in the "2.1.1 Data movement instructions" in the fasm manual, that demonstrate Based-Indexed Addressing (for use in the source and destination) not just indirect addressing.
A few more lines in that document can't hurt. And certainly not than almost all information about x86 programming is ignorant about it. It would be a great improvement. I tried to find older original documents, but couldn't find any on intels site or elsewhere. So thanks for the following statement: Quote: I would recommend reading the old 80386 manual http://board.flatassembler.net/topic.php?p=55709#55709 from 1986. This is the document that I used myself when writing the very first version of fasm, and it contains a lot of the useful information, while not being as overwhelming as the modern ones. You can find the addressing through base, index and displacement explained nicely in section 2.5.3.2, "Effective-Address Computation". A few more lines in the fasm manual would spare future x86 explorers a huge amount of time. People have a short attention span, and it's a huge wast of time to spend hours and days for each individual, just to get hold of basic information that only could have taken a few minutes if it was pointed out from the start. So a few lines in the appropriate place could spare many hundreds hours in total. Remains of the following: Quote: Larry Kenyon was the engineer working on the disk driver and file system. Steve came into his cubicle and started to exhort him. "The Macintosh boots too slowly. You've got to make it faster!" |
|||
26 Sep 2015, 22:08 |
|
fasmnewbie 27 Sep 2015, 14:10
Logos wrote: I think that it would be appropriate to add a few more lines, in the examples in the "2.1.1 Data movement instructions" in the fasm manual, that demonstrate Based-Indexed Addressing (for use in the source and destination) not just indirect addressing. You probably got the wrong idea of what FASM manual is all about. FASM manual isn't a textbook on Assembly Programming that teaches all kind of addressing modes. Even the official intel manual mentions only 3 addressing modes while other textbooks mention 7. |
|||
27 Sep 2015, 14:10 |
|
Logos 27 Sep 2015, 17:53
fasmnewbie wrote:
The x86 need better documentation, so why would 3-4 more lines make the universe worse of? What is the reason why most information about x86 assembler, still talks about how to programs like we still live before 1996? In 1996 you had both windows 95 and you had direct X, so you could make programs and games that run faster in windows than in DOS (Win 95 used a flat memory model). And the x86, has the flat memory model in protected mode since 1986, when the 386 was introduced. But people still talks about how to program x86 processors, in ways that in best of worlds, should have been forgotten when we left the 80's. In that context, it would be great if people stopped to program like it still was 1984. It's not a good thing if people stay ignorant about x86 assembler. Why do most programmers ignore x86 assembler? I don't think it's about the fantastic speed or the orthogonal instruction sets of the x86, that all modern OS use. It's about the huge amount of misleading and confusing documentation, that hides the processors true nature. And talks about it like it had no orthogonality at all, and like it has really crippled addressing modes and instruction set, compared to a RISC processor. Most x86 documentation is like taking a acid trip, as it talks about how to program like it still was 1984, and talks about huge amount of unused modes of the x86, mashed some crippled sprinkles of 386 programming in the flat memory model. Documentation about x86 is confusing, as it talks a lot about possible programming models, that no one uses. And they teaches how to program like the x86 has no orthogonal instructions. As I learn more about the x86 processor, I like it more and more. But there is a huge amount of misleading information out there. In actuality, x86 is more like a really good RISC processor to program. But to get there, you have to ignore 95% of all you read about this processor. There is a really good reason why x86 processor is that fast. And it's because it has less registers than a modern RISC processor. Many registers makes RISC processors slow to use for normal computer use. Take the Power PC processor, it has a huge amount of registers. This makes it fast for DSP applications. But in a OS with lots of applications running, it uses a huge amount of time wasted to save and reload all registers when switching threads. One of the things that make ARM good for running a common OS with lots of applications, is that it has less registers than most RISC processors. I really begin to like the x86 processor, but it has nothing to do with the documentation. But the fasm documentation is much better than most information out there. |
|||
27 Sep 2015, 17:53 |
|
fasmnewbie 28 Sep 2015, 04:19
PEexecutable]
I really don't know what you want after reading your elaborated comment. Just like I said, Intel Manual is not a textbook on x86 programming simply because, we earthlings been told that Intel's INSTRUCTION MNEMONICS ARE NOT A PROGRAMMING LANGUAGE. Intel provides definitions via symbolic interfaces so that they don't have to use binaries to explain what the CPU does. They especially don't teach you how to program. It was the third party initiatives such as Tomasz that turn the mnemonics into actual implementation by providing a compiler so that we can all use an assembler. Tomasz can change MOV instruction mnemonic to MOVE_IT_BABY and implement it like a MOV. That's when you need an assembler manual, to explain such mnemonic implementation and definition process. That's why we can see similar instruction set references in FASM manual because Tomasz wants us to know how he implements such thing. |
|||
28 Sep 2015, 04:19 |
|
revolution 28 Sep 2015, 04:22
fasmnewbie wrote: PEexecutable |
|||
28 Sep 2015, 04:22 |
|
fasmnewbie 28 Sep 2015, 04:26
revolution wrote:
|
|||
28 Sep 2015, 04:26 |
|
revolution 28 Sep 2015, 04:36
fasmnewbie wrote: That's because we are lovers. Lovers know each other's smell. |
|||
28 Sep 2015, 04:36 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.