自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

“C語言” 讀書札記之[編譯執(zhí)行]

開發(fā) 前端
C語言的好處是各種體系結(jié)構(gòu)的計(jì)算機(jī)都有各自的C編譯器,可以把C程序編譯成各種不同體系結(jié)構(gòu)的機(jī)器指令,這意味著用C語言寫的程序只需稍加修改甚至不用修改就可以在各種不同的計(jì)算機(jī)上編譯運(yùn)行。

介紹

現(xiàn)在C語言跨的領(lǐng)域非常之多,如游戲、嵌入式、智能電器等。為什么不直接用匯編或機(jī)器語言直接寫呢?原因是匯編和機(jī)器語言受到計(jì)算機(jī)體系結(jié)構(gòu)的影響。直接用某種體系結(jié)構(gòu)的匯編或機(jī)器指令寫出來的程序只能在這種體系結(jié)構(gòu)的計(jì)算機(jī)上運(yùn)行。

C語言的好處是各種體系結(jié)構(gòu)的計(jì)算機(jī)都有各自的C編譯器,可以把C程序編譯成各種不同體系結(jié)構(gòu)的機(jī)器指令,這意味著用C語言寫的程序只需稍加修改甚至不用修改就可以在各種不同的計(jì)算機(jī)上編譯運(yùn)行。

hello,world

我們從簡(jiǎn)單hello,world開始——有人說了,又來了,這個(gè)“hello,world”,好多博友都寫這種東西煩不煩?呵呵,那我寫的也許跟他們說的不一樣呢?或者理解的跟別人有不一樣的地方。

先寫個(gè)程序我們看看。

源程序(或者源文件):是程序員通過文本編輯器創(chuàng)建并保存的文本文件。源程序?qū)嶋H就是由0和1組成的位序列,這些位8個(gè)一組,成為字節(jié),每個(gè)字節(jié)通過ASCII字符集(大部分是)對(duì)應(yīng)一個(gè)文本字符。

 [[80334]]下面是上面程序?qū)?yīng)的16進(jìn)制數(shù)字表示

 [[80334]] 在終端輸入man ascii看看ascii表

#p#

操作步驟:

[[80334]]

 [[80334]]查看16進(jìn)制格式

  [[80334]]回復(fù)到文本格式

  [[80334]]我們看看對(duì)應(yīng)的二進(jìn)制是什么樣的?——這個(gè)也是在磁盤中的存儲(chǔ)狀態(tài)。

總結(jié):

系統(tǒng)中所有的信息——包括磁盤文件、存儲(chǔ)器中的程序,存儲(chǔ)器中存放的用戶數(shù)據(jù)以及網(wǎng)絡(luò)上傳送的數(shù)據(jù),都是由一串比特表示的。

思考:

同樣的一套字節(jié)序列可能在不同的上下文中表示一個(gè)整數(shù)、浮點(diǎn)數(shù)、字符串或者機(jī)器指令。——這取決于數(shù)據(jù)對(duì)象的上下文。

我們?cè)撟鍪裁矗?/p>

做為程序員,我們需要了解數(shù)字的機(jī)器表示方式,因?yàn)樗鼈兣c常見的整數(shù)和實(shí)數(shù)是不同的。

使用參考:在Linux下使用vim配合xxd查看并編輯二進(jìn)制文件

#p#

翻譯

源程序是能夠被人讀懂的,為了能在系統(tǒng)上運(yùn)行,我們需要把C語句通過其他程序轉(zhuǎn)化為一系列的低級(jí)機(jī)器語言指令。然后這些指令按照一種稱為“可執(zhí)行目標(biāo)程序“的格式打包好,并以二進(jìn)制磁盤文件的形式存放起來。

在Linux系統(tǒng)上,從源文件到目標(biāo)文件(可執(zhí)行目標(biāo)程序文件)的轉(zhuǎn)化是由編譯器驅(qū)動(dòng)程序完成的。如下圖:

編譯系統(tǒng)

我們用GCC工具觀察每個(gè)階段。(GCC:GNU Compiler Collection,GNU編譯器套裝)

先贈(zèng)送一張gcc命令選項(xiàng)圖

 [[80337]]

預(yù)處理階段

[[80334]]查看main.i的部分源碼

