Linux Assembly "Hello World" Tutorial, CS 200
by Bjorn Chambless
Introduction
The following is designed familiarize the reader with programming in x86 (AT&T
style, that produced by gcc) assembly under Linux and how to interface assembly
and higher-level language code (i.e. C). The tutorial will also briefly cover
debugging your assembly using GDB.
This tutorial requires the following:
an i386 family PC running Linux
GCC, the GNU C-compiler
GDB, the GNU debugger command line debugger
The tutorial was developed on and tested with GCC version 2.95.4 and GDB 19990928 under Linux kernel 2.4.9
I highly recommend working through this tutorial with
"as"
and "gdb"
documentation close at hand.
Source Code
The process begins with a source code program. For example, hello.c
/* hello.c */
#include
main()
{
printf("hello\n").
}
which, when compiled and executed, prints a message
linuxbox> gcc -o hello hello.c
linuxbox> ./hello
hello
The actual compilation process can be viewed by including the -v
option
linuxbox> gcc -v -o hello hello.c
Reading specs from /usr/lib/gcc-lib/i386-linux/2.95.4/specs
gcc version 2.95.4 20010902 (Debian prerelease)
/usr/lib/gcc-lib/i386-linux/2.95.4/cpp0 -lang-c -v -D__GNUC__=2
-D__GNUC_MINOR__=95 -D__ELF__ -Dunix -D__i386__ -Dlinux -D__ELF__
-D__unix__ -D__i386__ -D__linux__ -D__unix -D__linux -Asystem(posix)
-Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ hello.c
/tmp/ccCGCFmG.i
GNU CPP version 2.95.4 20010902 (Debian prerelease) (i386 Linux/ELF)
#include "..." search starts here:
#include <...> search starts here: /usr/local/include
/usr/lib/gcc-lib/i386-linux/2.95.4/include /usr/include
End of search list.
The following default directories have been omitted from the search
path: /usr/lib/gcc-lib/i386-linux/2.95.4/../../../../include/g++-3
/usr/lib/gcc-lib/i386-linux/2.95.4/../../../../i386-linux/include
End of omitted list. /usr/lib/gcc-lib/i386-linux/2.95.4/cc1
/tm
相关文档:
=== 6 体系Makefile文件
在开始进入各个目录编译之前,顶层Makefile文件设置编译环境和做些准备工作。顶层Makefile文件包含通用部分,arch/$(ARCH) /Makefile包含该体系架构所需的设置。因此arch/$(ARCH)/Makefile会设置一些变量和少量的目标。
当编译时将按照以下大概步骤执行:
1) 配置内核 => 产生 .config文件
......
<!--
@page { margin: 2cm }
P { margin-bottom: 0.21cm }
-->
在本文中,
Linux
是指草根版的
Linux
,也就是说,
Linux
是正宗的
GNU/Linux
。现在的问题是,在中国,为什么
GNU/Linux
要远离硬盘?这是什么原因造成的?
......
操作系统的一个经典问题是"生产者-消费者"问题, 这涉及同步信号量和互斥信号量的应用, 在这里,我用线程的同步和互斥来实现.
/*
* author 张文
* 2008/06/20
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <semaphore.h> ......
#include <iostream>
#include <pwd.h>
#include <sys/types.h>
#include <stddef.h>
#include <string>
#include <list>
using namespace std;
void GetUser(list<string>& lsUser);
int main()
{
list<string> lsUser;
GetUser(lsUser);
cout <&l ......
在Linux 中,动态库的搜索路径除了默认的搜索路径外,还可通过三种方法来指定:方法一:在配置文件/etc/ld.so.conf中指定动态库搜索路径;方法二:通过环境变量LD_LIBRARY_PATH指定动态库搜索路径;方法三:在编译目标代码时指定该程序的动态库搜索路径。
众所周知,Linux动态库的默认搜索路径是/lib和/usr/lib。动态库被 ......