|
|||||||||||
| 技術(shù)交流 | 電路欣賞 | 工控天地 | 數(shù)字廣電 | 通信技術(shù) | 電源技術(shù) | 測控之家 | EMC技術(shù) | ARM技術(shù) | EDA技術(shù) | PCB技術(shù) | 嵌入式系統(tǒng) 驅(qū)動編程 | 集成電路 | 器件替換 | 模擬技術(shù) | 新手園地 | 單 片 機 | DSP技術(shù) | MCU技術(shù) | IC 設(shè)計 | IC 產(chǎn)業(yè) | CAN-bus/DeviceNe |
GCC高手們,請給我一個合理的解釋好嗎? |
| 作者:BitFu 欄目:單片機 |
同樣的代碼 ICC編譯后736字節(jié) (版本icc avr 6.30 45天試用版) GCC編譯后1652字節(jié) (版本winavr 20030310 ) 在硬件上運行結(jié)果相同。 gcc優(yōu)化級為 s 結(jié)果讓我十分苦惱 我實在不愿看到這個結(jié)果(心愛的GCC你不會是和我開玩笑呢吧!)。 就算插入初始化代碼也不至于將近1K(單片機一共沒多少K呀)吧! GCC高手們,請給我一個合理的解釋好嗎? 代碼點下面鏈接下載后把擴展名改成RAR后解壓縮。 http://www.21icsearch.com/buzi/upimage/upfile/2004422923170.jpg |
| 2樓: | >>參與討論 |
| 作者: BitFu 于 2004/4/22 9:49:00 發(fā)布:
這里下 http://bitfu.go.nease.net/temp/code.rar |
|
| 3樓: | >>參與討論 |
| 作者: 笑蒼天 于 2004/4/22 11:18:00 發(fā)布:
你的程序好像沒用到printf函數(shù) 所以可以修改一下鏈接編譯選項 你的Makefile中 # Optional linker flags. LDFLAGS = -Wl,-Map=$(TARGET).map,--cref,-u,vfprintf -lprintf_min 改為 # Optional linker flags. LDFLAGS = -Wl,-Map=$(TARGET).map,--cref # Additional libraries # # Minimalistic printf version #LDFLAGS += -Wl,-u,vfprintf -lprintf_min # # Floating point printf version (requires -lm below) #LDFLAGS += -Wl,-u,vfprintf -lprintf_flt # # -lm = math library #LDFLAGS += -lm 可視情況添加或刪減鏈接庫文件 試試看,程序代碼量應該會大大減少,比ICC少很多 (我沒試,暫時不用AVR,所以機子沒裝WinAvr) |
|
| 4樓: | >>參與討論 |
| 作者: yfzhang 于 2004/4/22 12:56:00 發(fā)布:
我換了makefile 編譯后為510字節(jié) #makefile如下: # WinAVR SAMPLE makefile written by Eric B. Weddington, Jörg Wunsch, et al. # Released to the Public Domain # Please read the make user manual! # # # On command LINE: # # make all = Make SOFTWARE. # # make clean = Clean out built project files. # # make coff = Convert ELF to AVR COFF (for use with AVR Studio 3.x or VMLAB). # # make extcoff = Convert ELF to AVR Extended COFF (for use with AVR Studio # 4.07 or greater). # # make program = Download the hex file to the DEVICE, using avrdude. Please # customize the avrdude settings below first! # # make fileNAME.s = Just compile fileNAME.c into the assembler code ONLY # # To rebuild project do "make clean" then "make all". # #============= MCUÑ¡Ôñ =========================== # MCU NAME MCU = AT90S8535 #============= Êä³ö¸ñʽѡÔñ ====================== # OUTPUT format. (can be srec, ihex, binary) FORMAT = ihex #============= Ä¿±êÎļþÃû(²»´øÀ©Õ¹Ãû) ============ # Target file NAME (without extension). TARGET = DEMO #============= ÓÅ»¯¼¶±ðÑ¡Ôñ ====================== # Optimization level, can be [0, 1, 2, 3, s]. 0 turns off optimization. # (Note: 3 is not always the best optimization level. See avr-libc FAQ.) OPT = s #============= C Ô´ÎļþÁбí("\"Ϊ»»ÐзûºÅ) ======= # List C source files here. (C dependencies are automatically generated.) SRC = $(TARGET).c # If there is more than one source file, append them above, or adjust and # uncomment the following: #SRC += foo.c bar.c # You can also wrap LINEs by appending a backslash to the end of the LINE: #SRC += baz.c \ #xyzzy.c #============= ASM Ô´ÎļþÁбí ==================== # List Assembler source files here. # Make them always end in a capital .S. Files ending in a lowercase .s # will not be considered source files but generated files (assembler # OUTPUT from the compiler), and will be deleted upon "make clean"! # Even though the DOS/Win* filesystem matches both .s and .S the same, # it will preserve the spelling of the fileNAMEs, and gcc itself does # care about how the NAME is spelled on its command-LINE. ASRC = #============= C±àÒëÑ¡Ïî ========================= # Optional compiler flags. # -g: generate debugging information (for GDB, or for COFF conversion) # -O*: optimization level # -f...: tuning, see gcc manual and avr-libc documentation # -Wall...: warning level # -Wa,...: tell GCC to pass this to the assembler. # -ahlms: create assembler listing CFLAGS = -g -O$(OPT) \ -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums \ -Wall -Wstrict-prototypes \ -Wa,-ahlms=$(<:.c=.lst) #============= »ã±àÆ÷Ñ¡Ïî ======================== # Optional assembler flags. # -Wa,...: tell GCC to pass this to the assembler. # -ahlms: create listing # -gstabs: have the assembler create LINE NUMBER information; note that # for use in COFF files, additional information about fileNAMEs # and function NAMEs needs to be present in the assembler source # files -- see avr-libc docs [FIXME: not yet described there] ASFLAGS = -Wa,-ahlms=$(<:.S=.lst),-gstabs #============= Á¬½ÓÆ÷Ñ¡Ïî ======================== # Optional linker flags. # -Wl,...: tell GCC to pass this to linker. # -Map: create map file # --cref: add cross reference to map file LDFLAGS = -Wl,-Map=$(TARGET).map,--cref #============= ¸½¼Ó¿âÑ¡Ïî ======================== # Additional libraries # # Minimalistic printf version #LDFLAGS += -Wl,-u,vfprintf -lprintf_min # # Floating point printf version (requires -lm below) #LDFLAGS += -Wl,-u,vfprintf -lprintf_flt # # -lm = math library LDFLAGS += -lm # PROGRAMMING SUPPORT using avrdude. Settings and variables. # PROGRAMMING HARDWARE: AVRISP STK500 avr910 pavr stk200 pony-stk200 # dt006 bascom alf # Type: avrdude -c ? # to get a full listing. # AVRDUDE_PROGRAMMER = STK500 AVRDUDE_PORT = com1 # programmer connected to serial DEVICE #AVRDUDE_PORT = lpt1 # programmer connected to parallel port AVRDUDE_ERASE = -e AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) # Uncomment the following if you want avrdude's erase cycle counter. # Note that this counter needs to be initialized first using -Yn, # see avrdude manual. #AVRDUDE_ERASE += -y # # Uncomment the following if you do /not/ wish a verification to be # performed after PROGRAMMING the DEVICE. #AVRDUDE_FLAGS += -V # # Increase verbosity level. Please use this when submitting bug # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> # to submit bug reports. #AVRDUDE_FLAGS += -v -v # --------------------------------------------------------------------------- #============= Ö¸¶¨Ä¿Â¼£¬Èç¹ûÐèÒª ================ # Define directories, if needed. DIRAVR = c:/winavr DIRAVRBIN = $(DIRAVR)/bin DIRAVRUTILS = $(DIRAVR)/utils/bin DIRINC = . DIRLIB = $(DIRAVR)/avr/lib #============= ¶¨ÒåÃüÁî(¹¤¾ßÈí¼þÃû³Æ) ============ # Define programs and commands |
|
| 5樓: | >>參與討論 |
| 作者: BitFu 于 2004/4/22 15:47:00 發(fā)布:
確實是這樣 感謝 笑蒼天、yfzhang。 我也試過了,那個MAKEFILE是WINAVR里的示例,改時沒有注意。 我很抱歉,GCC及它的愛好者們! |
|
|
|
| 免費注冊為維庫電子開發(fā)網(wǎng)會員,參與電子工程師社區(qū)討論,點此進入 |
Copyright © 1998-2006 m.58mhw.cn 浙ICP證030469號 |