read and print number of command-line arguments in Linux assembly

霸气de小男生 提交于 2019-12-13 05:53:59

问题


I'm writing an assembly program with AT&T syntax (GAS compiling) on an Intel processor and on Ubuntu 14.

I'm trying to read the number of parameters passed by the user at the moment of program launch. For instance if user open his terminal and types ./programname x y z I'd like that the nParameters variable assumes value 4 (because programname, x, y and z are parameter).

This is what I've done so far but I keep getting a segementation fault error.

.code32
.section .data

nParameters: .byte 0

.section .text
    .global _start

_start:
    popl %eax   #extract the number of parameters on the stack
    movl %eax,nParameters

movl $1,%eax
movl $0,%ebx
int $0x80

The error lies on this line: movl %eax,nParameters but I don't know why

来源:https://stackoverflow.com/questions/37829346/read-and-print-number-of-command-line-arguments-in-linux-assembly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!