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
Ïà¹ØÎĵµ£º
¡¡¡¡ ¶àÏ̳߳ÌÐòÉè¼ÆµÄ¸ÅÄîÔçÔÚÁùÊ®Äê´ú¾Í±»Ìá³ö£¬µ«Ö±µ½°ËÊ®Äê´úÖÐÆÚ£¬UnixϵͳÖвÅÒýÈë¶àÏ̻߳úÖÆ£¬Èç½ñ£¬ÓÉÓÚ×ÔÉíµÄÐí¶àÓŵ㣬¶àÏ̱߳à³ÌÒѾµÃµ½Á˹㷺µÄÓ¦Óᣱ¾ÎÄÎÒÃǽ«½éÉÜÔÚLinuxϱàд¶à½ø³ÌºÍ¶àÏ̳߳ÌÐòµÄһЩ³õ²½ÖªÊ¶¡£
------------------------------------------------------------------------ ......
¹À¼ÆÊDZ»¹¥»÷ÁË£¬¹ý¸ö¼ÙÆÚssh¾ÍÁ¬½Ó²»ÉÏÁË£¬Ô¶³ÌÁ¬½ÓÌáʾ network refused¡£Ö»ÄÜÅܵ½»ú·¿¿´¸ö¾¿¾¹£¬Ê×ÏÈÓôó¼ÒµÄÐ޸ķ½Ê½£º
LinuxÏÂSSHĬÈÏ22¶Ë¿ÚµÄÐ޸ķ½·¨ÈçÏÂ:
NO 1£º
01¼ÙÈçÒª¸ÄSSHµÄĬÈ϶˿ڣ¨22£©£¬ÄÇôÄãÖ»ÒªÐ޸ģº/etc/ssh/sshd_configÖÐPort 22£¬ÕâÀï°Ñ22¸Ä³É×Ô¼ºÒªÉèµÄ¶Ë¿Ú¾ÍÐÐÁË£¬²»¹ýǧÍò±ðÉèºÍÏÖÒÑÓеĶ ......
ÉèÖÃdsnºóËäÈ»ÐéÄâ»ú¿ÉÒÔÉÏÍøÁË£¬µ«ÊÇÓû§Ãû±ä³ÉÁËbogon£¬¶ø²»ÊÇ֮ǰµÄlocalhost£¬È¥µôDNSºóÖØÆôÐéÄâ»ú¾ÍÓÖ±ä³ÉÁËlocalhost
È»ºó¾Í¿ÉÒÔmount±¾»úÁË
»¹ÓÐÒ»ÖÖ·½·¨£º
hostname ÏÔʾµ±Ç°Ö÷»úÃû
hostname localhost ÉèÖõ±Ç°Ö÷»úÃûΪlocalhost
¹À¼ÆÒ²¿ÉÒÔ½â¾öÉÏÊö²»ÄÜmountµÄÎÊÌâ¡£ ......