Questions tagged [assembly]

Assembly language questions. Please tag the processor and/or the instruction set you are using, as well as the assembler, a valid set should be like this: ([assembly] [x86] [gnu-assembler] or [att]). Use the [.net-assembly] tag instead for .NET assemblies, [cil] for .NET assembly language, and for Java bytecode, use the tag java-bytecode-asm instead.

Assembly is a family of very low-level programming languages, just above machine code. In assembly, each statement corresponds to a single machine code instruction. These instructions are represented as mnemonics in the given assembly language and are converted into executable machine code by a utility program referred to as an assembler; the conversion process is referred to as assembly, or assembling the code.

Language design

Basic elements

There is a large degree of diversity in the way that assemblers categorize statements and in the nomenclature that they use. In particular, some describe anything other than a machine mnemonic or extended mnemonic as a pseudo-operation (pseudo-op). A typical assembly language consists of three types of instruction statements that are used to define program operations:

  • Opcode mnemonics
  • Data sections
  • Assembly directives

Opcode mnemonics and extended mnemonics

Instructions (statements) in assembly language are generally very simple, unlike those in high-level languages. Generally, a mnemonic is a symbolic name for a single executable machine language instruction (an opcode), and there is at least one opcode mnemonic defined for each machine language instruction. Each instruction typically consists of an operation or opcode plus zero or more operands. Most instructions refer to a single value, or a pair of values. Operands can be immediate (value coded in the instruction itself), registers specified in the instruction or implied, or the addresses of data located elsewhere in storage. This is determined by the underlying processor architecture: the assembler merely reflects how this architecture works. Extended mnemonics are often used to specify a combination of an opcode with a specific operand. For example, the System/360 assemblers use B as an extended mnemonic for BC with a mask of 15 and NOP for BC with a mask of 0.

Extended mnemonics are often used to support specialized uses of instructions, often for purposes not obvious from the instruction name. For example, many CPU's do not have an explicit NOP instruction, but do have instructions that can be used for the purpose. In 8086 CPUs the instruction xchg ax,ax is used for nop, with nop being a pseudo-opcode to encode the instruction xchg ax,ax. Some disassemblers recognize this and will decode the xchg ax,ax instruction as nop. Similarly, IBM assemblers for System/360 and System/370 use the extended mnemonics NOP and NOPR for BC and BCR with zero masks. For the SPARC architecture, these are known as synthetic instructions

Some assemblers also support simple built-in macro-instructions that generate two or more machine instructions. For instance, with some Z80 assemblers the instruction ld hl,bc is recognized to generate ld l,c followed by ld h,b. These are sometimes known as pseudo-opcodes.

Tag use

Use the tag for assembly language programming questions, on any processor. You should also use a tag for your processor or instruction set architecture (, , , , , etc). Consider a tag for your assembler as well (, , , et cetera).

If your question is about inline assembly in C or other programming languages, see . For questions about .NET assemblies, use instead and for .NET's Common Intermediate Language, use . For Java ASM, use the tag .

Resources

Beginner's resources

Assembly language tutorials, guides, and reference material

43242 questions
11
votes
6 answers

What's the purpose of using assembly language inside a C program?

What's the purpose of using assembly language inside a C program? Compilers are able to generate assembly language already. In what cases would it be better to write assembly than C? Is performance a consideration?
san6086
  • 459
  • 8
  • 20
11
votes
1 answer

Why I cannot compile the assembly codes for x64 platform with VC2010?

