您现在的位置是:主页 > news > 潜江公司做网站/站内优化怎么做
潜江公司做网站/站内优化怎么做
admin2025/6/7 2:44:34【news】
简介潜江公司做网站,站内优化怎么做,网站开发设计说明书,前台网站建设看内核的时候遇到一个问题,一个.S文件跟一个.c文件都有一个同名的变量,都是全局的,那么编译之后.S文件先执行,当时我以为是.S中的变量与.c中的变量是同一个变量,其实是错误的,代码验证A10.section .dataout…
看内核的时候遇到一个问题,一个.S文件跟一个.c文件都有一个同名的变量,都是全局的,那么编译之后.S文件先执行,当时我以为是.S中的变量与.c中的变量是同一个变量,其实是错误的,代码验证
A=10
.section .data
output:
.asciz "this is [%d]\n"
.secion .text
.globl main
main:
call hello
pushl $A
pushl $output
call printf
movl $1, %eax
movl $0, %ebx
int $0x80
此为 1.S文件
#include
int A=5;
void hello(){
printf("hello world A=[%d]\n", A);
}
此为 2.c文件
编译命令: gcc -o test 1.S 2.c
./test
结果: A=5, A=10 //两个不同结果,说明彼此的A是不同的,那么如何才能引用c中的A呢?
代码如下: 1.S 改一下
.extern int A;
.section .data
output:
.asciz "this is [%d]\n"
.secion .text
.globl main
main:
call hello
pushl A //注意传过来的是A的地址
pushl $output
call printf
movl $1, %eax
movl $0, %ebx
int $0x80
要注意的是 如果在 .extern int A; 的下一行 这样 A= 10 ,那么pushl A这里的A总认为是 A=10中的A,并非extern int A 中的A