Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Do Assemblers Map x86 Instruction Mnemonics to Binary Machine Instructions?

Tags:

x86

assembly

I'm interested in writing an x86 assembler. I'm wondering what is a good way to map x86 assembly mnemonic instructions (using an Intel-like syntax) into the corresponding binary machine code instructions.

like image 373
mudge Avatar asked May 03 '10 18:05

mudge


People also ask

How do assembly languages use mnemonics?

In assembly language, mnemonics are used to specify an opcode that represents a complete and operational machine language instruction. This is later translated by the assembler to generate the object code.

Which type of mapping is used for mapping assembly language instructions into machine language instructions?

The Assembler The program that translates from assembly language to machine language is called an Assembler A program that translates from assembly language to machine language.. It allows the programmer to specify the memory locations for his data and programs and symbolically refer to them in his assembly code.

Does assembly use mnemonic?

Assembly language uses a mnemonic to represent, e.g., each low-level machine instruction or opcode, each directive, typically also each architectural register, flag, etc. Some of the mnemonics may be built in and some user defined. Many operations require one or more operands in order to form a complete instruction.

What is x86 assembly instructions?

The x86 instruction set refers to the set of instructions that x86-compatible microprocessors support. The instructions are usually part of an executable program, often stored as a computer file and executed on the processor.


1 Answers

Do you want to understand the physical mapping of mnemonics to machine code? If so volume 2A & 2B of the the Intel IA32/IA64 reference manuals describe the binary format of x86 machine code .

The x86 instruction set page on Wikipedia has a compact listing of all the instructions categorized by when they were introduced, which might help you prioritize what to implement first.

However, if you are asking about how to go about parsing an assembly code text file to get to the point where your program could start writing out machine code then you basically need to understand how to write a compiler. The tools lex and yacc are good places to start but if you don't know how build a compiler you'll also need to get a book. I think the Dragon book is the best one out there but there are any number of other books you could use, SO has plenty of recommendations.

like image 124
Andrew O'Reilly Avatar answered Sep 20 '22 03:09

Andrew O'Reilly