装配x82 IA32 AT& T - 分段故障

时间:2015-10-18 03:51:09

标签: assembly segmentation-fault

我目前正在尝试为过去几天的课程进行大会作业。我有一个C程序,它是确定性有限状态自动机(DFA)的实现。简而言之,我返回一个字符串,表示它将根据所使用的输入接受,拒绝或终止程序。以下是我将我的程序翻译成IA32程序集的尝试:

    ## Test run 4   

    .file   "dfaswi.c"
    .globl  state
    .bss
    .align 4
    .type   state, @object
    .size   state, 4

state:
    .zero   4
    .comm   input,1,1
    .section    .rodata

.LC0:
    .string "Enter a string of 0s and 1s: "

.LC1:
    .string "%c"
    .align 8

.LC2:
    .string "Invalid input: program terminating"

.LC3:
    .string "Input accepted"

.LC4:
    .string "Input rejected"
    .text
    .globl  main
    .type   main, @function

main:

.LFB0:
    pushl   %ebp
    movl    %esp, %ebp
    movl    $.LC0, %edi
    movl    $0, %eax
    call    printf
    jmp .L17

.L22:
    nop

.L17:
    movl    $input, %esi
    movl    $.LC1, %edi
    movl    $0, %eax
    call    __isoc99_scanf
    movzbl  input(%ebp), %eax
    cmpb    $10, %al
    je  .L21

.L2:
    movzbl  input(%ebp), %eax
    cmpb    $48, %al
    je  .L4
    movzbl  input(%ebp), %eax
    cmpb    $49, %al
    je  .L4
    movl    $.LC2, %edi
    call    puts
    jmp .L3

.L4:
    movl    state(%ebp), %eax
    testl   %eax, %eax
    jne .L5
    movzbl  input(%ebp), %eax
    cmpb    $48, %al
    jne .L6
    movl    $1, %eax
    jmp .L7

.L6:
    movl    $3, %eax

.L7:
    movl    %eax, state(%ebp)
    jmp .L22

.L5:
    movl    state(%ebp), %eax
    cmpl    $1, %eax
    jne .L9
    movzbl  input(%ebp), %eax
    cmpb    $48, %al
    jne .L10
    movl    $0, %eax
    jmp .L11

.L10:
    movl    $2, %eax

.L11:
    movl    %eax, state(%ebp)
    jmp .L22

.L9:
    movl    state(%ebp), %eax
    cmpl    $2, %eax
    jne .L12
    movzbl  input(%ebp), %eax
    cmpb    $48, %al
    jne .L13
    movl    $3, %eax
    jmp .L14

.L13:
    movl    $1, %eax

.L14:

    movl    %eax, state(%ebp)
    jmp .L22

.L12:

    movl    state(%ebp), %eax
    cmpl    $3, %eax
    jne .L22
    movzbl  input(%ebp), %eax
    cmpb    $48, %al
    jne .L15
    movl    $2, %eax
    jmp .L16

.L15:
    movl    $0, %eax

.L16:
    movl    %eax, state(%ebp)
    jmp .L22

.L21:
    nop

.L3:
    movzbl  input(%ebp), %eax
    cmpb    $10, %al
    jne .L18
    movl    state(%ebp), %eax
    testl   %eax, %eax
    jne .L19
    movl    $.LC3, %edi
    call    puts
    jmp .L18

.L19:
    movl    $.LC4, %edi
    call    puts

.L18:
    movl    $0, %eax
    popl    %ebp
    ret

非常感谢我对代码的任何输入。

0 个答案:

没有答案