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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:10:03+00:00 2026-06-07T23:10:03+00:00

This code is a C program (bubble sort) disassembled into assembly. How can I

  • 0

This code is a C program (bubble sort) disassembled into assembly. How can I make the following code run if I put it in a .asm file and use nasm to assemble? If you know what needs changing, please say what to change it to. For instance I understand that nasm won’t accept DWORD PTR, but I haven’t found out what to do instead. Thanks

.file   "sort.c" .intel_syntax noprefix .text .globl 
sort .type   sort, @function
sort: .LFB0:
    .cfi_startproc
    push    rbp
    .cfi_def_cfa_offset 16
    .cfi_offset 6, -16
    mov rbp, rsp
    .cfi_def_cfa_register 6
    mov QWORD PTR [rbp-24], rdi
    mov DWORD PTR [rbp-28], esi
    mov DWORD PTR [rbp-12], 0
    jmp .L2
.L6:
    mov DWORD PTR [rbp-8], 0
    jmp .L3
.L5:
    mov eax, DWORD PTR [rbp-8]
    cdqe
    sal rax, 2
    add rax, QWORD PTR [rbp-24]
    mov edx, DWORD PTR [rax]
    mov eax, DWORD PTR [rbp-8]
    cdqe
    add rax, 1
    sal rax, 2
    add rax, QWORD PTR [rbp-24]
    mov eax, DWORD PTR [rax]
    cmp edx, eax
    jle .L4
    mov eax, DWORD PTR [rbp-8]
    cdqe
    sal rax, 2
    add rax, QWORD PTR [rbp-24]
    mov eax, DWORD PTR [rax]
    mov DWORD PTR [rbp-4], eax
    mov eax, DWORD PTR [rbp-8]
    cdqe
    sal rax, 2
    add rax, QWORD PTR [rbp-24]
    mov edx, DWORD PTR [rbp-8]
    movsx   rdx, edx
    add rdx, 1
    sal rdx, 2
    add rdx, QWORD PTR [rbp-24]
    mov edx, DWORD PTR [rdx]
    mov DWORD PTR [rax], edx
    mov eax, DWORD PTR [rbp-8]
    cdqe
    add rax, 1
    sal rax, 2
    add rax, QWORD PTR [rbp-24]
    mov edx, DWORD PTR [rbp-4]
    mov DWORD PTR [rax], edx
.L4:
    add DWORD PTR [rbp-8], 1
.L3:
    mov eax, DWORD PTR [rbp-28]
    sub eax, 1
    sub eax, DWORD PTR [rbp-12]
    cmp eax, DWORD PTR [rbp-8]
    jg  .L5
    add DWORD PTR [rbp-12], 1
.L2:
    mov eax, DWORD PTR [rbp-28]
    sub eax, 1
    cmp eax, DWORD PTR [rbp-12]
    jg  .L6
    pop rbp
    .cfi_def_cfa 7, 8
    ret
    .cfi_endproc
.LFE0:
    .size   sort, .-sort
    .ident  "GCC: (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3"
    .section    .note.GNU-stack,"",@progbits
  • 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-06-07T23:10:04+00:00Added an answer on June 7, 2026 at 11:10 pm

    Just remove PTR and all nonsensical .somethings.

    This assembles just fine:

    ; file: gas-nasm-sort.asm
    bits 64
    
    sort:
    push rbp
    mov rbp, rsp
    mov QWORD [rbp-24], rdi
    mov DWORD [rbp-28], esi
    mov DWORD [rbp-12], 0
    jmp .L2
    
    .L6:
    mov DWORD [rbp-8], 0
    jmp .L3
    
    .L5:
    mov eax, DWORD [rbp-8]
    cdqe
    sal rax, 2
    add rax, QWORD [rbp-24]
    mov edx, DWORD [rax]
    mov eax, DWORD [rbp-8]
    cdqe
    add rax, 1
    sal rax, 2
    add rax, QWORD [rbp-24]
    mov eax, DWORD [rax]
    cmp edx, eax
    jle .L4
    mov eax, DWORD [rbp-8]
    cdqe
    sal rax, 2
    add rax, QWORD [rbp-24]
    mov eax, DWORD [rax]
    mov DWORD [rbp-4], eax
    mov eax, DWORD [rbp-8]
    cdqe
    sal rax, 2
    add rax, QWORD [rbp-24]
    mov edx, DWORD [rbp-8]
    movsx rdx, edx
    add rdx, 1
    sal rdx, 2
    add rdx, QWORD [rbp-24]
    mov edx, DWORD [rdx]
    mov DWORD [rax], edx
    mov eax, DWORD [rbp-8]
    cdqe
    add rax, 1
    sal rax, 2
    add rax, QWORD [rbp-24]
    mov edx, DWORD [rbp-4]
    mov DWORD [rax], edx
    
    .L4:
    add DWORD [rbp-8], 1
    
    .L3:
    mov eax, DWORD [rbp-28]
    sub eax, 1
    sub eax, DWORD [rbp-12]
    cmp eax, DWORD [rbp-8]
    jg .L5
    add DWORD [rbp-12], 1
    
    .L2:
    mov eax, DWORD [rbp-28]
    sub eax, 1
    cmp eax, DWORD [rbp-12]
    jg .L6
    pop rbp
    ret
    

    Command:

    nasm gas-nasm-sort.asm -f bin -o gas-nasm-sort.bin
    

    But again, there’s NASM documentation. Read it. In particular these sections:

    • 2.2.2 NASM Requires Square Brackets For Memory References

    • 2.2.3 NASM Doesn’t Store Variable Types

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

Sidebar

Related Questions

Why does this code crash the program when I run it ostream& operator<<(ostream& cout,
When I run this code the program freezes,why? main() { int co; co=0; while
Consider the following code: class Program { static void Main(string[] args) { new Program().Run(args);
I use this code in my program to load a properties file: Properties properties
First look at this code: class Program { static void Main(string[] args) { var
I have this code in my program: (I included the cout statements for debugging
This code below doesn't work correctly since my MFC program is in unicode circumstance.
I was writing this code for a C program that transforms letters to lower
I'm working on a picture select/crop program and using this code below: http://www.androidworks.com/crop_large_photos_with_android/comment-page-1#comment-969 As
Given below is program for encrypting a string. I had taken this code from

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.