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

Base pointer and stack pointer

Given this piece of code: swap: push ebp ; back up the base pointer, mov ebp, esp ; push the context of the registers on the stack push eax push ebx push ecx …
yhcowboy
  • 585
  • 1
  • 5
  • 13
31
votes
2 answers

Difference between "section" and "segment" in NASM

I am using some baby NASM programs to help me learn the language. From what I've read, NASM programs can have three sections; the .data, the .bss, and the .text which is mandatory. However I am finding very often that sometimes the names of the…
CodyBugstein
  • 21,984
  • 61
  • 207
  • 363
30
votes
3 answers

Error when trying to run .asm file on NASM on Ubuntu

I'm using ubuntu 64-bit and trying to run a .asm file on NASM. But it returns this error when I try to run the following code. What Iḿ trying to do is build an executable by compiling (or assembling) object file from the source $ nasm -f elf…
rogcg
  • 10,451
  • 20
  • 91
  • 133
30
votes
5 answers

How do I print an integer in Assembly Level Programming without printf from the c library? (itoa, integer to decimal ASCII string)

Can anyone tell me the purely assembly code for displaying the value in a register in decimal format? Please don't suggest using the printf hack and then compile with gcc. Description: Well, I did some research and some experimentation with NASM and…
Kaustav Majumder
  • 341
  • 1
  • 4
  • 8
29
votes
2 answers

Linux Shellcode "Hello, World!"

I have the following working NASM code: global _start section .text _start: mov eax, 0x4 mov ebx, 0x1 mov ecx, message mov edx, 0xF int 0x80 mov eax, 0x1 mov ebx, 0x0 int 0x80 section .data message: db "Hello,…
user1408643
  • 731
  • 2
  • 7
  • 14
28
votes
6 answers

How to print a number in assembly NASM?

Suppose that I have an integer number in a register, how can I print it? Can you show a simple example code? I already know how to print a string such as "hello, world". I'm developing on Linux.
AR89
  • 3,548
  • 7
  • 31
  • 46
28
votes
3 answers

x86, difference between BYTE and BYTE PTR

What is the difference between these two lines? What PTR changes here? ;first mov BYTE [ecx], 0 ;second mov BYTE PTR [ecx], 0
Linkas
  • 906
  • 2
  • 10
  • 26
26
votes
2 answers

How to generate plain binaries like nasm -f bin with the GNU GAS assembler?

I have some NASM files that generally have the structure: [BITS 64] [ORG 0x0000000000200000] start: ... ret I'm assembling them like so: nasm -f bin abc.asm I'd like to write some of these using GAS instead. Two…
dharmatech
  • 8,979
  • 8
  • 42
  • 88
26
votes
3 answers

How to generate a nasm compilable assembly code from c source code on Linux?

Test platform is 32 bit Linux. Basically, I know gcc can be used to generate both Intel and At&T style assembly code, but it seems that you can not directly use nasm/tasm to compile the Intel style assembly code gcc generated. I am conducting a…
lllllllllllll
  • 8,519
  • 9
  • 45
  • 80
25
votes
4 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
  • 859
  • 1
  • 8
  • 18
24
votes
4 answers

MOV src, dest (or) MOV dest, src?

MOV is probably the first instruction everyone learns while learning ASM. Just now I encountered a book Assembly Language Programming in GNU/Linux for IA32 Architectures By Rajat Moona which says: (broken link removed) But I learnt that it is MOV…
claws
  • 52,236
  • 58
  • 146
  • 195
23
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,790
  • 9
  • 36
  • 57
22
votes
1 answer

Why data and stack segments are executable?

I have just noticed that my simple program has its data and stack segments executable. I saw it in /proc/[pid]/maps, and simple code confirmed it. For example: ; prog.asm section .data code: db 0xCC ;int3 section .text global…
witosx
  • 614
  • 4
  • 15
22
votes
2 answers

Loop unrolling vs Loop tiling

Can someone please tell if the 2 optimization techniques are same or different? Also, is it responsibility of programmer or compiler to do it?
paseena
  • 4,207
  • 6
  • 32
  • 51
22
votes
2 answers

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
  • 409
  • 1
  • 5
  • 10