總結(jié):預(yù)處理器(cpp)根據(jù)以字符#開頭的命令,修改原始C程序,結(jié)果得到了另一個(gè)C程序(還是C程序),通常以i做為文件擴(kuò)展名。

編譯階段

 [[80334]]查看main.s的源碼

總結(jié):將C語言文本文件翻譯成匯編語言文本文件。——匯編語言是非常有用的,因?yàn)樗鼮椴煌呒?jí)語言的不同編譯器提供了通用的輸出語言。

匯編階段

 [[80334]]打開源代碼,注意此時(shí)為二進(jìn)制磁盤文件,還有注意操作步驟

[[80334]]此時(shí)為亂碼,需要進(jìn)行:%!xxd操作

[[80334]]查看指令

總結(jié):匯編器(as)將main.s翻譯成機(jī)器語言指令,把這些指令打包成為一種“可重定位目標(biāo)程序“的格式,并將結(jié)果保存到main.o文件中,main.o是二進(jìn)制文件,它的字節(jié)編碼是機(jī)器語言指令而不是字符(所以用文本編譯器看會(huì)出現(xiàn)亂碼)。

鏈接階段

  [[80334]]按照匯編階段操作,查看部分指令碼

總結(jié):程序中調(diào)用了printf函數(shù),它是C標(biāo)準(zhǔn)庫的一個(gè)函數(shù),printf函數(shù)存在于一個(gè)名為printf.o的單獨(dú)的預(yù)編譯目標(biāo)文件中。連接器(ld)負(fù)責(zé)把printf.o的預(yù)編譯目標(biāo)文件進(jìn)行并入,結(jié)果就得到a.out文件。

NOTE:a.out是可執(zhí)行的目標(biāo)文件,而main.o是可重定位目標(biāo)程序文件。——可執(zhí)行目標(biāo)文件加載到系統(tǒng)存儲(chǔ)器后,由系統(tǒng)負(fù)責(zé)執(zhí)行。而可重定位目標(biāo)程序文件是提供給鏈接器使用,執(zhí)行并入操作。

總結(jié)

這一篇主要是學(xué)習(xí)gcc編譯器的編譯過程,對(duì)整個(gè)過程有所熟悉。如果有好的知識(shí)點(diǎn),望大家賜教。

#p#