I am now practicing assembly codes mixed with c++ codes, and I can compile the mixed codes for win32 platform without any problem as the following codes illustrate: int main() { char alphabet = 'X'; printf ("Type letter = "); __asm { …
feelfree
  • 11,175
  • 20
  • 96
  • 167
11
votes
2 answers

GDB complains No Source Available

I'm running on Ubuntu 12.10 64bit. I am trying to debug a simple assembly program in GDB. However GDB's gui mode (-tui) seems unable to find the source code of my assembly file. I've rebuilt the project in the currently directory and searched google…
Irresponsible Newb
  • 603
  • 2
  • 7
  • 15
11
votes
3 answers

Speed up x64 assembler ADD loop

I'm working on arithmetic for multiplication of very long integers (some 100,000 decimal digits). As part of my library I to add two long numbers. Profiling shows that my code runs up to 25% of it's time in the add() and sub() routines, so it's…
cxxl
  • 4,939
  • 3
  • 31
  • 52
11
votes
3 answers

Writing x86_64 linux kernel module in assembler

I try write simple kernel module (v3.6) in nasm, but insmod say me: $ sudo insmod ./hello.ko insmod: ERROR: could not insert module ./hello.ko: Invalid module format $ echo $? 1 I compile my code with: $ nasm -f elf64 -o hello.m hello.asm $ ld -m…
11
votes
6 answers

gas vs. nasm: which assembler produces the best code?

Both tools translate assembly instructions directly into machine code, but is it possible to determine which one produces the fastest and cleanest code?
user157000
11
votes
2 answers

Why does gcc push %rbx at the beginning of main?

The latest version of gcc is producing assembly that doesn't make sense to me. I compiled the code using no optimization; but, some parts of this code don't make sense, even with no optimization. Here is the C source: #include int…
Zack
  • 6,232
  • 8
  • 38
  • 68
11
votes
2 answers

Why does GCC emit "lea" instead of "sub" for subtraction?

I am looking at some assembly that was generated by disassembling some C programs and I am confused by a single optimization that I see repeated frequently. When I have no optimizations on the GCC compiler uses the subl instruction for subtraction,…
Hunter McMillen
  • 59,865
  • 24
  • 119
  • 170
11
votes
3 answers

gdb + nasm debug info not being created

I am trying to debug a small .asm file that I wrote in Ubuntu. I am however running into an issue where my symbol table is not being loaded and was looking for some help. I am compiling my program as follows. nasm -f elf -g -F dwarf bs.asm gcc -m32…
cpowel2
  • 605
  • 1
  • 11
  • 20
11
votes
1 answer

Is it possible to use SSE and SSE2 to make a 128-bit wide integer?

I'm looking to understand SSE2's capabilities a little more, and would like to know if one could make a 128-bit wide integer that supports addition, subtraction, XOR and multiplication?
Erkling
  • 509
  • 4
  • 16
11
votes
3 answers

How does hardware run assembly? How was the first assembler written?

Having taken a course on compilers and making a rudimentary one by myself, i still have this lingering doubt about the first compiler. From a high to low level, i see code running in lets say C or C++ which gets converted to the respective assembly…
user720694
  • 2,035
  • 6
  • 35
  • 57
11
votes
5 answers

If the only difference between 32bit and 64bit CPUs is their register size then why must 32 bit programs be rewritten for a 64 bit platform?

What is the actual difference in terms of source code when writing a 64 bit program? For example is only the assembly different? It's not like there's a 64 bit version of C++. If it's something as simple as an option on the compiler than how come…
Celeritas
  • 14,489
  • 36
  • 113
  • 194
11
votes
2 answers

How does the Objective-C runtime retrieve the list of classes and methods?

If I get the following Objective-C source file: // test.m #import @interface MySuperClass: Object { } -(void) myMessage1; @end @implementation MySuperClass -(void) myMessage1 { } @end @interface MyClass: MySuperClass…
LuisABOL
  • 2,951
  • 4
  • 25
  • 57
11
votes
0 answers

How to convert Linux 32-bit gcc inline assembly to 64-bit code?

I'm attempting to convert RR0D Rasta Ring 0 Debugger from 32-bit mode to 64-bit mode (long mode) in Linux, using gcc. I'm familiar with x86 32-bit assembly (in MS-DOS environment) but I'm a beginner in x86 64-bit assembly and in Linux assembly…
nrz
  • 10,435
  • 4
  • 39
  • 71
11
votes
4 answers

Is CIL an assembly language and JIT an assembler

Does the Just In Time Compiler(JIT) really map each of the Common Intermediate Language(CIL) instructions in a program to underlying processor's opcodes? And If so can we call CIL an assembly language and JIT an assembler Note: Wikipedia doesn't…
Anirudha
  • 32,393
  • 7
  • 68
  • 89