我編譯在Debian喘息以下彙編程序運行,但它不會跑給我的錯誤:二進制不是Debian的喘息
-bash:./power:不能執行二進制文件
代碼
.section data
.section text
.global _start
_start:
# do first calc and save the answer
pushl $3
pushl $2
call power
addl $8, %esp
pushl %eax
# do second calc
pushl $2
pushl $5
call power
addl $8, %esp
# add both together
popl %ebx
addl %eax, %ebx
# exit with answer as return status
movl $1, %eax
int $0x80
.type power, @function
power:
# ?
pushl %ebp
movl %esp, %ebp
subl $4, %esp
# load params
movl 8(%ebp), %ebx
movl 12(%ebp), %ecx
movl %ebx, -4(%ebp)
power_loop_start:
# have we looped down to 1?
cmpl $1, %ecx
je end_power
# multiply prev result by base and store
movl -4(%ebp), %eax
imull %ebx, %eax
movl %eax, -4(%ebp)
# go again
decl %ecx
jmp power_loop_start
end_power:
movl -4(%ebp), %eax
movl %ebp, %esp
popl %ebp
ret
我奔跑着:
as power.s -o power.o
ld power.o -o power
./power
兩個uname -m
和arch
給我i686的,和二進制輸出這對objdump -x
:
$ objdump -x power
power: file format elf32-i386
power
architecture: i386, flags 0x00000012:
EXEC_P, HAS_SYMS
start address 0x00000000
Sections:
Idx Name Size VMA LMA File off Algn
0 text 0000004a 00000000 00000000 00000034 2**0
CONTENTS, READONLY
SYMBOL TABLE:
00000000 l d text 00000000 text
00000023 l F text 00000000 power
00000032 l text 00000000 power_loop_start
00000043 l text 00000000 end_power
00000000 g text 00000000 _start
08049034 g *ABS* 00000000 __bss_start
08049034 g *ABS* 00000000 _edata
08049034 g *ABS* 00000000 _end
不知道我做錯了。
其他備註:
本例來自「從頭開始編程」一書。我試過一個紅帽x86_64機器,as
標誌--32
和ld
標誌-m elf_i386
,它所有的編譯就像在x86機器上一樣,但是執行時會給出相同的錯誤。
你有一個錯字:'.section text'應該是'.section .text'(注意點)或者只是'.text'。 – Jester
@Jester哇,我希望我能投票給你100次。我一直在試圖弄清楚這一點。文本和數據都沒有點!我希望編譯器抱怨... – sprocket12