vim配置分享

  1. " An example for a vimrc file.  
  2. "  
  3. " Maintainer:   Bram Moolenaar <Bram@vim.org>  
  4. " Last change:  2006 Nov 16  
  5. "  
  6. " To use it, copy it to  
  7. "     for Unix and OS/2:  ~/.vimrc  
  8. "         for Amiga:  s:.vimrc  
  9. "  for MS-DOS and Win32:  $VIM\_vimrc  
  10. "       for OpenVMS:  sys$login:.vimrc  
  11.  
  12. " When started as "evim", evim.vim will already have done these settings.  
  13. if v:progname =~? "evim" 
  14.   finish  
  15. endif  
  16.  
  17. " Use Vim settings, rather then Vi settings (much better!).  
  18. " This must be first, because it changes other options as a side effect.  
  19. set nocompatible  
  20.  
  21. " allow backspacing over everything in insert mode  
  22. set backspace=indent,eol,start  
  23.  
  24. if has("vms")  
  25.   set nobackup      " do not keep a backup file, use versions instead  
  26. else 
  27.   set nobackup      " keep [NO] backup file  
  28. endif  
  29. set history=250     " keep 250 lines of command line history  
  30. set ruler       " show the cursor position all the time  
  31. set showcmd     " display incomplete commands  
  32. set incsearch      " do incremental searching  
  33. set nu  
  34.  
  35. " For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries  
  36. " let &guioptions = substitute(&guioptions, "t", "", "g")  
  37.  
  38. " Don't use Ex mode, use Q for formatting  
  39. map Q gq  
  40.  
  41. " In many terminal emulators the mouse works just fine, thus enable it.  
  42. set mouse=a  
  43.  
  44. " Switch syntax highlighting on, when the terminal has colors  
  45. " Also switch on highlighting the last used search pattern.  
  46. if &t_Co > 2 || has("gui_running")  
  47.   syntax on  
  48.   set hlsearch  
  49. endif  
  50.  
  51. " Only do this part when compiled with support for autocommands.  
  52. if has("autocmd")  
  53.  
  54.   " Enable file type detection.  
  55.   " Use the default filetype settings, so that mail gets 'tw' set to 72,  
  56.   " 'cindent' is on in C files, etc.  
  57.   " Also load indent files, to automatically do language-dependent indenting.  
  58.   filetype plugin indent on  
  59.  
  60.   " Put these in an autocmd group, so that we can delete them easily.  
  61.   augroup vimrcEx  
  62.   au!  
  63.  
  64.   " For all text files set 'textwidth' to 78 characters.  
  65.   autocmd FileType text setlocal textwidth=78  
  66.  
  67.   " When editing a file, always jump to the last known cursor position.  
  68.   " Don't do it when the position is invalid or when inside an event handler  
  69.   " (happens when dropping a file on gvim).  
  70.   autocmd BufReadPost *  
  71.     \ if line("'\"") > 0 && line("'\"") <= line("$") |  
  72.     \   exe "normal! g`\"" |  
  73.     \ endif  
  74.  
  75.   autocmd VimLeave *  
  76.     \ if has("mksession") && exists("v:this_session") && v:this_session != "" |  
  77.     \   exec "mksession!" v:this_session |  
  78.     \ endif  
  79.  
  80.   augroup END  
  81.  
  82. else 
  83.  
  84.   set autoindent        " always set autoindenting on  
  85.  
  86. endif " has("autocmd")  
  87.  
  88. " Convenient command to see the difference between the current buffer and the  
  89. " file it was loaded from, thus the changes you made.  
  90. command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis  
  91.         \ | wincmd p | diffthis  
  92.  
  93. " Add by Journeylee to make things more easily  
  94. set softtabstop=4  
  95. set shiftwidth=4  
  96. set tabstop=4  
  97. set noexpandtab  
  98. set smarttab  
  99. set showmatch  
  100. set foldenable  
  101. set autoindent  
  102. set smartindent  
  103. set cindent  
  104. set foldmethod=marker  
  105. set background=dark  
  106. set nobackup  
  107. set encoding=utf-8  
  108. language en_US.utf8  
  109. set fileencodings=ucs-bom,utf-8,gbk,latin1  
  110. set fileformats=unix,dos,mac  
  111. set fileencoding=utf-8  
  112. set fileformat=unix  
  113.  
  114. set fileformat=unix  
  115. set matchtime=15  
  116.  
  117. " Make shift-insert work like in Xterm  
  118. map <S-Insert> <MiddleMouse>  
  119. map! <S-Insert> <MiddleMouse>  
  120.  
  121. " let xterm16_brightness = 'default'     " Change if needed  
  122. " let xterm16_colormap = 'allblue'       " Change if needed  
  123. " colo xterm16   
  124. "不使用swap文件  
  125. map <F5> :!php -l %<CR>  
  126. "set runtimepath+=/home/zhoubc/opt/vim/doc  
  127. "autocmd BufNewFile,Bufread *.ros,*.inc,*.php set keywordprg="help"  
  128.  
  129. let g:winManagerWindowLayout='TagList|FileExplorer' 
  130. let g:winManagerWidth=30  
  131. nmap  wm :WMToggle 

【編輯推薦】

  1. “C語言” 讀書札記之[程序和編程語言]
  2. 淺談前端開發(fā)的水有多深
責(zé)任編輯:張偉 來源: 川山甲的博客
相關(guān)推薦

2012-06-25 10:14:10

C語言

2012-06-23 18:13:39

C語言

2012-07-12 14:06:10

C語言

2012-06-28 10:38:45

Web

2012-06-20 15:01:04

Web

2013-09-03 09:35:10

2009-08-25 16:32:24

C#語言

2009-08-26 17:22:09

C#語言

2010-05-06 10:01:26

nginx負(fù)載均衡

2023-11-08 13:17:00

Python解釋型語言

2010-02-03 17:29:06

Python編譯

2010-01-18 09:39:25

C++語言

2015-03-10 14:05:46

程序員軟件架構(gòu)讀書筆記

2022-07-11 10:45:37

插樁性能優(yōu)化打包

2009-06-11 14:11:33

代碼混淆Java反編譯

2010-02-25 10:46:44

Linux操作系統(tǒng)

2009-09-28 09:32:01

編譯語言C#

2010-08-27 13:07:00

CSS規(guī)則

2009-12-22 02:48:23

COBOL語言Grace Hoppe編譯語言

2010-08-03 09:57:55

Linux Deepi
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)