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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:19:30+00:00 2026-05-26T14:19:30+00:00

This is a homework if anyone’s curious. The task is to have a C

  • 0

This is a homework if anyone’s curious.

The task is to have a C program create a 2D array and pass that array into assembly which it should be sorted using selection sort.

The error I’m having when trying to run it is segmentation fault. I’ve tried putting

push tesst
push sout
call printf

to print out “test” on the terminal window but I couldn’t figure out where it’s coming from. I also tried putting it right after “enter 0,0” and I still havent gotten a print out of test. So i’m completely out of ideas as to where i’m getting the segmentation fault.

Any assistance would be very much appreciated. 🙁 Due tomorrow night and i’ve been stuck at this for a couple of days. Someone shed some light please

-Chris

The codes will be below

my c program

#include <stdio.h>

int ssort(char * hi[], int x, int y);

int main(){

  int i, j;


  char hi[3][5] = {"Yoshi", "Annie", "Chris"};

  printf("Display Unsorted Strings\n");
  for(i = 0; i < 3; i++){
    for(j = 0; j < 5; j++){
      printf("%c", hi[i][j]);
    }
    printf("\n");
  }
  printf("It Got Here\n");
  ssort((char*)hi, 5, 3);
  printf("Sorted\n");
  for(i = 0; i < 3; i++){
    for(j = 0; j < 5; j++){
      printf("%c", hi[i][j]);
    }
    printf("\n");
  }
}

And my Assembly Code

extern    printf

segment   .data

tesst db  't','e','s','t',0
sout  db  "%s", 10, 0

segment   .text

  global  ssort

ssort:    
  enter   0,0

;;; for(i = 0; i < namecount; i++){
;;;   for(j = 1; j < namecount; j++){
;;;       if(array[i] < array[j])
;;;           do nothing
;;;       else
;;;           swap
;;;   }
;;; }


  mov esi,    [ebp+8] 
  mov edi,    esi
  add edi,    [ebp+8]
  mov ecx,    0   ;i
  mov edx,    0
  add edx,    1   ;j
  ;; [ebp+16] = namecount

iloop:
  push    esi
  cmp ecx,    [ebp+16]
  je  done_sorting
jloop:
  cmp edx,    [ebp+16]
  je  j_done

;;; compare here now
compare:
  mov al, [esi]
  mov bl, [edi]
  cmp al, bl
  jg  alisbigger
  jl  blisbigger
  inc esi
  inc edi
  jmp compare
alisbigger:   
  jmp swap
blisbigger:   
  jmp done

swap:
  mov ebx,    0
  mov ebx,    [ebp+12]
swap_loop:
  dec ebx

  mov al, [esi]
  mov bl, [edi]
  mov [esi],  bl
  mov [edi],  al

  inc esi
  inc edi

  cmp ebx,    0
  je  done
  jmp swap_loop

done:
  inc edx
  jmp jloop

j_done:
  add ecx, 1
  add esi, [ebp+12]
  mov edx, 1
  jmp iloop   


done_sorting:
  leave
  ret
  • 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-26T14:19:31+00:00Added an answer on May 26, 2026 at 2:19 pm

    Print-style debugging is okay in situations where there’s nothing else available but nothing beats getting down and dirty inside a source level debugger.

    Step 1: Probably the easiest way is to first take out the call into assembly and run it, to ensure it’s not your C code causing the problem.

    Step 2: Then, put the call back in and load it into gdb or your favorite source level debugger. Set a breakpoint on the first assembler instruction. When it breaks, examine the stack to ensure it’s what you expect.

    Step 3: Then single step through the assembly until you find your problem.

    That will be the best way for you to learn, and to quickly find and fix your problem.


    I will tell you one thing I see as a potential problem. Just after the iloop label, you have push esi. I can’t see a pop (or other esp-modifying statement) anywhere in your code and, worse yet, that push is happening in a loop.

    If you try to return from a function with the stack pointer different to what it was when you entered, you’re in for a world of pain. I may just have missed something but I’d start by looking there.

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

Sidebar

Related Questions

This is a homework problem that I have. I have been doing some research
(Before anyone asks, this is not homework.) I have a set of workers with
I have a prolog homework, which should work like this: singles([1,2,3,2,2,4,1], [3,4]). true Now
I assure you all that this is not homework. I have a combo box:
This was a homework assignment problem which I know I have incorrectly answered. I
I'm working on this homework that's kind of confusing me... I am provided with
This is a homework task, but it's very simple. The task comes with a
This is not homework, I need this for my program :) I ask this
Please note that this is not homework and i did search before starting this
this one is not homework, it just the fact that i've been out of

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.