小编Mee*_*cus的帖子

为什么这个IA32汇编代码有三个leal指令?

我编译了这个C函数:

int calc(int x, int y, int z) {
   return x + 3*y + 19*z;
}
Run Code Online (Sandbox Code Playgroud)

我在calc.s中得到了这个,我正在注释正在发生的事情:

        .file   "calc.c"
        .text
.globl calc
        .type   calc, @function
calc:
        pushl   %ebp                    //Save paramaters
        movl    %esp, %ebp              //Move stack pointer into %ebp
        movl    12(%ebp), %eax          //Move y into %eax
        movl    16(%ebp), %ecx          //Move z into %ecx
        leal    (%eax,%eax,2), %eax     //%eax = 3*y
        addl    8(%ebp), %eax           //%eax = x+3y
        leal    (%ecx,%ecx,8), %edx     // ?
        leal    (%ecx,%edx,2), %edx     // ?
        addl    %edx, %eax              //%eax = (x+3*y)+(19*z) …
Run Code Online (Sandbox Code Playgroud)

c x86 assembly intel

5
推荐指数
1
解决办法
2847
查看次数

"print $ ARGV"会以任何方式改变参数数组吗?

这是一个例子:

$a = shift; 
$b = shift; 
push(@ARGV,$b); 
$c = <>; 

print "\$b: $b\n"; 
print "\$c: $c\n"; 
print "\$ARGV: $ARGV\n"; 
print "\@ARGV: @ARGV\n"; 
Run Code Online (Sandbox Code Playgroud)

并输出:

$b: file1 
$c: dir3 

$ARGV: file2 
@ARGV: file3 file1 
Run Code Online (Sandbox Code Playgroud)

我不明白在没有任何索引的情况下打印$ ARGV时究竟发生了什么.它是否打印第一个参数然后从数组中删除它?因为我认为在所有语句之后数组变成:

file2 file3 file1
Run Code Online (Sandbox Code Playgroud)

调用:

perl port.pl -axt file1 file2 file3 
Run Code Online (Sandbox Code Playgroud)

file1包含以下行:

dir1 
dir2 
Run Code Online (Sandbox Code Playgroud)

文件2:

dir3 
dir4 
dir5 
Run Code Online (Sandbox Code Playgroud)

文件3:

dir6 
dir7
Run Code Online (Sandbox Code Playgroud)

perl shift argv command-line-arguments

3
推荐指数
2
解决办法
961
查看次数

C中数组的递归和

您好我正在学习C中的递归,我试图找到元素的总和.

这是我的主要内容:

int main()
{


    int arr[] = {1,2,3,4,5};
    int sum;
    sum = arr_sum(arr,4);
    printf("\nsum is:%d",sum);



    return 0;

}
Run Code Online (Sandbox Code Playgroud)

而我的递归功能:

//n is the last index of the array

int arr_sum( int arr[], int n )
{ // must be recursive

    int sum = 0;
    //base case:
    if (n < 0) {
        return sum;
    } else{
        sum = sum + arr[n];
    }
    //make problem smaller
    arr_sum(arr,n-1);
}
Run Code Online (Sandbox Code Playgroud)

输出是:

sum is :0 
Run Code Online (Sandbox Code Playgroud)

c arrays recursion sum

2
推荐指数
2
解决办法
5万
查看次数

标签 统计

c ×2

argv ×1

arrays ×1

assembly ×1

command-line-arguments ×1

intel ×1

perl ×1

recursion ×1

shift ×1

sum ×1

x86 ×1