编写汇编的时候出现的问题

1.relocation truncated to fit: R_386_16 against `.text' 

如果出现了类似的错误,说明的是当前情况下是32的情况,不能使用16位的数据,

 

2.将.c语言编译为汇编语言的gcc指令

gcc -S main.c

编译为main.s

    .file    "main.c"
    .text
    .globl    f
    .type    f, @function
f:
.LFB0:
    .cfi_startproc
    pushl    %ebp
    .cfi_def_cfa_offset 8
    .cfi_offset 5, -8
    movl    %esp, %ebp
    .cfi_def_cfa_register 5
    movl    $1, %eax//通过的是eax返回的
    popl    %ebp
    .cfi_def_cfa 4, 4
    .cfi_restore 5
    ret
    .cfi_endproc
.LFE0:
    .size    f, .-f
    .globl    main
    .type    main, @function
main:
.LFB1:
    .cfi_startproc
    pushl    %ebp
    .cfi_def_cfa_offset 8
    .cfi_offset 5, -8
    movl    %esp, %ebp
    .cfi_def_cfa_register 5
    call    f
    popl    %ebp
    .cfi_def_cfa 4, 4
    .cfi_restore 5
    ret
    .cfi_endproc
.LFE1:
    .size    main, .-main
    .ident    "GCC: (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3"
    .section    .note.GNU-stack,"",@progbits

上面的.s对应的.c

#include<stdio.h>
int f()
{

    return 1;
}
int main()
{
    f();
    

}

可以看出是通过eax处理的返回值,这里要注意了,是否可以通过栈的形式处理呢????

 

3.在汇编中定义为.global 导出为全局变量的,在C语言中使用的时候是使用的变量,不是该变量对应的地址

例如

global idt

如果需要对idt重新的定义需要

void *idt_base=(void *)&idt;这就是需要使用&取地址符号。

posted on 2014-02-17 23:31  Practicer..  阅读(392)  评论(0编辑  收藏  举报

导航