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
1 answer

symbol table and relocation table in object file

From what I understand, instructions and data in an object file all have addresses. First data item start at address 0 and first instruction also start at address 0. The relocation table contains information about instructions that need to be…
Carlj901
  • 1,329
  • 4
  • 24
  • 39
11
votes
2 answers

How do I decompile a .hex file into C++ for Arduino?

I have a hex file that is to be flashed onto an Atmel chip running on an Arduino device. There are certain aspects of this file that I would like to modify before putting it onto my Arduino, but I don't have the source C++; just the hex file. Is…
Matt Cashatt
  • 23,490
  • 28
  • 78
  • 111
11
votes
1 answer

Why don't GCC and Clang use cvtss2sd [memory]?

I'm trying to optimize some code that's supposed to read single precision floats from memory and perform arithmetic on them in double precision. This is becoming a significant performance bottleneck, as the code that stores data in memory as single…
dsimcha
  • 67,514
  • 53
  • 213
  • 334
11
votes
1 answer

Running code on different processor (x86 assembly)

In real mode on x86, what instructions would need to be used to run the code on a different processor, in a multiprocessor system? (I'm writing some pre-boot code in assembler that needs to set certain CPU registers, and do this on every CPU in the…
Rhys Bradshaw
  • 113
  • 1
  • 4
11
votes
1 answer

Why does switching from AT&T to Intel syntax make this tutorial segfault using GAS?

I'm working through some of the tutorials on http://www.ibm.com/developerworks/linux/library/l-gas-nasm/index.html to familiarize myself with x86/x64. This tutorial code compiles and runs without a hiccup using the provided code, which uses AT&T…
Alex
  • 599
  • 1
  • 4
  • 16
11
votes
1 answer

Debugging disassembled libraries with gdb

in Linux and Mac OS X I can use stepi and nexti to debug an application without debugging information. On Mac OS X gdb shows the functions that are called inside the library, although sometimes advancing several assembler instructions in each stepi…
Freeman
  • 5,810
  • 3
  • 47
  • 48
11
votes
3 answers

How to make the GNU Assembler use a slash / for comments?

This is indeed a stupid idiosyncrasy of mine, but I can't stand the way GNU AS uses to insert a comment. I am too accustomed to the Sun way (the same used in most UNIX assemblers), that uses a simple slash "/" to comment out the code till the end…
mghis
  • 517
  • 1
  • 5
  • 14
11
votes
5 answers

How to load a kernel from disk with BIOS int 13h in NASM assembly?

I've been stuck with this for weeks now and have no idea where I'm going wrong because NASM hasn't given me any errors. The code is pretty self explanatory because of the comments. this is the code that is loaded from the BIOS …
user188025
11
votes
2 answers

Buffer overflow appeared before it is expected

I'm trying to take a control over a stack overflow. First, here is an example of C code I compiled on an x32 VM Linux (gcc -fno-stack-protector -ggdb -o first first.c), #include "stdio.h" int CanNeverExecute() { printf("I can never…
Artur Korobeynyk
  • 955
  • 1
  • 9
  • 24
11
votes
1 answer

Int to Float to Int conversion precision loss

Recently, I wrote a small program and compiled it using mingw32(on Windows8) of 2 different versions. Surprisingly, I got two different reusults. I tried disassmbling it but found nothing special. Could anyone help me? Thank you. the exe…
Zhe Chen
  • 2,918
  • 4
  • 23
  • 39
11
votes
1 answer

How to pass functions parameters in a register with gcc asm keyword

In gcc you can declare that a local variable should be put in a register using the following syntax. register int arg asm("eax"); In some old code I found on the internet this syntax was used to declare that the parameters to a function should be…
j.karlsson
  • 618
  • 4
  • 14
11
votes
2 answers

asm in C "too many memory references for `mov'"

I've seen the post about the same error but i'm still get error : too many memory references for `mov' junk `hCPUIDmov buffer' after expression ... here's the code (mingw compiler / C::B) : #include iostream using namespace std; …
user2101247
  • 149
  • 1
  • 1
  • 5
11
votes
5 answers

Near and Far JMPs

I am doing Linux assembly and I understand that is has a flat memory model. What I am confused about is NEAR and FAR JMPs. NEAR is in the same segment while FAR is another segment. From what I understand there are no segments in linux virtual…
ST-User
  • 395
  • 2
  • 3
  • 12
11
votes
2 answers

Linux assembler error "impossible constraint in ‘asm’"

I'm starting with assembler under Linux. I have saved the following code as testasm.c and compiled it with: gcc testasm.c -otestasm The compiler replies: "impossible constraint in ‘asm’". #include int main(void) { int foo=10,bar=15; …
slashmais
  • 7,069
  • 9
  • 54
  • 80
11
votes
9 answers

Programming Environment for a Motorola 68000 in Linux

Greetings all, I am taking a Structure and Application of Microcomputers course this semester and we're programming with the Motorola 68000 series CPU/board. The course syllabus suggests running something like Easy68K or Teesside Motorola 68000…
Nick Presta
  • 28,134
  • 6
  • 57
  • 76