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

Emulated ARM assembler environment?

I would like my son to learn ARM assembler, and I'm considering buying him an embedded system that he can program so he can make LEDs flash and other cool stuff that I got a kick out of as a kid. Are there any emulated or virtual "workbenches" that…
user54307
  • 91
  • 1
  • 3
9
votes
1 answer

linux kernel development

I am currently reading 'Linux Kernel Development' by Robert Love and I do not understand what this bit of assembly is doing. Basically, in each process kernel stack, there is a struct thread_info which resides at the end of the stack. Now, on the…
tbh
  • 93
  • 2
9
votes
3 answers

How do they convert Decimal to Hexadecimal so fast (in mind)?

I've observed few reverse engineers, they convert decimal to hexadecimal so fast in mind. It's simply amazing. I never got chance to ask them. Personally, I really suck it this conversion and I always use a calculator for conversion. I was wondering…
claws
  • 47,010
  • 55
  • 140
  • 185
9
votes
1 answer

Allocating variables on the stack in x86 assembly. rbp and rsp vs esp and ebp

I have recently been learning assembly, and decided to disassemble some of my own executables to study from. I've noticed online resources often reference esp and ebp, the stack and base pointer. I wrote this program: int comp(int a, int b) { …
Carson
  • 97
  • 1
  • 4
9
votes
2 answers

How to change kernal SCNKEY routine behaviour in Commodore 64

I'm trying to implement game controls using kernel routines in Commodore 64. Below code works with one exception. Each key stroke counted as single input. e.g.: There is no effect if you keep holding the button. You had to release and press again…
wizofwor
  • 877
  • 5
  • 22
9
votes
3 answers

What's the easiest way to determine if a register's value is equal to zero or not?

I'm using x86 assembly with the Irvine library. What's the easiest way to check if a register value is equal to zero or not? I used cmp instruction but i'm searching for alternative way. This is my code using cmp instruction and the register is ebx…
Zeyad Etman
  • 1,374
  • 3
  • 18
  • 31
9
votes
3 answers

Assembly Analysis Tools

Does anyone have any suggestions for assembly file analysis tools? I'm attempting to analyze ARM/Thumb-2 ASM files generated by LLVM (or alternatively GCC) when passed the -S option. I'm particularly interested in instruction statistics at the basic…
Zeke
  • 1,744
  • 15
  • 32
9
votes
2 answers

Why does ICC unroll this loop in this way and use lea for arithmetic?

Looking at the ICC 17 generated code for iterating over a std::unordered_map<> (using https://godbolt.org) left me very confused. I distilled down the example to this: long count(void** x) { long i = 0; while (*x) { ++i; x =…
9
votes
1 answer

MIPS: Why do we need load byte when we already have load word?

In the RISC MIPS instruction set, we have load byte (lbu), load half word (lhu) and load word (lw) instructions. It appears to me that everything lbu and lhu can do can be achieved with lw. So why did the MIPS designers introduce lbu and lhu? In…
flow2k
  • 2,619
  • 24
  • 40
9
votes
5 answers

Converting assembly code to C code

What process can be used to convert assembly code into equivalent C code? What kind of tools can be leveraged for higher result accuracy?
Brian
  • 109
  • 1
  • 1
  • 8
9
votes
3 answers

Triple fault in home grown kernel

I am trying to write a kernel, mostly for entertainment purposes, and I am running into a problem were I believe it is triple faulting. Everything worked before I attempted to enable paging. The code that is breaking is this: void…
bschaffer13
  • 200
  • 1
  • 8
9
votes
3 answers

What is my compiler doing? (optimizing memcpy)

I'm compiling a bit of code using the following settings in VC++2010: /O2 /Ob2 /Oi /Ot However I'm having some trouble understanding some parts of the assembly generated, I have put some questions in the code as comments. Also, what prefetching…
ronag
  • 43,567
  • 23
  • 113
  • 204
9
votes
1 answer

Responsibility of stack alignment in 32-bit x86 assembly

I am trying to get a clear picture of who (caller or callee) is reponsible of stack alignment. The case for 64-bit assembly is rather clear, that it is by caller. Referring to System V AMD64 ABI, section 3.2.2 The Stack Frame: The end of the input…
Grzegorz Szpetkowski
  • 35,042
  • 4
  • 82
  • 127
9
votes
2 answers

Switch Case Assembly Language

I am looking at the assembly language code of a switch statement. I understand how the code works and what the cases are. My question is how do I decide on the case names? Below is the assembly language code, which will be followed with my…
Catie
  • 535
  • 5
  • 11
  • 21
9
votes
1 answer

How to get linux ebpf assembly?

I want to learn linux ebpf vm, if I write a ebpf program test.c, used llvm: clang -O2 -target bpf -o test.o test.c. How to get the ebpf assembly like tcpdump -d in classic bpf, thanks.
Junli Ou
  • 91
  • 1
  • 4
1 2 3
99
100