Вызов функции не работает - PullRequest
       2

Вызов функции не работает

0 голосов
/ 21 декабря 2011

С учетом следующего кода:

.globl  main
    .type main, @function
input:  .string  "%d"
main:

        pushl   %ebp            # save the old frame pointer
        movl    %esp,%ebp       # create the new frame pointer

        movl    $0,%eax
        addl    $-4 ,%esp       # moving down the stack
        pushl   %esp            # push the address of esp to the stack in order to store the number given by the user
        pushl   $input  # push to the stack the format of the input
        call    scanf           # call scanf to get a number from the user
        addl    $8,%esp         # clear the stack
        movl    (%esp),%eax     # get the selection from the user


        subl    $50,%eax
        jmp     *.switching(,%eax,4)


.section .rodata
    .align 4

.switching:

    .long .L1
    .long .L2
    .long .L3
    .long .L4

.text

.L1:
    call    case1
    jmp     .quitTheProgram
.L2:
    call    case2
    jmp     .quitTheProgram
.L3:
    call    case
    jmp     .quitTheProgram
.L4:
    call    case4
    jmp     .quitTheProgram



case1:

            pushl   %ebp            # save the old frame pointer
            movl    %esp,%ebp       # create the new frame pointer
#
# code of case1
# 
            movl    %ebp,%esp       # restore the old ebp
            popl    %ebp            # restore the old stack pointer and release all used memory
            ret                     # return to caller function (OS)

Пользователь нажимает цифры от 50 до 54. Проблема после нажатия (например) 50 Я перехожу к case1, но не к самому коду, а прямо к строке ret, а затем код останавливается и завершает работу case1 (как в остальных случаях).

В чем может быть проблема?

С уважением, Рон

1 Ответ

0 голосов
/ 21 декабря 2011

Проблема в том, что после нажатия (например) 50 я перехожу к case1, но не к самому коду, а к прямой линии

Я только что собрал ваш код в Linux, прошел через него в GDB и не наблюдал такое поведение.

Вполне вероятно, что вы неверно истолковываете то, что действительно наблюдали.

...