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) Note that you should use the ".net-assembly" tag instead for .NET assembly languages, 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

37939 questions
9
votes
1 answer

What segment is used by default in x86 indirect addressing?

I'm a little confused as to exactly what segment is used when you have x86 assembly like the below (Intel syntax): mov ax, [di] I'm pretty certain it wouldn't be the code segment, I'm thinking either the data segment or the stack? (Or is the stack…
PeterBelm
  • 698
  • 1
  • 6
  • 17
9
votes
2 answers

How's __RTC_CheckEsp implemented?

__RTC_CheckEsp is a call that verifies the correctness of the esp, stack, register. It is called to ensure that the value of the esp was saved across a function call. Anyone knows how it's implemented?
ollydbg
  • 3,289
  • 5
  • 26
  • 29
9
votes
2 answers

Is Intel's timestamp reading asm code example using two more registers than are necessary?

I'm looking into measuring benchmark performance using the time-stamp register (TSR) found in x86 CPUs. It's a useful register, since it measures in a monotonic unit of time which is immune to the clock speed changing. Very cool. Here is an Intel…
Edd Barrett
  • 2,751
  • 2
  • 23
  • 37
9
votes
7 answers

Causing a divide overflow error (x86)

I have a few questions about divide overflow errors on x86 or x86_64 architecture. Lately I've been reading about integer overflows. Usually, when an arithmetic operation results in an integer overflow, the carry bit or overflow bit in the FLAGS…
Channel72
  • 22,459
  • 30
  • 97
  • 168
9
votes
1 answer

Slow jmp-instruction

As follow up to my question The advantages of using 32bit registers/instructions in x86-64, I started to measure the costs of instructions. I'm aware that this have been done multiple times (e.g. Agner Fog), but I'm doing it for fun and self…
ead
  • 27,136
  • 4
  • 67
  • 108
9
votes
5 answers

Online Assembly language resources

does anyone have any resources for learning assembly language on x86? I'm trying to debug a program in MSVC++6 and frequently come across assembly (like stepping into memcpy).. Previously I just ignored these but memcpy keeps throwing exceptions and…
krebstar
  • 3,778
  • 8
  • 42
  • 62
9
votes
5 answers

How does a graphics driver programmatically communicate from CPU to GPU?

I have wondered for quite some time how CPU instructions can interact with the GPU. As I understand things, the CPU has a certain set of instructions (machine code) that it understands and performs and a driver is a piece of software that…
vlind
  • 579
  • 5
  • 14
9
votes
3 answers

Why does gcc generate a memmove instead of a memcpy for copying a std::vector<>?

With gcc 5.3, both functions in the following example generate a call to memmove. Would it be inappropriate to generate a memcpy? #include int blackhole(const std::vector&); int copy_vec1(const std::vector& v1) { const…
Praxeolitic
  • 17,768
  • 12
  • 57
  • 109
9
votes
1 answer

Using ".intel_syntax noprefix" how can I get memory address of a label?

I'm learning how to create real mode programs assembled and linked with: GCC Assembler version 2.25 Binutils version 2.25 GCC version 5.2.0 I use Intel syntax without prefixes specified with .intel_syntax noprefix I want to load the address of a…
TheDome
  • 172
  • 1
  • 6
9
votes
1 answer

gcc - writing and executing code in the bss - setting the permission flags

I am generating x86-64 code at runtime in a C program on a linux system (centos 5.4 to be exact). I generate my bytecodes into a global array as shown below char program[1024 * 1024] __attribute__((aligned (16))); and then call into it via a…
auscoder
  • 93
  • 4
9
votes
2 answers

writing functions in assembler

I am writing code in assembler (nasm) and I want to include functions, at the moment I have function0: code jmp return0 the function is called with a jump to function0 with the return linking to a label below where the function is called, however…
PStag
  • 241
  • 1
  • 4
  • 6
9
votes
1 answer

How can C code be run on different processors?

As I understand it, C code is compiled to machine (assembly) code on someone’s machine, and it becomes an exe file that can be run on lots of different processors (machines). But since different processors have their own unique assembly code how can…
Melkor
  • 719
  • 1
  • 11
  • 27
9
votes
1 answer

Using Multiply Accumulate Instruction Inline Assembly in C++

I am implementing a FIR filter on an ARM9 processor and am trying to use the SMLAL instruction. Initially I had the following filter implemented and it worked perfectly, except this method uses too much processing power to be used in our…
John C
  • 111
  • 1
  • 6
9
votes
2 answers

Creating a bootable ISO image with custom bootloader

I am trying to convert a bootloader I wrote in Assembly Language to an ISO image file. The following is the code from MikeOS bootloader. Here is my bootloader code: BITS 16 start: mov ax, 07C0h ; Set up 4K stack space after this…
9
votes
5 answers

Writing an assembler , need help

I'm writing an 8086 assembler for a college project . I've gone through some material on compiler design on the internet and am reading the 'dragon book' of compilers . But the problem is I couldn't find much about the assembling (generating object…
abc def foo bar
  • 2,134
  • 5
  • 26
  • 41
1 2 3
99
100