/* linux version of AVTEMP.ASM CS 200, fall 1998 */
.data /* beginning of data segment */
/* hi_temp data item */
.type hi_temp,@object /* declare as data object */
.size hi_temp,1 /* declare size in bytes */
hi_temp:
.byte 0x92 /* set value */
/* lo_temp data item */
.type lo_temp,@object
.size lo_temp,1
lo_temp:
.byte 0x52
/* av_temp data item */
.type av_temp,@object
.size av_temp,1
av_temp:
.byte 0
/* segment registers set up by linked code */
/* beginning of text(code) segment */
.text
.align 4 /* set 4 double-word alignment */
.globl main /* make main global for linker */
.type main,@function /* declare main as a function */
main:
pushl %ebp /* function requirement */
movl %esp,%ebp /* function requirement */
movb hi_temp,%al
addb lo_temp,%al
movb $0,%ah
adcb $0,%ah
movb $2,%bl
idivb %bl
movb %al,av_temp
leave /* function requirement */
ret /* function requirement */
This code may be assembled with the following command:
as -a --gstabs -o average.o average.s
The link command is the following:
"-m elf_i386" instructs the linker to use the ELF file format. "-static" cause static rather than dynamic linking to occur. And "-lc" links in the standard c libraries (libc.a). It might be necessary to include "-I/libdirectory" in the invocation for ld to find the c library.
The object file (average.o) can then be linked to the Linux wrapper code in order to create an executable. These files are crt1.o, crti.o and crtn.o. crt1.o and crti.o provide initialization code and crtn.o does cleanup. These should all be located in "/usr/lib" be may be elsewere on some systems. They, and their source, might be located by executing the following find command:
本文介绍了Linux下的链接命令,如ld -m elf_i386 -static /usr/lib/crt1.o /usr/lib/crti.o -lc average.o /usr/lib/crtn.o ,说明了各参数作用,如'-m elf_i386'指定ELF文件格式,'-static'实现静态链接等。还提到将目标文件average.o与Linux包装代码链接生成可执行文件,以及查找相关文件的方法。
2033

被折叠的 条评论
为什么被折叠?



