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

Can i use binary to write integer constants in assembly?

i have an assignment that asks to define 4 integers, each of a different byte length (1, 2, 4, 8) would this code work? segment .data one db 1 two dw 01 four dd 1011 eight dq 01101110 global…
Nasmarr
  • 77
  • 1
  • 1
  • 6
7
votes
1 answer

How can I use NASM as a library?

I would like to include NASM itself (the assembler) in a C++ project. Can I compile NASM as a shared library? If not, is there another assembler that works as a C or C++ library? I checked libyasm but couldn't understand how I can use it to…
kubuzetto
  • 1,046
  • 1
  • 12
  • 31
7
votes
3 answers

How do i read single character input from keyboard using nasm (assembly) under ubuntu?

I'm using nasm under ubuntu. By the way i need to get single input character from user's keyboard (like when a program ask you for y/n ?) so as key pressed and without pressing enter i need to read the entered character. I googled it a lot but all…
Roozbeh Sharafi
  • 347
  • 1
  • 6
  • 21
7
votes
3 answers

NASM local label differentiation

From what I understand, NASM (like all good assemblers) allows you to define local labels by prefixing them with a period, and it allows later definitions to override previous ones. The code I've seen demonstrating this looks like: part1 mov ax,…
paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
7
votes
3 answers

Declaring Arrays In x86 Assembly

I am learning Assembly and I need to make a large array. I have looked around at how to declare arrays and I have come across this. array db 10 dup(?) Where an array of 10 uninitialized bytes is declared. I tried this and tried to assemble it and…
CMilby
  • 624
  • 1
  • 6
  • 23
7
votes
2 answers

CMake uses NASM for linking, which fails.

I have an assembler file I want to compile in one run. However, the following code fails: enable_language(ASM_NASM) set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -f bin") add_executable(test test.s) CMake first runs: nasm -f bin -o test.s.o…
7
votes
1 answer

How to print a string to the terminal in x86-64 assembly (NASM) without syscall?

I am new to assembly, and want to first try to get an intuitive feel for how printing a string to the terminal would work, without going through the operating system abstraction (Linux or OSX). (Editor's note: the accepted answer only covers Linux. …
Lance
  • 75,200
  • 93
  • 289
  • 503
7
votes
2 answers

Mach-O 64-bit format does not support 32-bit absolute addresses. NASM

When I use nasm -f macho64 asm1.asm I get the following error: asm1.asm:14: error: Mach-O 64-bit format does not support 32-bit absolute addresses This is asm1.asm SECTION .data ;initialized data msg: db "Hello world, this is assembly",…
Daniel Node.js
  • 6,734
  • 9
  • 35
  • 57
7
votes
4 answers

How to detect architecture in NASM at compile time to have one source code for both x64 and x86?

I am looking for some preprocessor functionality in nasm that would allow having one source code for both x86 and x64 architectures. I mean something in the vein of ifdef some_constant. Like C preprocessor uses if it wants to detect say if it's…
infoholic_anonymous
  • 969
  • 3
  • 12
  • 34
7
votes
2 answers

Possible to use bios interrupts in your code on linux?

I write a simple program in assembly language in Linux (using nasm), and for educational purposes, I want to use BIOS interrupt instead linux system calls, is this possible ?
user1886376
7
votes
1 answer

Assembly/Linking problem with nasm and ld

I have a sample assembly file that I compile with nasm: nasm -f elf syscall.asm This generates a syscall.o file. I try to link it with ld: ld -o syscall syscall.o The ld command fails with the following error: ld: i386 architecture of input file…
ardsrk
  • 2,407
  • 2
  • 21
  • 33
7
votes
2 answers

Xcode and NASM coding

How can i write and build programs in assembly language in Xcode? I search for it but I wasn't successfull. Can you help me? If it isn't possible to code NASM in xcode please recommend some good IDE.
user1477988
  • 103
  • 1
  • 6
7
votes
1 answer

Can I add 64bit constants to 64bit registers?

At my 64bit Intel machine following code works: mov rdi, 1 << 40 add r10, rdi and this quite equivalent looking one produces a warning and doesn't work: add r10, 1 << 40 Should I just stick with number 1 or am I missing something? This behaviour…
user1864035
  • 113
  • 1
  • 4
7
votes
1 answer

GCC outputs error "undefined reference to `printf'" when using an NASM extern statement to access printf

I am learning NASM and am tying to compile this code (which I found here). It assembles using this NASM command: nasm -f coff -l printf.lst printf1.asm to printf.o but this gcc linking command: gcc -o printf1 printf1.o fails with the…
Callum Rogers
  • 15,630
  • 17
  • 67
  • 90
7
votes
3 answers

How can I run this assembly code on OS X?

Starting to learn assembly, I was given some Hello World assembly code created during the class on Linux. I would like to get it to work for 64-bit Mac OS X. code.asm: SECTION .data hola: db "Hola!",10 tam: equ $-hola …
Saturn
  • 17,888
  • 49
  • 145
  • 271