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
3 answers

Can branch prediction cause illegal instruction?

In the following pseudo-code: if (rdtscp supported by hardware) { Invoke "rdtscp" instruction } else { Invoke "rdtsc" instruction } Let's say the CPU does not support the rdtscp instruction and so we fallback to the else statement. If CPU…
mtoossi
  • 937
  • 8
  • 14
11
votes
1 answer

Vectorizing Modular Arithmetic

I'm trying to write some reasonably fast component-wise vector addition code. I'm working with (signed, I believe) 64-bit integers. The function is void addRq (int64_t* a, const int64_t* b, const int32_t dim, const int64_t q) { for(int i = 0; i…
crockeea
  • 21,651
  • 10
  • 48
  • 101
11
votes
4 answers

How to single step ARM assembly in GDB on QEMU?

I'm trying to learn about ARM assembler programming using the GNU assembler. I've setup my PC with QEmu and have a Debian ARM-HF chroot environment. If I assemble and link my test program: .text .global _start _start: mov r0, #6 …
fred basset
  • 9,774
  • 28
  • 88
  • 138
11
votes
3 answers

Converting Int to Float or Float to Int using Bitwise operations (software floating point)

I was wondering if you could help explain the process on converting an integer to float, or a float to an integer. For my class, we are to do this using only bitwise operators, but I think a firm understanding on the casting from type to type will…
Andrew T
  • 783
  • 4
  • 11
  • 20
11
votes
1 answer

Understanding MRC on ARM7

I am new to ARM and trying to understand MRC instruction. As I understood , MRC is to read Coprocessor registers and put it into main Core register. Now Coprocessors are attached to main core and is used to control the memory subsystem of main…
Amit Singh Tomar
  • 8,380
  • 27
  • 120
  • 199
11
votes
2 answers

Running assembly in an empty virtual machine instance?

How is it possible to run assembly code in an empty virtual machine (virtualbox, vmware) instance? I want to try writing a simple bootloader. My aim is to work for a hobby operating system.
tolga
  • 2,462
  • 4
  • 31
  • 57
11
votes
1 answer

Hello World in LLVM-Assembly Language on Windows

As an experienced programmer I feel quite dumb asking such a question: Is there a step-by-step tutorial explaining how to write a "Hello World"-Program in LLVM-Assembly Language resulting in a simple "hello.exe" which can be executed on a Standard…
Kai Giebeler
  • 517
  • 6
  • 12
11
votes
5 answers

problem in understanding mul & imul instructions of Assembly language

I'm learning 80386 from PC Assembly by paul caurter mul source If the operand is byte sized, it is multiplied by the byte in the AL register and the result is stored in the 16 bits of AX. fine. If the source is 16-bit, it is multiplied…
claws
  • 52,236
  • 58
  • 146
  • 195
11
votes
2 answers

Load from a 64-bit address into other register than rax

On x64, loading from a 64-bit absolute address (that is, dereferencing a 64-bit immediate) can be done by movabs addr64, %rax However, when the destination register is any other than rax the assembler gives an error message saying operand size…
Torgny
  • 279
  • 3
  • 10
11
votes
2 answers

Waiting for a change on $D012 (C64 assembler)

I've run into a few issues while playing around with asm on an emulated C64 machine. What I want to do is to check if the key "N" on the keyboard is being pressed, then the program should wait for a change to appear on address $D012. Now what I…
user1062704
  • 438
  • 4
  • 14
11
votes
1 answer

6502 lightweight compression algorithms

I'm implementing virtual memory on dual cassette tape decks on a Commodore PET (for fun) for a Forth I'm writing. What I have so far is at http://github.com/chitselb/pettil if you're interested. I'm planning to use the PET's native 192-byte…
chitselb
  • 153
  • 5
11
votes
2 answers

GCC C++ Exception Handling Implementation

I would like to know how GCC implements exception handling for C++ programs. I couldn't find an easy-to-understand and self-explanatory article on the Web (although there are many such articles for Visual C++). All I know is that GCC's…
Nithin
  • 113
  • 1
  • 6
11
votes
1 answer

"global main" in Assembly

I came across this snippet of code: section .text global main ;must be declared for linker (gcc) and then there is a function called main after this line: main: ;tell linker entry point but i don't seem to understand what global main…
tenstar
  • 9,816
  • 9
  • 24
  • 45
11
votes
3 answers

Converting C to nasm assembly

I try to covert my c code to assembly by GCC (by typing gcc -S -masm=intel or pg.c or gcc -S prog.c) but it gives me MASM code although I need NASM one. I wonder if you could help me to convert my c to NASM assembly.
Abtin
  • 301
  • 2
  • 3
  • 7
11
votes
1 answer

What does the ".align" directive mean in x86-64 Assembly?

I notice that there's some directives used with the .align prefix followed by numerical values. I'm not sure on what this is, nor if it's even necessary to use, but I've wrote x86 Assembly and never used ".align" before. What is the basic purpose of…
Waluigi