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

vectorized strlen getting away with reading unallocated memory

While studying OSX 10.9.4's implementation of strlen, I notice that it always compares a chunk of 16-bytes and skips ahead to the following 16-bytes until it encounters a '\0'. The relevant part: 3de0: 48 83 c7 10 add …
Aktau
  • 1,847
  • 21
  • 30
11
votes
3 answers

How can I multiply 64 bit operands and get 128 bit result portably?

For x64 I can use this: { uint64_t hi, lo; // hi,lo = 64bit x 64bit multiply of c[0] and b[0] __asm__("mulq %3\n\t" : "=d" (hi), "=a" (lo) : "%a" (c[0]), "rm" (b[0]) : "cc" ); a[0] += hi; a[1] += lo; } But I'd like…
user3360486
  • 153
  • 1
  • 5
11
votes
2 answers

make: Circular dependency dropped

I've already searched a long time on stackoverflow and other make manuals, websites but cannot find any trailing whitespace or miss usage in make functions. Can you help me solve this warning message ? make: Circular main.asm.o <- main.asm…
Amaury Brisou
  • 344
  • 1
  • 4
  • 10
11
votes
1 answer

What does the /4 mean in FF /4?

One site that I commonly refer to for x86 documentation has a few instruction codes with a slash and a number. For instance, jmp near absolute indirect gives FF /4, whereas jmp far absolute indirect gives FF /5. What do the /4 and /5 mean? To run a…
Qix - MONICA WAS MISTREATED
  • 14,451
  • 16
  • 82
  • 145
11
votes
5 answers

Force visual studio to always 'rebuild all' when debugging

Edit: Basically what I need is for visual studio to always rebuild all when I hit debug. I'm currently using visual studio to compile my assembly programs, using MASM and in general it's working fine. However I've run into an annoying issue: If I…
Cam
  • 14,930
  • 16
  • 77
  • 128
11
votes
5 answers

Integer absolute value in MIPS?

Do you have any simple ways to make a value in a register in MIPS as an absolute value?
aherlambang
  • 14,290
  • 50
  • 150
  • 253
11
votes
3 answers

masm division overflow

I'm trying divide two numbers in assembly. I'm working out of the Irvine assembly for intel computers book and I can't make division work for the life of me. Here's my code .code main PROC call division exit main ENDP division PROC mov…
11
votes
1 answer

x86_64 Linux syscall arguments

I'm learning x86_64 assembly on Linux and I've run into some conflicting information that I was hoping could get cleared up. On one hand, I've read that for syscall arguments, you would use registers in the order of rdi, rsi, rdx, and so on. But on…
Chiggins
  • 8,197
  • 22
  • 56
  • 81
11
votes
1 answer

How much does function alignment actually matter on modern processors?

When I compile C code with a recent compiler on an amd64 or x86 system, functions are aligned to a multiple of 16 bytes. How much does this alignment actually matter on modern processors? Is there a huge performance penalty associated with calling…
fuz
  • 88,405
  • 25
  • 200
  • 352
11
votes
1 answer

ARM NEON: How to implement a 256bytes Look Up table

I am porting some code I wrote to NEON using inline assembly. One of the things I need is to convert byte values ranging [0..128] to other byte values in a table which take the full range [0..255] The table is short but the math behind this is not…
Jordi C.
  • 339
  • 2
  • 12
11
votes
1 answer

What does JS do in Assembly x86?

cmp %al, %cl js x I'm confused on what the js (jump on sign) is doing. Is it saying that if al is positive and cl is negative vice versa then jump? Also, what happens if %cl is 0?
user3128376
  • 974
  • 6
  • 17
  • 40
11
votes
1 answer

How To Build a Hello World For Nintendo 64?

I'm reading MIPS Assembly Language Programming, but now I want to build a simple "game" for Nintendo 64. I want to print a Hello, World to the screen, but someone can help with this. As I don't have nothing to start. I've choose for Nintendo 64…
Nathan Campos
  • 28,769
  • 59
  • 194
  • 300
11
votes
1 answer

X86 instructions to power off computer in real mode?

Is there any sequence of x86 instructions in real mode that will power off (not reboot) the machine? I have an old computer with MS-DOS still on it and I'm curious about it. This question is specifically about real mode, not protected mode or…
Govind Parmar
  • 20,656
  • 7
  • 53
  • 85
11
votes
3 answers

Is it possible to run x86 assembly on a x64 operating system?

Recently I decided that it was worth getting a try on basic x86 assembly so that it would be easier to debug programs, etc, etc. So I started (about a week ago) learning x86 assembly, in that time, I upgraded my computer to 8GB ram, so obviusly my…
user252778
11
votes
1 answer

Strange behaviour of ldr [pc, #value]

I was debugging some c++ code (WinCE 6 on ARM platform), and i find some behavior strange: 4277220C mov r3, #0x93, 30 42772210 str r3, [sp] 42772214 ldr r3, [pc, #0x69C] 42772218 ldr r2,…
XAder
  • 676
  • 4
  • 12