调用函数不起作用

时间:2011-12-21 17:08:56

标签: linux assembly x86

给出以下代码:

.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 :(得分:0)

  

问题是按下后(例如)50我跳转到case1,但不是代码本身,而是直接到ret行

我刚刚在Linux上构建了你的代码,在GDB中逐步完成了代码,并且没有观察到了这种行为。

你有可能错误地解释了你实际观察到的内容。