问题
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