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

pop Instruction not supported in 64-bit mode using NASM?

I'm working on a more indepth hello world using NASM following this tutorial (section 4). This tutorial essentially teaches you how to handle command line input. This is the snippet of the code in question: section .text global…
ahodder
  • 11,353
  • 14
  • 71
  • 114
21
votes
1 answer

How many bytes do RESB, RESW, RESD, RESQ allocate in NASM?

DB allocates in chunks of 1 byte. DW allocates in chunks of 2 bytes. DD allocates in chunks of 4 bytes. DQ allocates in chunks of 8 bytes. So I assume that: RESB 1 allocates 1 byte. RESW 1 allocates 2 bytes. RESD 1 allocates 4 bytes. RESQ 1…
user8240761
  • 975
  • 1
  • 10
  • 15
20
votes
2 answers

execute binary machine code from C

following this instructions I have managed to produce only 528 bytes in size a.out (when gcc main.c gave me 8539 bytes big file initially). main.c was: int main(int argc, char** argv) { return 42; } but I have built a.out from this assembly…
4pie0
  • 29,204
  • 9
  • 82
  • 118
19
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
  • 2,049
  • 3
  • 20
  • 27
19
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
  • 4,766
  • 3
  • 32
  • 45
19
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
  • 349
  • 1
  • 5
  • 13
18
votes
2 answers

How to install NASM in windows 10?

I'm trying to learn assembly and want to download NASM I use Windows 10,is it possible to install NASM without using DosBox or VM ?? because I saw someone using CodeBlocks with NASM to code in assembly..
Hajar Alhalabi
  • 303
  • 1
  • 2
  • 9
18
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
  • 189
  • 1
  • 1
  • 8
18
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,954
  • 4
  • 18
  • 28
17
votes
3 answers

How to generate assembly code with gcc that can be compiled with nasm

I am trying to learn assembly language as a hobby and I frequently use gcc -S to produce assembly output. This is pretty much straightforward, but I fail to compile the assembly output. I was just curious whether this can be done at all. I tried…
Alexander Cska
  • 738
  • 1
  • 7
  • 29
17
votes
1 answer

Boot loader doesn't jump to kernel code

I'm writing small operation system - for practice. I started with bootloader. I want to create small command system that runs in 16 bit real mode (for now). I've created bootloader that resets drive, then loads sector after bootloader. The problem…
vakus
  • 732
  • 1
  • 10
  • 24
16
votes
2 answers

x86 NASM 'org' directive meaning

I am following this tutorial as a first foray into bootloader/OS development for x86 using NASM: http://joelgompert.com/OS/TableOfContents.htm And I'm on Lesson 4, which is making my bootloader print the "Hello, world" string. I'm not understanding…
tdenniston
  • 3,389
  • 2
  • 21
  • 29
16
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
  • 181
  • 1
  • 1
  • 6
16
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
  • 7,757
  • 14
  • 81
  • 175
16
votes
2 answers

The new line characted in the string constant isn't being recognized by nasm

I'm writing a 'Hello world' program using Assembler. I've declared 2 string constants with the new line character \n at the end of each string: section .data str1: db "abcd\n" str2: db "efgh\n" section .text global _start _start: …
Igor
  • 477
  • 5
  • 13