Questions tagged [nasm]

NASM is the Netwide Assembler, an open-source x86/x64 assembler. It aims at being portable, modular and at having a simple syntax.

NASM is the Netwide Assembler, an open-source x86/x64 assembler. It aims at being portable, modular and at having a simpler syntax than the most commonly used open-source assembler gas. It supports a whole range of output formats (including ELF, PE/COFF), plain binary (a.out) and supports Intel 64, 32, 16 and 8 bit syntaxes.

For x86 assembly info in general, see the many links to reference manuals/docs, optimization/performance guides, tools, and debugging tips in the x86 tag wiki

See also:

  • The NASM homepage

  • The NASM manual

  • An older version of the NASM Appendix A that has text descriptions with every instruction entry, along with the CPU they were introduced in (8086, 186, 386, etc.) But it only includes MMX and older; the current version of the appendix stripped the text because SSE2/AVX/etc. have so many instructions.

  • https://yasm.tortall.net/ YASM is a NASM-compatible assembler with some nice features (e.g. long NOPs by default), but development has stalled and it doesn't support AVX512.

  • x264 has a very large set of NASM macros that attempt to abstract the calling conventions of x86_32, win64, linux64, and also do CPU feature-level checking. (e.g. to declare a function/block as SSSE3, and catch accidental usage of an SSE4.1 instruction).

    It is very intrusive and makes your source code look significantly different from normal x86 asm (macros for register names). It's licensed separately (ISC, not GPL) so it can be used in other projects.

    One copy of it can be found in the libvpx (VP8/9 video codec) source tree. x264 itself also has a copy, and see those projects for DSP functions using it.

5046 questions
15
votes
1 answer

x86 ASM Linux - Using the .bss Section

I hope these questions is rather simple: (NASM Compiler, Linux, x86 Intel Syntax) PART 1: I am trying to figure out how to use the .bss section of an Assembly program to find a way to store values, like a value from an operation (+ - * /), to an…
nmagerko
  • 6,586
  • 12
  • 46
  • 71
15
votes
2 answers

Use label in assembly from C

I simply need a way to load the address of a label e.g. MyLabel: in e.g. 'src.asm' into a variable in e.g. 'src.c'. (These files will be linked together) I am using gcc and nasm to assemble these files. How can I load the label address?
Kendall Frey
  • 43,130
  • 20
  • 110
  • 148
15
votes
2 answers

Can't call C standard library function on 64-bit Linux from assembly (yasm) code

I have a function foo written in assembly and compiled with yasm and GCC on Linux (Ubuntu) 64-bit. It simply prints a message to stdout using puts(), here is how it looks: bits 64 extern puts global foo section .data message: db 'foo() called',…
szx
  • 6,433
  • 6
  • 46
  • 67
15
votes
2 answers

ASM x86_64 AVX: xmm and ymm registers differences

What are the differences between xmm and ymm registers? I thought that xmm is for SSE, and ymm is for AVX, but I wrote some code: vmovups ymm1, [r9] vcvtss2si rcx, ymm1 and it gives me: error: invalid combination of opcode and…
SciArt
  • 351
  • 1
  • 2
  • 8
15
votes
2 answers

Addressing Modes in Assembly Language (IA-32 NASM)

As the web-resources on this is sparse, I will, for the benefit of future searches, begin by listing the address modes for IA-32 Assembly Language (NASM) and then follow up with a quick question. Register addressing mov eax, ebx: Copies what is in…
Magnus
  • 6,791
  • 8
  • 53
  • 84
14
votes
2 answers

Switching to User-mode using iret

I am writing a small OS that will execute some code in user mode (privilege level 3). From that user level code, I want to call an interrupt back to the OS that prints a message. Right now I don't really care how my interrupt handler takes…
Alex Nichol
  • 7,512
  • 4
  • 32
  • 30
14
votes
2 answers

Does [ebp*2] reference DS or SS segment?

IDM says the memory op uses SS segment if EBP is used as base register. As a result, [ebp + esi] and [esi + ebp] references SS and DS segments, respectively. See NASM's doc: 3.3 Effective Address. In the above same section, NASM mentioned how to…
wildpie
  • 143
  • 4
14
votes
0 answers

Is there a simple DWARF CFI represenation for functions that set up a conventional frame pointer?

I'm programming in a mix of C, C++ and assembly and I'd like to get reliable backtraces from any part of the code. This mostly works fine for the C and C++ code since I can generate debugging info with -g, which for modern x86 compilers and…
BeeOnRope
  • 60,350
  • 16
  • 207
  • 386
14
votes
2 answers

writing functions in assembler

I am writing code in assembler (nasm) and I want to include functions, at the moment I have function0: code jmp return0 the function is called with a jump to function0 with the return linking to a label below where the function is called, however…
PStag
  • 291
  • 1
  • 4
  • 7
14
votes
3 answers

How to compile using nasm on MacOSX

I am trying to compile and link my first program on Assembler. I try to compile the following code: ; %include "stud_io.inc" global _main section .text _main: xor eax, eax again: ; PRINT "Hello" ; PUTCHAR 10 inc eax …
Ilya Lavrenov
  • 347
  • 1
  • 2
  • 7
14
votes
2 answers

Hello world using nasm in windows assembly

I'm using nasm to compile the following assembly. However the code crashes in the console under Windows. C:\>nasm -f win32 test.asm -o test.o C:\>ld test.o -o test.exe section .data msg db 'Hello world!', 0AH len equ $-msg section…
gotnull
  • 26,454
  • 22
  • 137
  • 203
13
votes
4 answers

Can't link assembly file in Mac OS X using ld

I'm trying to run a basic assembly file using 64 Bit Mac OS X Lion, using nasm and ld which are installed by default with Xcode. I've written an assembly file, which prints a character, and I got it to build using nasm. nasm -f elf -o program.o…
Jack Greenhill
  • 10,240
  • 12
  • 38
  • 70
13
votes
3 answers

Return value of a C function to ASM

I'm trying to call a function from within ASM. I know how to call it, but i'm having trouble finding how to get the return value of this function. An example follows: C code: int dummy() { return 5; } (N)ASM code: dummyFunction: …
Juan Pablo
  • 593
  • 1
  • 6
  • 12
13
votes
2 answers

How to link the C Runtime Library with 'ld'?

I'm learning assembly with NASM for a class I have in college. I would like to link the C Runtime Library with ld, but I just can't seem to wrap my head around it. I have a 64 bit machine with Linux Mint installed. The reason I'm confused is that --…
mrDudePerson
  • 327
  • 3
  • 12
12
votes
1 answer

NASM is pure assembly, but MASM is high level Assembly?

I'm learning assembly, motivation being able to reverse engineer. I'm trying to find the assembler I should begin with, so that I can then find tutorials and start writing some assembly. I came to know that MASM has a lot of built in constructs, so…
questions
  • 2,337
  • 4
  • 24
  • 39