Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6221145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:04:55+00:00 2026-05-24T08:04:55+00:00

As you might guess, I’m new to this (both nasm and assembly, though I’ve

  • 0

As you might guess, I’m new to this (both nasm and assembly, though I’ve done some basic assembly before).
I’m trying to create a function that prints integers to standard output. Using non-reusable code (where the number to be printed is static), I’ve succeeded… However, for obvious reasons, I want it to take the number to print as an argument.

I’m unsure whether a macro or a function is best for me, and I can’t find much on the topic of NASM macros at all. I’ve read the manual quite carefully, but it’s not enough.

Anyway, I’ve tried to do this with a NASM macro, as I created another one that prints strings with success that way.
I’ve narrowed down the problematic code to this:

%macro crash 1
jmp %%endstr
%%str: db %1,0x0a
%%endstr:
mov [%%str], byte 0x16 <<< this crashes (segmentation fault)
%endmacro

section .text
global _start
_start:
crash "abc"

It looks like anything that uses brackets on the buffer crashes, and I can only assume I’m doing it wrong.
What I want the above to do is to overwrite the first byte in %%str with another byte value. More precisely, I need to write a string to a buffer byte-by-byte backwards; I (try to) do this with a loop, where I do

mov [%%str+rcx], dl
dec rcx

until rcx is 0.

If I shouldn’t use macros for this, please enlighten me!
I intend to save the function in a mini-library for later use as well, so it should be easy to pop it in to any NASM project.

As the topic and tags say, all this is under Linux/amd64.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T08:04:55+00:00Added an answer on May 24, 2026 at 8:04 am

    You can’t do that in the code segment because it’s read-only. You should declare str in the @data segment, then you’ll be fine. And, just like @user786653 said, “You should make this a function, having macros spread internal state all around your code is bad style (even for assembler!)”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I guess there might be some overlapping with previous SO questions, but I could
I guess this might have been posted somewhere, I did search, but couldn't find
I'm trying to simplify a form (using ASP.NET MVC but I guess that might
I guess this might be a miracle, but is there a way to make
Yes, as you might guess, I want to ask about Cloud-computing. I doubt that
My guess is that <br> might be inline and that <hr> might be block.
might be a stupid question but I seem to be confused. Im pretty new
I had this problem a long time ago and recently I got some clues
I'm trying to get a very basic JSF page running. Using Websphere 7.0 as
there's two methods i was looking at @stackOverFlow , i guess there might be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.