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 6121893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:50:09+00:00 2026-05-23T15:50:09+00:00

So I’m learning x86_64 nasm assembly on my mac for fun. After hello world

  • 0

So I’m learning x86_64 nasm assembly on my mac for fun. After hello world and some basic arithmetic, I tried copying a slightly more advanced hello world program from this site and modifying it for 64 bit intel, but I can’t get rid of this one error message: hello.s:53: error: Mach-O 64-bit format does not support 32-bit absolute addresses. Here is the command I use to assemble and link: nasm -f macho64 hello.s && ld -macosx_version_min 10.6 hello.o. And here is the relevant line:

cmp rsi, name+8

rsi is the register I am using for my index in the loop, and name is a quad word reserved for the user input which is the name, which by this point has already been written.

Here is a part of the code (to see the rest, click the link and go to the bottom, the only difference is that I use 64 bit registers):

loopAgain:
mov al, [rsi]           ; al is a 1 byte register
cmp al, 0x0a            ; if al holds an ascii newline...
je exitLoop             ; then jump to label exitLoop

; If al does not hold an ascii newline...
mov rax, 0x2000004      ; System call write = 4
mov rdi, 1              ; Write to stdout = 1
mov rdx, 1              ; Size to write
syscall

inc rsi

cmp rsi, name+8         ; LINE THAT CAUSES ERROR
jl loopAgain
  • 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-23T15:50:09+00:00Added an answer on May 23, 2026 at 3:50 pm

    The cmp instruction does not support a 64-bit immediate operand. As such, you cannot put a 64-bit immediate address reference in one of its operands – load name+8 into a register then compare to that register.

    You can see what instruction encodings are permitted in the Intel ISA manual (warning: huge PDF). As you can see on the entry for CMP, there are CMP r/m32,
    imm32
    and CMP r/m64,
    imm32
    encodings, which allow for comparisons of a 32-bit immediate with both 32-bit and 64-bit registers, but not a CMP r/m64, imm64. There is, however, a MOV r64, imm64 encoding.

    Or even better, use a RIP-relative LEA: Use default rel then lea r64, [name+8]. This is more efficient and smaller than mov r64, imm64.


    Since nasm is crashing, the failure of MOV rcx, name+8 is just plain a bug in nasm. Please report it to the nasm devs (after making sure you’re using the latest version of nasm; also, check that this patch doesn’t fix the problem). In any case, though, one workaround would be to add a symbol for the end of name:

    name:
        resb 8
    name_end:
    

    Now simply use MOV rcx, name_end. This has the advantage of not needing to update the referents when the size of name changes. Alternately you could use a different assembler, such as the clang or GNU binutils assemblers.


    Discussion in comments points out that Linux can use a symbol address as a 32-bit immediate. This is true only in non-PIE executables which are linked with a base address in the low 2GiB of virtual address space. But MacOS chooses to put the image base address above 4GiB so you can’t use mov r32, imm32 or cmp r64, sign_extended_imm32 with symbol addresses.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Specifically, suppose I start with the string string =hello \'i am \' me And
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which is

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.