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
1
vote
0 answers

Why am I getting segmentation fault when I run this asm code? (using WSL - Ubuntu in VS code)

; print_row(10, '<') Prints character N-times - this case 10x '<' print_row: mov ecx, edi ; num push rbx ; preserving callee-saved register value mov ebx, esi ; using callee-saved register for the char value sub…
1
vote
0 answers

How to write a nasm file to achieve high precision division

I want to use nasm language to achieve a high precision division, firstly, I have written a C file, according which to write my assembly file. It's the C file #include #include static const int LEN = 1004; int a[LEN], b[LEN],…
fanrcis
  • 11
  • 1
1
vote
1 answer

I want to write bubble sort but my code is accessing non-accessible element in array

Write simple buble sort in nasm x86. %include "io.inc" section .bss n resd 1 arr resd 1000000 section .text global main main: mov ebp, esp; for correct debugging GET_UDEC 4, n xor ecx, ecx xor esi, esi mov edi, 1 l1: cmp…
1
vote
1 answer

Trouble doubling the size of array in Assembly

Trying to double the array to increase the array to add more elements. There is no compile or runtime error but it doesn't let you input more elements after 5 I'm not sure if the array size is not doubling at all or what is happening because you can…
1
vote
1 answer

When i try to write to an address 1 byte up with a loop it corrupts the variable asm

Im trying to do a loop in NASM that simply writes to a variable 1 and then do it again but 1 byte up on the variable... i have come up with this design mov ebx, 0 mov rax, 1 test_loop: cmp ebx, 4 je test_loop_end mov…
Rabyt
  • 61
  • 6
1
vote
0 answers

Why does this subtraction in NASM not set the sign flag?

I'm attempting to locate the minimum value in an array in NASM. My array is set up fine, but I keep running into this problem where the sign flag is not set, even though a negative result is produced. Here's the GDB debugger for the problem. R8 is…
louis
  • 11
  • 2
1
vote
0 answers

How to mix assembly language (nasm) and C?

I wrote some c header and I want to use it in assembly code. How can I do that? How to compile them? example: somefunc.h: // somefunc.h int int_func(){ // some code here } float float_func(){ // some code here } main_assembly_code.h: section…
1
vote
1 answer

Decimal representation of a number that doesn't fit in one register in NASM

If we have a number in a register and we need to get its decimal digits values - it's easy. All we need is divide the number by 10 and save the remainders we get. lp: cmp eax, 0 ; have we finished? je prinrt inc …
Fyodor
  • 25
  • 5
1
vote
0 answers

How do print non-ascii characters in NASM string?

I made a little NASM program that reads it's first command line argument and prints it out. It works well with ascii input: running "myfile hello" returns "argv = hello", but if input string contains special letters such as õ, ä, ö, ü , they will…
tanler
  • 9
  • 3
1
vote
1 answer

Bootloader doesn't jump to the right address and doesn't print anything

I'm trying to build a small bootloader that loads the second sector of a floppy disk. The bootloader I started is pretty basic: I print a hello world message. Load the second sector. I compile it and put along with a sample. I run qemu with gdb,…
Flyfe
  • 33
  • 5
1
vote
1 answer

Problem with number output to DOS console in NASM Assembler

We have the following task: write a program that sets the default values of x and y (in the program these are 3 and 5 respectively), then it compares these numbers and replaces the lesser of them with the half-sum of x and y, and replaces the…
Mizless
  • 11
  • 2
1
vote
0 answers

QEMU starts blinking with custom boot loader in x86

I'm writing my own boot loader for i386 in NASM for education purposes. But when I'm running qemu with this it starts blinking and do anything but what I want. Here's my code: ; defs.asm %define STACK_SEGMENT_REAL_MODE 0x9000 %define…
k1r1t0
  • 465
  • 2
  • 11
1
vote
1 answer

Manipulating Strings in x86 assembly code , NASM, Linux

I have been trying to manipulate a string in my .s file i want that the variable "pa" that contains "/bin/bash" be transformed into "/bin/sh" and then i want to make a call to the system that executes "/bin/sh" I have written a print mechanism to…
Hitesh Dharamdasani
  • 852
  • 1
  • 10
  • 19
1
vote
1 answer

How to write only the digits in a string in assembly NASM

MY objective is to collect the digits in a string and print only them. In the end i wish to add them together to return a result, but for now i am stuck at trying to collect them. I am totaly new to assembly in general (3 hours in) i am a computer…
isaac
  • 11
  • 2
1
vote
0 answers

How can I know the number of bytes I need for a given input?

I'm using the SASM IDE using NASM as my assembler to produce a 32-bit program. How can I know the number of bytes (first parameter) I need for a given input when using the PRINT_DEC macro? let's say I need to print 6518846, how many bytes do I need…
ae winter
  • 11
  • 2
1 2 3
99
100