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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:37:53+00:00 2026-05-26T17:37:53+00:00

My goal is to load values in a 5×5 matrix and compare each value

  • 0

My goal is to load values in a 5×5 matrix and compare each value and print out the largest number.

After running a debugger I get :

0x080480bb <+0>:     mov    esi,DWORD PTR [eax+edi*1]

0x080480be <+3>:     jmp    0x804809d <loop>

segment .data
    matrix db   1,62,3,44,35, \
            61,52,43,45,55, \
            17,23,37,74,65, \
            13,12,93,94,95, \
            31,21,13,14,25

segment .bss

holder  resb    4

counter resb    4


segment .text

global _start

_start:

    mov eax, matrix
    call big

big:
    mov esi, holder
    mov edi, counter
    mov edi, 0
    jmp switch

loop:
    inc edi
    cmp esi, [eax + edi]
    jg switch
    cmp edi, 25 
    jle loop
    mov eax, [esi]
    sub eax, '0'
    mov eax, 4              
    mov ebx, 1
    mov ecx, esi
    mov edx, 4
    int 0x80

switch:
    mov esi, [eax + edi]
    jmp loop

exit:
    mov eax, 1
    xor ebx, ebx
    int 0x80
  • 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-26T17:37:53+00:00Added an answer on May 26, 2026 at 5:37 pm

    I can see some problems in your code. Here’s the first one:

    cmp edi, 25 
    jle loop
    mov eax, [esi]   <--
    sub eax, '0'
    mov eax, 4 
    

    At this point, you’ve checked the whole matrix and want to write down the largest value found, which is already in esi, so you don’t have to dereference to get it. Also, you should be adding ‘0’ for numbers between 0 and 9, so the conversion is also wrong. And, one final thing, after converting you’re overwriting the value in eax, which is therefore lost.
    The real segmentation fault, howewer, happens here,

    mov esi, [eax + edi]   <--
    jmp loop
    

    Right after you write the result. The problem is that ecx should contain a pointer to the zero terminated string to write. Instead of that, you put in it the number you want to write, which is undefined behavior (it means everything might happen). Now, eax holds write’s return value, so my guess is that an error occurred and eax now contains -1, resulting in a seg. fault.
    One simple work-around for that is adding a jmp exit after you write the value.

    And, last but not least, (and as @user786653 said), “not handling your byte-sized data properly”. What does that mean? Basically, your matrix is an array of bytes, but every time you read from memory you pick up 4 bytes at time. The simplest solution is to declare your matrix as a double words array (dd or dword in place of db) and multiply by 4 the offset (example: mov eax, [ebx + ecx * 4]).

    C’mon, don’t worry! Assembly is a difficult beast to play with 😉

    EDIT:
    The part which finds the greatest number is correct. You just have to fix the “output” part and the addressing stuff I said before. In my opinion, if you use the hex base for your numbers converting it to a printable string will be much easier (you can multiply by 2^n by shifting left by n places -> shl eax, 5 = eax *= 32)

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

Sidebar

Related Questions

My ultimate goal is to load controls as plugins, for use as DocumentContent in
My goal is to pull XML data from the API and load it to
can I load a ps1 file from within a ps1 file. The end goal
I have just recently implemented the inAppSettings kit. My goal was to load my
I am filling up a Stackpanel with Textboxes. Each textbox, Should display the Value
my goal is to load three distinct div elements from an external HTML and
Greetings, My goal: To validate an XML document then load the data into a
The following jQuery's goal is to load images from a server, and then control
I have a UIWebView that is being populated dynamically out of the values stored
My goal is to dynamically load the contents of a component in JSF 2.0.

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.