32位绝对地址超出范围

时间:2013-09-06 02:38:59

标签: assembly

我是汇编语言的新手。现在我正在编写我的'hello,world'.s程序。

代码来自Richard Blum的“Professional Assembly Language”一书:

        ;; #cpuid.s Sample program to extract the processor Vendor ID

.section .data,
output:
    .ascii "The processor vendor is 'xxxxxxxxxx'\n"

.section .bbs,

.section .text,
.globl _main
_main:  
    movl $0, %eax
    ;; cpuid
    ;; movl $output, %edi
    ;; movl %ebx, 28(%edi)
    ;; movl %edx, 32(%edi)
    ;; movl %ecx, 36(%edi)
    ;; movl $4, %eax
    ;; movl $1, %ebx
    ;; movl $output, %ecx
    ;; movl $output, %ecx
    ;; movl $42, %edx
    ;; int $0x80
    ;; movl $1, %eax
    ;; movl $0, %ebx
    ;; int $0x80

本书指示使用'as'和'ld'编译,但我没有使用它们。 那我用gcc: gcc -o cpuid cpuid.s,但仍然得到错误:

****:asm $ls
cpuid.s
****:asm $gcc -o cpuid cpuid.s 
final section layout:
    __TEXT/__text addr=0x100000F58, size=0x0000003C, fileOffset=0x00000F58, type=1
    __TEXT/__stubs addr=0x100000F94, size=0x00000006, fileOffset=0x00000F94, type=27
    __TEXT/__stub_helper addr=0x100000F9C, size=0x0000001A, fileOffset=0x00000F9C, type=31
    __TEXT/__unwind_info addr=0x100000FB6, size=0x00000048, fileOffset=0x00000FB6, type=21
    __DATA/__program_vars addr=0x100001000, size=0x00000028, fileOffset=0x00001000, type=29
    __DATA/__nl_symbol_ptr addr=0x100001028, size=0x00000010, fileOffset=0x00001028, type=28
    __DATA/__la_symbol_ptr addr=0x100001038, size=0x00000008, fileOffset=0x00001038, type=26
    __DATA/__common addr=0x100001040, size=0x00000020, fileOffset=0x00000000, type=24
    .data/ addr=0x100002000, size=0x00000025, fileOffset=0x00002000, type=0
    .text/ addr=0x100003000, size=0x0000003F, fileOffset=0x00003000, type=0
ld: 32-bit absolute address out of range (0x100002000 max is 4GB): from _main + 0x00000028 (0x100003000) to output (0x100002000) in _main from /var/folders/p2/s66vmvlx0vxc7svvwtjfnjb80000gn/T//ccKx07kO.o for architecture x86_64
collect2: ld returned 1 exit status
****:asm $

我的环境是: mac os 10.7,64bit

****:asm $uname -a
Darwin **** 11.4.2 Darwin Kernel Version 11.4.2: Thu Aug 23 16:25:48 PDT 2012; root:xnu-1699.32.7~1/RELEASE_X86_64 x86_64
****:asm $

你能帮我编译一下这段代码吗?

0 个答案:

没有答案