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

Does usage of a pointer cancel the "register" property of the associated variable?

In C, does usage of a pointer cancel the "register" property of the associated variable? #include #include int main() { register int clk=0; //maybe register maybe not int *adr=&clk; //not a register now? i have…
huseyin tugrul buyukisik
  • 11,469
  • 4
  • 45
  • 97
11
votes
5 answers

Fast intersection of two sorted integer arrays

I need to find the intersection of two sorted integer arrays and do it very fast. Right now, I am using the following code: int i = 0, j = 0; while (i < arr1.Count && j < arr2.Count) { if (arr1[i] < arr2[j]) { i++; } else …
Neir0
  • 12,849
  • 28
  • 83
  • 139
11
votes
3 answers

how convert two bytes into one 16-bit number?

I understand that 1 byte will hold a number from 0-255. And that a 16-bit number is between 0-65535. If I'm trying to represent a 16-bit number using two separate 8-bit registers...how do I do that? How does the math work? Thanks!
Jay Kim
  • 843
  • 4
  • 12
  • 28
11
votes
6 answers

Why calls when jmps would suffice?

I have two files: #include static inline void print0() { printf("Zero"); } static inline void print1() { printf("One"); } static inline void print2() { printf("Two"); } static inline void print3() { printf("Three"); } static inline void…
skink
  • 5,133
  • 6
  • 37
  • 58
11
votes
2 answers

What is the difference between RCR and ROR?

I understand the from the terms that RCR would rotate the bit from the right to left, taking the bit from the carry while ROR will rotate the bit from right to left, taking the bit from the right but is that the only difference between them? If this…
Foo
  • 309
  • 2
  • 5
  • 10
11
votes
1 answer

Porting compiler from x86 Assembly to LLVM

So recently, in an attempt to hone my assembly skills, I wrote a VERY simple compiler for a toy language in C++. It runs single pass, and directly emits code during the parsing phase to several string streams, each representing a section of the code…
Samuel Breese
  • 694
  • 10
  • 26
10
votes
1 answer

x86 assembly multiply and divide instruction operands, 16-bit and higher

I'm rather confused about how the multiply and divide operations work in x86 assembly. For example, the code below doesn't seem too difficult since deals with 8-bit. 8-Bit Multiplication: ; User Input: ; [num1], 20 ; [num2] , 15 mov ax, [num1] …
StartingGroovy
  • 2,802
  • 9
  • 47
  • 66
10
votes
4 answers

Looking for a half float or quarter float library

I need to store values in a range of about -10000 to 10000. At the range borders, the precision needed is not very high (maybe about 64, I will see how it fits), around zero the precision needs to be 1 or better. Unfortunately space is very limited,…
Gunther Piez
  • 29,760
  • 6
  • 71
  • 103
10
votes
2 answers

How is the I/O Address Space mapped to devices?

I hope the question is phrased well enough for someone to understand. I understand that main memory (RAM) and for Port I/O driven I/O, it has it's own Address Space that Instructions like IN, OUT use. If one were to write a real-mode assembler…
Ryan Warren
  • 115
  • 1
  • 7
10
votes
11 answers

How can I multiply two 64-bit numbers using x86 assembly language?

How would I go about... multiplying two 64-bit numbers multiplying two 16-digit hexadecimal numbers ...using Assembly Language. I'm only allowed to use registers %eax, %ebx, %ecx, %edx, and the stack. EDIT: Oh, I'm using ATT Syntax on the…
Kawarazu
  • 121
  • 1
  • 1
  • 8
10
votes
1 answer

Delphi assembler constant 'eof'

There seems to be an undocumented constant eof in asm block context. This was tested using Delphi 7. program TestEof; {$APPTYPE CONSOLE} var example : Integer; begin asm mov example, eof end; writeln(example); readln; end. This prints…
Egon
  • 1,705
  • 18
  • 32
10
votes
2 answers

How to link a C object file with a Assembly Language object file?

I am having trouble linking 2 object files one of which was generated from an Assembly Language Source File and another that was generated from a C Source file. C source code: //main2.c extern int strlength(char *); int main(){ char * test =…
Hudson Worden
  • 2,263
  • 8
  • 30
  • 45
10
votes
5 answers

8086/88 emulator for ubuntu

I need to emulate assembly for 8086 program in Ubuntu. I searched repository and I found 8085 emulator which is not similar to 8086. Is there any 8086/88 assembly emulator for ubuntu?
Moein Hosseini
  • 4,309
  • 15
  • 68
  • 106
10
votes
2 answers

Stack eip overflow x86 vs x86_64 easy C code

Let me skip introduction and jump to the good part. I am reading 'Ethical Hackers Handbook' and trying some example code (around p175). ----------------------------------------------------------------------------------------- Goal : overflow the EIP…
Jorn De Pril
  • 191
  • 1
  • 1
  • 7
10
votes
2 answers

what does "outb" in AT&T asm mean?

I am reading some code of Linux. The keyboard.S has something like outb %al,$0x61 and inb $0x61,%al I think the pending 'b' means 'byte', but i still cannot find what these instructions mean.
onemach
  • 4,265
  • 6
  • 34
  • 52