小编L's*_*rld的帖子

使用GNU汇编程序在x86_64中调用printf

我用AT&T语法编写了一个程序,用于GNU汇编程序:

            .data
format:   .ascii "%d\n"  

            .text
            .global main  
main:
            mov    $format, %rbx
            mov    (%rbx), %rdi
            mov    $1, %rsi
            call     printf
            ret
Run Code Online (Sandbox Code Playgroud)

我使用GCC来组装和链接:

gcc -o main main.s

我用这个命令运行它:

./主要

当我运行程序时,我得到一个seg错误.通过使用gdb,它说printf没有找到.我试过".extern printf",但是没有用.有人建议我应该printfRET之前存储堆栈指针并在RET之前恢复,我该怎么做?

linux assembly gcc x86-64 gnu-assembler

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

当任何值分配给*(p + 1)时,为什么指针p的值发生了变化?

#include <stdio.h>
int main(void){
    int* p = NULL;
    int y = 1;
    p = &y;
    printf("%p\n",p);
    *(p+1) = 10;
    printf("%p\n",p);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出:

0x7ffe2368f2e4
0x7ffe0000000a

我不知道为什么p在这里被改变了,第二个有"0000000a",最后是10,你能帮助我吗?谢谢.我用linux中的gcc编译它.

c pointers

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

使用makefile时对"main"的未定义引用

我有四个文件 list.h list.c test_list.c Makefile

list.h

#ifndef List_H
#define List_H
#endif
/*nothing else*/
Run Code Online (Sandbox Code Playgroud)

list.c

#include "list.h"
#include <stdio.h>
#include <stdlib.h>
/*nothing else*/
Run Code Online (Sandbox Code Playgroud)

test_list.c

#include "list.h"
#include <stdio.h>   
int main(){
    return 0;
}
/*nothing else*/
Run Code Online (Sandbox Code Playgroud)

Makefile文件

CC=cc
CXX=CC
CCFLAGS= -g -std=c99 -Wall -Werror

all: list test_list

%.o : %.c
    $(CC) -c $(CCFLAGS) $<

test_list: list.o test_list.o
    $(CC) -o test_list list.o test_list.o

test: test_list
    ./test_list

clean:
    rm -f core *.o test_list
Run Code Online (Sandbox Code Playgroud)

当我在shell中输入make时,出现错误:

/ usr/bin/ld:/usr/lib/debug/usr/lib/i386-linux-gnu/crt1.o(.debug_line):重定位0具有无效的符号索引2/usr/lib/gcc/i686-linux- gnu/4.8 /../../../ i386-linux-gnu/crt1.o:在函数_start':(.text+0x18): undefined reference tomain'collect2:error:ld返回1退出状态make:***[list]错误1 …

c gcc makefile

0
推荐指数
1
解决办法
1758
查看次数

标签 统计

c ×2

gcc ×2

assembly ×1

gnu-assembler ×1

linux ×1

makefile ×1

pointers ×1

x86-64 ×1