首页 > 解决方案 > 关于汇编中的命令行参数

问题描述

这是我的代码

    segment .data
    ; initialized data is put in the data segment here
    ;

    segment .text
    global  main
main:
    enter   0,0     ; setup stack frame
    pusha

    call    func
    ;

    ; 

    ; 
    ;

    popa
    mov eax, 0  ; 
    leave           ; 
    ret

func:
    push ebp
    mov ebp,esp
    sub esp,4  ;this is for local variable

    mov eax,dword [ebp+12]
    call    print_int
    call    print_nl

    mov eax,dword [ebp+8]
    call    print_int
    call    print_nl

    mov esp,ebp
    pop ebp
    ret

如果我键入命令$./test 1 2 3,则在堆栈中

---------------
pointer to argv-------->ebp+12
---------------
argc           -------->ebp+8
---------------
return address -------->ebp+4
---------------
saved ebp      -------->ebp
---------------

它应该打印出 3(参数的数量),但控制台中只有 0。

怎么了?

标签: assemblyx86callstackstack-frame

解决方案


推荐阅读