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

Near and Far JMPs

I am doing Linux assembly and I understand that is has a flat memory model. What I am confused about is NEAR and FAR JMPs. NEAR is in the same segment while FAR is another segment. From what I understand there are no segments in linux virtual…
ST-User
  • 395
  • 2
  • 3
  • 12
11
votes
2 answers

GDB complains No Source Available

I'm running on Ubuntu 12.10 64bit. I am trying to debug a simple assembly program in GDB. However GDB's gui mode (-tui) seems unable to find the source code of my assembly file. I've rebuilt the project in the currently directory and searched google…
Irresponsible Newb
  • 603
  • 2
  • 7
  • 15
11
votes
6 answers

gas vs. nasm: which assembler produces the best code?

Both tools translate assembly instructions directly into machine code, but is it possible to determine which one produces the fastest and cleanest code?
user157000
11
votes
3 answers

gdb + nasm debug info not being created

I am trying to debug a small .asm file that I wrote in Ubuntu. I am however running into an issue where my symbol table is not being loaded and was looking for some help. I am compiling my program as follows. nasm -f elf -g -F dwarf bs.asm gcc -m32…
cpowel2
  • 605
  • 1
  • 11
  • 20
10
votes
2 answers

Outputting integers in assembly on Linux

This needs to be done in pure assembly (ie. no libraries or calls to C). I understand the essence of the problem: one needs to divide the integer by 10, convert the one-digit remainder to ASCII, output that and then repeat the process with the…
David Chouinard
  • 6,466
  • 8
  • 43
  • 61
10
votes
2 answers

Linux default behavior of executable .data section changed between 5.4 and 5.9?

Story Case 1 I accidentally wrote my Assembly code in the .data section. I compiled it and executed it. The program ran normally under Linux 5.4.0-53-generic even though I didn't specify a flag like execstack. Case 2: After that, I executed the…
Ammar Faizi
  • 1,393
  • 2
  • 11
  • 26
10
votes
4 answers

How do I compile DOS programs on Debian?

For my assembly language class, we're writing DOS programs using DPMI. Unfortunately, I don't have access to a 32-bit windows machine all the time. I do have a Debian virtual machine installed on just about every computer I do use. I've got both…
Jason Baker
  • 192,085
  • 135
  • 376
  • 510
10
votes
4 answers

Unresolved external symbol printf in Windows x64 Assembly Programming with NASM

I've been trying to learn assembly lately, and came across this post. The author used NASM and Microsoft linker to set up the assembly working environment. I followed the same steps and installed NASM. Then I started to compile the hello world…
jtxkopt
  • 916
  • 1
  • 8
  • 21
10
votes
1 answer

what would be the benefit of moving a register to itself in x86-64

I'm doing a project in x86-64 NASM and came across the instruction: mov rdi, rdi in the output of a compiler my professor wrote. I have searched all over but can't find mention of why this would be needed. Does it affect the flags or is it…
nrmad
  • 422
  • 9
  • 19
10
votes
1 answer

glibc scanf Segmentation faults when called from a function that doesn't align RSP

When compiling below code: global main extern printf, scanf section .data msg: db "Enter a number: ",10,0 format:db "%d",0 section .bss number resb 4 section .text main: mov rdi, msg mov al, 0 call printf mov rsi, number …
user3057544
  • 807
  • 9
  • 22
10
votes
1 answer

Symbol name conflicts with new register names in new NASM versions?

Imagine you wrote this 10 years ago (before Intel MPX and the bnd0..bnd3 registers were even on a roadmap): section .data ; define some globals which are part of an ABI so you can't just rename them global bnd0 ; MPX bound register name…
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
10
votes
2 answers

Shadow space example

EDIT: I have accepted an answer below and also added my own with my final revision of the code. Hopefully it shows people actual examples of Shadow Space allocation rather than more words. EDIT 2: I also managed to find a link to a calling…
Simon Whitehead
  • 63,300
  • 9
  • 114
  • 138
10
votes
2 answers

Why use RIP-relative addressing in NASM?

I have an assembly hello world program for Mac OS X that looks like this: global _main section .text _main: mov rax, 0x2000004 mov rdi, 1 lea rsi, [rel msg] mov rdx, msg.len syscall mov rax, 0x2000001 mov rdi, 0 …
Jerfov2
  • 5,264
  • 5
  • 30
  • 52
10
votes
3 answers

Why is 1.0f in C code represented as 1065353216 in the generated assembly?

In C I have this code block: if(x==1){ a[j][i]=1; } else{ a[j][i]=0; } a is a matrix of float values, if I try to see the compiled assembly of this code in nasm syntax the line a[j][i]=0; assignment, was coded in this way dword [rsi+rdi],…
AndreaF
  • 11,975
  • 27
  • 102
  • 168
10
votes
2 answers

How to generate gdb symbol file with nasm?

I'm working on a toy bootloader/kernel written in assembly and run on the qemu emulator. I can run qemu with -s -S option and debug with gdb using remote target, but I don't have any debug symbols loaded with gdb. How can I generate a symbol file…
brianmearns
  • 9,581
  • 10
  • 52
  • 79