flat assembler
Message board for the users of flat assembler.
Index
> Main > Designing an assembler - need help on instruction encoding |
Author |
|
b1528932 21 Aug 2010, 14:36
First of all you need perfect knowleadge of ALL released cpus you want to support.
Instruction can be encoded diffrently (or not at all) on diffrent cpus. Also, you need full cpu state, for example if cpu is in real mode, protected mode, long mode, or any other special mode that change instruction encoding. Remember, that assembler is just a language - in reality you have opcodes and you just give them names. I suggest you write emulator, in my opinion its bilion times easier. I dont think that any human is capable of writing what you suggest. it is possible, but huge, cpu specyfic, and kind of useless. |
|||
21 Aug 2010, 14:36 |
|
Tomasz Grysztar 21 Aug 2010, 15:06
This kind of questions is very welcome here, and it really is somehow related to fasm - I was once at the similar position when started writing my first assembler (the one before fasm); and at the time I had no access to internet to look for help, so all I had were those complex tables and lots of spare time...
The original 8086 code was based on octal numbers, so it will help if you try too look at instruction codes expressed in octal base, as you will then easily notice their structure. Look at the example: AND CL,DL Its opcode expressed in octal base is: 40o, 321o The digit 4 in the first byte means the AND operation (0 would be ADD, 1 - OR, 2 - SBB, etc. up to 7; you can look it up in the tables). The digit 0 in the first byte means the byte-size operation with register as source (1 would mean word-size operation with register as source, 2 would mean byte-size operation with register as destination, etc.) The digit 3 at the top of the second byte means that both operands are registers (other values would mean various types of memory addressing for the memory operand). The digit 2 in the middle is the one that corresponds to register operand (2 in case of byte-size registers means DL, 0 would be AL, 1 - CL, 3 - BL, etc. - again, you will find a table for this). The digit 1 at the end is the one that corresponds to operand that can be register or memory (this field is usually caled "r/m") - in this case we have selected that both operands are registers, so r/m field is interpreted as byte-size register, namely CL. I encourage you to get some disassembler (for example the one by CandyMan; or some tool like BIEW) and experiment a little - try to write different codes and see the effects (you can use fasm for this; just put "DB 40o, 321o" in a source file and assemble it to get the example result). |
|||
21 Aug 2010, 15:06 |
|
Tomasz Grysztar 21 Aug 2010, 15:18
[offtopic]It really was the perfect question for me to answer now, when I'm enjoying a tea break in a middle of implementing AVX into fasm. [/offtopic]
|
|||
21 Aug 2010, 15:18 |
|
edemko 21 Aug 2010, 19:48
[oops]
what is an AVX which coffee do you drink, i drink tea, green tee and kvass [/oops] |
|||
21 Aug 2010, 19:48 |
|
vivek 22 Aug 2010, 14:05
Thanks , Tomasz .That helped ,btw, is there any other material / book you suggest besides the intel manuals
|
|||
22 Aug 2010, 14:05 |
|
vid 22 Aug 2010, 15:34
|
|||
22 Aug 2010, 15:34 |
|
coconut 22 Aug 2010, 20:15
edemko wrote: [oops] i guess this: http://en.wikipedia.org/wiki/Advanced_Vector_Extensions tomasz how will you test, as wikipedia states there aren't any CPUs that support this until 2011? |
|||
22 Aug 2010, 20:15 |
|
Tomasz Grysztar 22 Aug 2010, 22:05
coconut wrote:
Neither did I have access to any 64-bit hardware when I was implementing x86-64 (and even writing first example programs for it). And AVX is now even better documented than x86-64 was back then. |
|||
22 Aug 2010, 22:05 |
|
coconut 23 Aug 2010, 01:41
Tomasz Grysztar wrote:
|
|||
23 Aug 2010, 01:41 |
|
edemko 23 Aug 2010, 10:10
Will they ever improve a quick copying instruction, is there such?
We use rep movsd, i'd like seeing rep movsQQQ, hoho |
|||
23 Aug 2010, 10:10 |
|
bitRAKE 24 Aug 2010, 03:54
REP MOV* is the quick copy - newer processors have special handling for (E|R)CX > N.
The best way to learn assembly is part-time with the computer and part-time away from the computer. One must test their understanding in this way, and in time the depth of code composed in the mind increases, imho. Tomasz is an excellent example of this - truly inspiring. There are many talented people here. |
|||
24 Aug 2010, 03:54 |
|
Madis731 24 Aug 2010, 09:15
[offtopic]
I think AVX even had a simulator/emulator thingy ... here it is: http://software.intel.com/en-us/avx/ No need to have a CPU Tomasz, can you comment on implementing AVX being easy so-to-speak. As far as I've read and understand it is really thought through and there are little to no exceptions [/offtopic] |
|||
24 Aug 2010, 09:15 |
|
Tomasz Grysztar 24 Aug 2010, 12:15
Madis731 wrote: Tomasz, can you comment on implementing AVX being easy so-to-speak. |
|||
24 Aug 2010, 12:15 |
|
rugxulo 01 Sep 2010, 02:02
|
|||
01 Sep 2010, 02:02 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.