Segmentation-fault error happening with Assembly code program

后端 未结 2 1669
逝去的感伤
逝去的感伤 2021-01-24 15:03

I keep getting a segmentation fault error when running my code. Everything has compiled well, but I can\'t seem to get it to do what I want. The program is to ask the user to e

相关标签:
2条回答
  • 2021-01-24 15:56

    It is not easy to pinpoint the problem without knowing the compiler you use.

    Segmentation fault hapens in protected mode, when you try to access a segment you have no permissions to access.

    You declare 3 diferent segments here. You have to make sure your ds register is initialized to your .data segment, before calling print_string.

    It also seems problematic that after read_int you save the data to the input1 variable which seems to be in a different segment than that you used for printing the message, but you do not change ds.

    I'm not familiar how exactly your compiler handles these segments, so please give a link to its documentation.

    0 讨论(0)
  • 2021-01-24 15:57
    div ebx
    

    the problem seems to be here. You have to zero out edx since is is the high order word of the divisor, so probably you're getting something like a division overflow exception.
    If this isn't the case probably the problem is in some of your I/O routines

    0 讨论(0)
提交回复
热议问题