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
10
votes
1 answer

How to read a NASM Assembly program .lst listing file

I wrote a NASM program and created a listing file from it using nasm -f elf -l rs.lst rs.asm. The program, which works perfectly, takes in a key input value, and outputs whether the value is a control key or printable key, and if it is a number,…
CodyBugstein
  • 21,984
  • 61
  • 207
  • 363
9
votes
3 answers

Cannot find crtn.o, linking 32 bit code on 64 bit system

I'm attempting to assemble some 32-bit code using NASM and GCC on a 64-bit system. I use the following two commands nasm -f elf32 -g -F stabs coc.asm gcc -m32 -o coc coc.o NASM appears to do fine, but LD complains: /usr/bin/ld: cannot find crt1.o:…
user606547
9
votes
2 answers

How would I write a bootloader to load a c kernel?

I am learning NASM as I write bootloaders. So far I have a hello world bootloader. I want to know how to link a c program to it and have the bootloader load it into memory and start executing it's entry point function. I need NASM code as I am a…
user701329
  • 127
  • 2
  • 7
9
votes
2 answers

Help Writing TSR Program(s) in NASM Assembly for DOS

I've been trying to write TSR (Terminate-Stay-Resident) programs (in general) in Assembly (16-bit) for MS-DOS. I've read through a Wikipedia page on TSR and also a page on using it specifically in DOS (but it seems to be teaching it in C and not…
Alex Ozer
  • 459
  • 5
  • 14
9
votes
1 answer

Assembly language programming hints and tips

I'm having a go at writing my own "toy" OS and for the moment I'm doing it mostly in assembly (NASM) - partly because I'm hoping it will help me understand x86 disassembly and also because I'm finding it fairly fun too! This is my first experience…
Justin
  • 84,773
  • 49
  • 224
  • 367
9
votes
1 answer

Should using MOV instruction to set SS to 0x0000 cause fault #GP(0) in 64-bit mode?

This question is inspired by a Reddit question in r/osdev except that this question focuses on the SS register. One may say RTFM (ISA entry for MOV), but when this question comes up it can get varying answers even among OS developers. Question:…
Michael Petch
  • 46,082
  • 8
  • 107
  • 198
9
votes
3 answers

NASM Guessing Number Game Gone Wrong

I have decided to create a simple guessing number game that uses Linux system calls, and some C functions to provide a more simpler interface. I seem to get a segmentation fault when I convert the int to string and print the correct answeron the…
Daniel Lopez
  • 177
  • 1
  • 1
  • 5
9
votes
1 answer

How to force NASM to encode [1 + rax*2] as disp32 + index*2 instead of disp8 + base + index?

To efficiently do x = x*10 + 1, it's probably optimal to use lea eax, [rax + rax*4] ; x*=5 lea eax, [1 + rax*2] ; x = x*2 + 1 3-component LEA has higher latency on modern Intel CPUs, e.g. 3 cycles vs. 1 on Sandybridge-family, so disp32 +…
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
9
votes
2 answers

Assembly compiled executable using INT 0x80 on Ubuntu on Windows Subsystem for Linux doesn't produce output

I've been looking at a tutorial for assembly, and I'm trying to get a hello world program to run. I am using Bash on Ubuntu on Windows. Here is the assembly: section .text global _start ;must be declared for linker (ld) _start: …
Zack
  • 874
  • 1
  • 9
  • 18
9
votes
1 answer

Using db to declare a string in assembly NASM

I am following a tutorial to write a hello world bootloader in assembly and I am using the NASM assembler for an x-86 machine. This is the code I am using : [BITS 16] ;Tells the assembler that its a 16 bit code [ORG 0x7C00] ;Origin, tell the…
Neeraj
  • 137
  • 1
  • 2
  • 9
9
votes
3 answers

How are dw and dd different from db directives for strings?

Let's say I want to define a initialized variable string before running my assembly program (in section .data). The variable I chose to create is called Digits and it is a string that contains all the hexadecimal symbols. Digits: db…
Pichi Wuana
  • 732
  • 2
  • 9
  • 35
9
votes
1 answer

Error: Operation size not specified - NASM

I'm working in 16 bit NASM assembly having an issue where my code won't build. The error happens on all the MOV lines here: section .bss x_coord RESB 8 ; [x_coord] is the head, [x_coord+2] is the next cell, etc. y_coord RESB 8 ; Same here …
Nat
  • 890
  • 3
  • 11
  • 23
9
votes
1 answer

Compile error: relocation R_X86_64_PC32 against undefined symbol

I try to make functions in assembly language and put them in a dynamic library so I create .o with .S with this command: nasm -f elf64 hello.S -o hello.o but when I want to create the lib with gcc: gcc -fPIC -shared hello.o -o libasm.so and it…
killmat
  • 113
  • 1
  • 4
9
votes
1 answer

How does one link NASM program to libc via ld?

I have a following program for NASM (ArchLinux i686) SECTION .data LC1: db "library call", 0 SECTION .text extern exit extern printf ;global main ;main: global _start _start: push LC1 call printf push 0 call exit Which is assembled…
Al Berger
  • 1,048
  • 14
  • 35
9
votes
1 answer

Why can't stdout from calling c library printf in asm be piped to other programs?

I have written a simple NASM program: printtest.asm section .data str_out db "val = %d",10,0 section .text global main extern printf main: PUSH 5 PUSH DWORD str_out CALL printf ADD ESP, 8 MOV EAX, 1 INT 80h I am linking…
user706775