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 asm 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's 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.

4372 questions
17
votes
5 answers

How to use scanf in NASM?

I'm trying to figure out how to use scanf to get user input. I know to use printf: all I have to do is push the data I want to write on the screen into the stack like this: global _main extern _printf extern _scanf section .data msg db "Hi",…
user1432532
  • 329
  • 1
  • 5
  • 13
16
votes
3 answers

nasm - Can't link object file with ld on macOS Mojave

I'm trying to assemble a simple Hello World, which worked fine in the previous macOS version: global start section .text start: mov rax, 0x02000004 mov rdi, 1 mov rsi, msg mov rdx, 13 …
Verloren
  • 599
  • 3
  • 17
15
votes
1 answer

What's the difference between %define and equ in NASM?

Code: %define x 0x03 x equ 0x03 What's the difference between them?
sam
  • 1,683
  • 3
  • 17
  • 25
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
  • 39,334
  • 18
  • 104
  • 142
15
votes
2 answers

Nasm - Symbol `printf' causes overflow in R_X86_64_PC32 relocation

I am trying to create a simple program in nasm that should display the letter a. however, It is giving me a Segfault and saying this: ./a.out: Symbol `printf' causes overflow in R_X86_64_PC32 relocation Segmentation fault (core dumped) Basically,…
Unknown
  • 171
  • 1
  • 6
15
votes
1 answer

64-bit mode does not support 32-bit PUSH and POP instructions

NASM returns an error like: "instruction not supported in 64-bit mode" (Or with YASM, invalid size for operand 1) The subject instructions are pop ecx and push ecx. What can I use instead of them or is there an other way to fix this issue?
Konko
  • 159
  • 1
  • 1
  • 7
15
votes
3 answers

How can I pass parameters in assembler x86 function call?

Look at this assembler code. It is designed for 32 bits x86 and will be compiled by nasm ... my_function: pop %eax ... ret main: push 0x08 call my_function I have learned a long time ago that we can…
Bob5421
  • 6,002
  • 10
  • 44
  • 120
15
votes
2 answers

Possibility of loading/executing ELF files on OSX

I'm just curious as to the possibility of loading and executing elf files on OSX. I know the standard executable format is MACHO, but NASM is unable to generate debug information for MACHO objects (and I am required to use NASM). I imagine its a…
Daniel Brotherston
  • 1,328
  • 1
  • 13
  • 27
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,382
  • 4
  • 29
  • 28
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
1 answer

How does $ work in NASM, exactly?

message db "Enter a digit ", 0xA,0xD Length equ $- message Is it used to get the length of a string? How does it work internally?
Naveen prakash
  • 309
  • 4
  • 9
14
votes
1 answer

How do I add contents of text file as a section in an ELF file?

I have a NASM assembly file that I am assembling and linking (on Intel-64 Linux). There is a text file, and I want the contents of the text file to appear in the resulting binary (as a string, basically). The binary is an ELF executable. My plan is…
David Jones
  • 3,640
  • 2
  • 28
  • 42
14
votes
7 answers

load warning: cannot find entry symbol _start

I'm learning assembly programming. Below is the simple program that prints 'Hello, World!'. While the program runs perfectly, I'm getting the warning message while loading ld: warning: cannot find entry symbol _start; defaulting to…
Atinesh
  • 1,392
  • 5
  • 24
  • 46
14
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
  • 4,901
  • 5
  • 31
  • 62
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…
fulvio
  • 24,168
  • 20
  • 122
  • 198