版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
$gcc- Thiswillproduceafile n:theoptimization$gcc–S-
main; .rdata,
o
$0, $0, .def_exit;.scl3;.type32;.def_printf;.scl3;.type32;
_main;%esp,$8,$-16,$0,$15,$15,$4,$4,%eax,--4(%ebp),
gccgcc- alloca main
$LC0, main;
.rdata, o
_main;%esp,$8,$-16,$0,$15,$15,$4,$4,%eax,--4(%ebp),
gccgcc- alloca main
$0,
$LC0,
.def_exit;.scl3;.type32;.def_printf;.scl3;.type32; main;
.rdata, oworld\12\0”.globl
_main;
$16,
%esp,$8, gcc- oworld.c- $-16, alloca 版本3.4.4(32位) main $LC0, $0, "o
_main;
$16,%esp,$8,$-16,$LC0,$0,匯編代碼中以“.”開頭的行都是匯編代碼中以“.”開頭的行都是匯編指示(Directives),如“.file”def”text main; #.defdirectivesdefinesadebugging#.scl2meansstorageclass(externalstorageclass)#.type32saysthissymbolisafunction.
地址的符號(hào)(Symbol)示例示例指示匯編器符號(hào)“_main”是全局的,這樣同一程序的其它模塊可它則則不是全局可見.p2align#指定下一行代碼的對齊方式:第1參數(shù)表示按2的多少次冪第216.section.rdata,.ascii o.globl.align1請嘗試解釋一下intc1局變
oworld.c main; .ascii o.p2align.globl
#1615字節(jié),則不對齊 _main; $16,%esp,$8,$-16,$LC0,$0,_puts; _exit; oworld.c "o.p2align.globl
#1615字節(jié),則不對齊
%esp,$4,
關(guān)#分配4字節(jié)堆棧關(guān)
gcc-O2-mpreferred- main
oworld.c-
$LC0,$0,
oworld.c main;
.ascii o
#1615關(guān)oworld.c關(guān)oworld.c-gcc-O2-mpreferred-stack-boundary=2-fomit-$4,$LC0,$0,charbig_array[1<<24];/*16MBcharhuge_array[1<<28];/*256MB char*p1,*p2,*p3,intuseless(){return0;int{p1=malloc(1<<28);p2=malloc(1<<8);p3=malloc(1<<28);p4=malloc(1<<8);
/*256MB/*256B/*256MB/*256B/*Someprintstatements...}finalmalloc()
&p2finalmalloc()
addressrange &p2 as-omy-object- //ld–omy-exe-filemy-object-64位環(huán)境下添加命令行參數(shù):-moworld
len
o $len,
$msg,$1,$4,$0,$1,
#系統(tǒng)輸出(writeint80寄存器eax中存放的是系統(tǒng)調(diào)用的功能號(hào),而傳給系統(tǒng)調(diào)用的數(shù)則必須按順序放到寄存器ebx,ecx,edx,esi,edi中當(dāng)系統(tǒng)調(diào)用完成之后,返回值可以在寄存器eax中獲需將系統(tǒng)調(diào)用功能號(hào)保存在寄存器eax中,全部參數(shù)依次放在一ebx中保存指向該內(nèi)存區(qū)域系統(tǒng)調(diào)用完成之后,返回值仍將保存在寄存器eax中1(Thiscalldoesnotfork-createchild20intheprocessidofcloneororENOMEMinread-readfromfileor3fileaddressofthebuffertoumnumberofbytesnumberofbytesactually|EAGAIN|EBADF|EFAULTEINTR|EINVAL|EIO|close-closeafileor6filezeroforsuccess|waitpid-waitforaprocessesto7processidoftheprocessto0,oraddressofbuffertoexitoptionflags|0|WNOHANGpidoffinishedprocess||EINVAL|exitstateoffinishedprocess,non-zerovaluewasinputincreate-createa8addressofzero-filepermissionfiledescriptorofopenedfileEACCESS|EEXIST|EFAULTEISDIR|ELOOP|EMFILE,LONG|ENFILEENOENT|ENODEV|ENODIRENOMEM|ENOSPC|ENXIOEROFS|unlink-deleteanameandremovefilewhennotaddressofzero-terminatedpathnameexistingfile0|EACCES|EFAULT|EIO|EISDIR|ELOOP LONG|ENOENT|ENOMEMENOTDIR|EPERM|execve-executeaaddressofzero-terminatedpathnameaddressofzero-terminatedlistofofzero-terminatedargumentaddressofzero-terminatedlistofofzero-terminatedenvironmentIfsuccess,noreturnbecausethenewprograminheritsresourcesandoverwritescaller;otherwise:E2BIG|EACCES|EINVAL|EIO|EISDIR|ELIBBAD|ELOOP|ENFILE|ENOEXEC|ENOENT|ENOMEM|ENOTDIR|EFAULT|ENA LONG|EPERM|chdir-changeworkingaddressofzero-terminatedpathnameexisting0|EACCES|EBADF|EFAULT|EIO|ELOOPLONG|ENOENT|ENOMEM .globl
#
%ecx,%ecx%ecx,%edx,(%ebx),%al,%al$10,-$4,$1,%ebx,
#時(shí),其所需的參數(shù)(argcargv)將sys_write)#文件描述符(stdout)指指 入。EAX寄存器用于決定CPUID指令EAX存器的值,CPUID指令在EBX,ECX和EDX寄存(0)值被EAX寄存器并且執(zhí)行CPUID令時(shí),處理器把廠商ID字符串返回到EBX,EDXECXEBX最低個(gè)字EDX中間個(gè)字ECX最高個(gè)字 "Theprocessvendoridis.sectionm.section
$0,$buffer, %ebx, %edx, %ecx,$as-ocpuid.o
$ld-lc-dynamic-linker/lib/ld-linux.so.2-ocpuid 匯編器使用_start符號(hào)表示默認(rèn)的起始點(diǎn),此外如果想要匯編 ,需要賦予.globl屬性,如:.globl只讀數(shù)據(jù)段一個(gè)數(shù)據(jù)元素時(shí),需要使用Symbol示例如下.ascii o .float 可以在一行中定義多個(gè)值如.int20,10,30,
.32.long32位整數(shù)和int.octa16.quad8.short16.single單精度浮點(diǎn)數(shù)(和float相同和data段不同,無需 特定的數(shù)據(jù)類型,只需 示例如下.sectionmbuffer,#該語句把1000字節(jié)的內(nèi)存地址賦予buffer外部模塊不能相相比較.data段,.bss 的優(yōu)點(diǎn)是.section.data.long.section.globlmovl$0,movldata_items(,%edi,4),%eaxmovl%eax,%ebxcmpl$0,%eaxjeloop_exitincl%edimovldata_items(,%edi,4),%eaxcmpl%ebx,%eaxjlemovl%eax,%ebxjmpstart_loopmovl$1,int
#1istheexit().section #Thesearethedata.long.section.globlmovl$0,%edi #move0intotheindexregistermovldata_items(,%edi,4),%eax#loadthefirstdatamovl%eax, #sincethisisthefirstitem,%eax#thecmpl$0,%eaxjeloop_exit
#start#checktoseeifwe'vehittheincl%edi #loadnextvaluemovldata_items(,%edi,4),%eaxcmpl%ebx,jlemovl%eax,%ebxjmpstart_loop
#compare#jumptoloopbeginningifthe#oneisn't#movethevalueasthelargest#jumptoloopbeginningmovlmovl$1,#1istheexit()int#%ebxisthestatuscodefortheexitsystem #anditalreadyhasthe um 補(bǔ)充:算術(shù)操作指指效描imullR[%edx]:R[%eax]=S*無符號(hào)64位mullR[%edx]:R[%eax]=S*有符號(hào)64位 R[%edx]:R[%eax]=符號(hào)位擴(kuò)展轉(zhuǎn)換為4字idivlR[%edx]=R[%edx]:R[%eax]%R[%eax]=R[%edx]:R[%eax]/divlR[%edx]=R[%edx]:R[%eax]%R[%eax]=R[%edx]:R[%eax]/64位數(shù)通 .section.globlpushlsecondpushlfirstcalltheaddl$8,thestackpointerpushlthefirstpushl$2pushl$5callpoweraddl$8,%esp
#pushsecondargument#pushfirstargument#callthefunction#movethestackpointersecondanswerisin%eax.We%eax,thefirstoutinto%ebxthemtogether;theresultisin%ebxmovl$1,%eax #exit(%ebxisreturned)int$0x80.typepower,@functionpushl%ebpmovl%esp,%ebpsubl$4,%espmovl8(%ebp),%ebxmovl12(%ebp),%ecxmovl%ebx,-
為何還要保存%ebp等操#saveoldbase#makestackpointerthebase#getroomforourlocalstorage#putfirstargumentin%eax#putsecondargumentin%ecx#storecurrentresultcmpl$1,%ecxjeend_power
#ifthepoweris1,wearemovl-4(%ebp),%eax#movethecurrentresultintoimull%ebx, #multiplythecurrentresultbythebasemovl%eax,-4(%ebp)#storethecurrentdecl #decreasethejmppower_loop_start#runforthenextmovl-4(%ebp),%eax#returnvaluegoesinmovl%ebp,popl
#restorethestack#restorethebase.type.typepower, lsthelinkerthatthesymbolpowershouldbetreatedasa階乘.section.globl #thisisunneededunlesswewanttoshare.globlpushlcall
#Thefactorialtakesoneargument–#thenumberwewantafactorialof.#runthefactorialfunction$4,#restorethe%eax,#factorialreturnstheanswerin%eax,but$1,#wantitin%ebxtosenditasourexit#callthekernel’sexitint#Thisistheactualfunction factorial,pushl
%esp,8(%ebp), #Thismovesthefirstargumenttocmpl$1, #Ifthenumberis1,thatisourbasecase,#wesimplyreturn(1isalreadyin%eaxas#returnjedecl #otherwise,decreasethepushl #pushitforourcalltocall #callmovl8(%ebp), #%eaxhasthereturnvalue,sowereload#parameterintoimull%ebx, #multiplythatbytheresultofthelastcall#factorial(in%eax);theanswerisstoredmovl%ebp,%esppopl%ebpStep1:Step2:Step3:如果輸入文件 位置已到文件尾,則轉(zhuǎn)Step7;Step4: Step5:遍歷該內(nèi)容,將其中的小寫字母轉(zhuǎn)換成大寫;Step6:將轉(zhuǎn)換后的該內(nèi)容寫入輸出文件,轉(zhuǎn)Step3;Step7:程序結(jié)束。.equ用于把常量值設(shè)置為可以在程序中使用的.equfactor,.equLINUX_SYS_CALL,經(jīng)過設(shè)置之后,數(shù)據(jù)符號(hào)值是不能在程序中改動(dòng)的#######toupper.s#systemcall.equSYS_OPEN,.equSYS_WRITE,.equSYS_READ,.equSYS_CLOSE,.equSYS_EXIT,#optionsforO_RDONLY,O_PERMISSION,#standardfile.equSTDIN,.equSTDOUT,.equSTDERR,#systemcall.equLINUX_SYSCALL,.equEND_OF_FILE,0#Thisisthereturnvalueofreadwhichmeans#hittheendofthe.section.section#Buffer-thisiswherethedataisloadedintofromthe#fileandwrittenfromintotheoutput.equBUFFER_SIZE,mBUFFER_DATA,.section#STACKST_FD_IN,-ST_FD_OUT,-8ST_ARGC,#NumberofST_ARGV_0,#NameofST_ARGV_1,ST_ARGV_2,#Inputfile#Outputfile.globl###INITIALIZEmovl%esp,subl$ST_SIZE_RESERVE,%esp#Allocatespaceforour$SYS_OPEN,#openST_ARGV_1(%ebp),#inputfilenameinto$O_RDONLY,$O_PERMISSION,intmovl%eax, #savethegivenfilemovl$SYS_OPEN,movlST_ARGV_2(%ebp),
#openthemovl$O_CREAT_WRONLY_TRUNC, #flagsforwritingtothe#modefornewmovl$O_PERMISSION,%edxint$LINUX_SYSCALL#storethefiledescriptorheremovl%eax,ST_FD_OUT(%ebp)###BEGINMAINmovl$SYS_READ,movlST_FD_IN(%ebp),%ebx #gettheinputfiledescriptormovl$BUFFER_DATA,%ecx #thelocationtoreadintomovl$BUFFER_SIZE,%edx #thesizeofthebufferint #Sizeofbufferreadisreturned###EXITIFWE’VEREACHEDTHEcmpl$END_OF_FILE,%eaxjleend_loop
#checkforendoffile#iffoundoronerror,gotothe###CONVERTTHEBLOCKTOUPPERpushlpushlcallpopl%eaxaddl$4,%esp
#locationof#sizeofthe#getthesizeback#restore%esp###WRITETHEBLOCKOUTTOTHEOUTPUTmovl%eax,movl$SYS_WRITE,movlST_FD_OUT(%ebp),%ebxmovl$BUFFER_DATA,%ecxint$LINUX_SYSCALL###CONTINUETHEjmp
#sizeofthe#theoutputfile#locationofthe###CLOSETHEmovl$SYS_CLOSE,movlST_FD_OUT(%ebp),intmovl$SYS_CLOSE,%eaxmovlST_FD_IN(%ebp),%ebxint$LINUX_SYSCALLmovl$SYS_EXIT,movl$0,int#convert_to_upper#INPUT:Thefirstparameteristhelocationoftheblockofmemory#Thesecondparameteristhelengthofthat#OUTPUT:Thisfunctionoverwritesthecurrentbufferwiththe.equLOWERCASE_A,.equLOWERCASE_Z,
#Thelowerboundaryofoursearch#Theupperboundaryofour.equUPPER_CONVERSION,’A’-###STACK.equST_BUFFER_LEN,.equST_BUFFER,
#Lengthof#actualpushl%ebpmovl%esp,%ebp#ifabufferwithzerolengthwasgiventous,justcmpl$0,jemovb(%eax,%edi,1),cmpb$LOWERCASE_A,jlcmpb$LOWERCASE_Z,jg
#getthecurrent#gotothenextbyteunlessit###SET###SETUPmovlST_BUFFER(%ebp),movlST_BUFFER_LEN(%ebp),movl$0,#loop#otherwiseconvertthebytetouppercase,andstoreitaddb$UPPER_CONVERSION,movb%cl,inclcmpl%edi,%ebxjneconvert_loopmovl%ebp,%esppopl%ebp
#next#continueunlesswe’vereachedthe#Common#CommonLinux#SystemCall.equSYS_EXIT,.equSYS_READ,.equSYS_WRITE,.equSYS_OPEN,.equSYS_CLOSE,.equSYS_BRK,#SystemCallInterrupt.equLINUX_SYSCALL,#StandardFile.equSTDIN,.equSTDOUT,.equSTDERR,#CommonStatus.equEND_OF_FILE,.equRECORD_FIRSTNAME,.equRECORD_LASTNAME,.equRECORD_ADDRESS,.equRECORD_AGE,.equRECORD_SIZE,使用時(shí).include.include"record-#read-.include"record-.include#INPUT:Thefiledescriptoranda#OUTPUT:Thisfunctionwritesthedatatothebufferandreturns#STACKLOCAL.equST_READ_BUFFER,.equST_FILEDES,
.section.globl.typeread_record,pushlmovl%esp,pushlmovlST_FILEDES(%ebp),%ebxmovlST_READ_BUFFER(%ebp),%ecxmovl$RECORD_SIZE,%edxmovl$SYS_READ,int
#NOTE-%eaxhasthereturnvaluepopl%ebxmovl%ebp,popl#write-.include.include"record-#INPUT:Thefiledescriptoranda#OUTPUT:Thisfunctionproducesastatus#STACKLOCAL.equST_WRITE_BUFFER,.equST_FILEDES,.section.globl.typewrite_record,@functionpushl%ebpmovl%esp,%ebppushl%ebxmovl$SYS_WRITE,movlST_FILEDES(%ebp),%ebxmovlST_WRITE_BUFFER(%ebp),%ecxmovl$RECORD_SIZE,%edxint
#NOTE-%eaxhasthereturnpoplmovl%ebp,popl%ebp#write-.include.include"record-.section.data.ascii.rept31#Paddingto40.byte
OpentheWritethreeClosethe.ascii.rept31#Paddingto40.ascii.rept31#Paddingto40.byte
“.reptN”209#Paddingto2400填充其與“.endr”之間容,重復(fù)N…
#skiprecord2~#Thisisthenameof.ascii
filewewillwrite.equST_FILE_DESCRIPTOR,-.globlmovl%esp,subl$4,%esp #Allocatespacetoholdthefiledescriptormovl$SYSOPEN%eaxaswrite-records.s-owrite-record.oaswrite-record.s-owrite-ldwrite-record.owrite-records.o-owrite-movl%eax,ST_FILE_DESCRIPTOR(%ebp)#Storethefilepushlpushl$record1callwrite_recordaddl$8,%esp
#Writethefirst#Writetheremainingrecords;closethefileand…OpentheAttempttoreadaIfweareattheendofthefile,Otherwise,countthecharactersofthefirstWritethefirstnametoWriteanewlinetoGobacktoreadanother#count-#INPUT:Theaddressofthe#OUTPUT:Returnsthecountin.typecount_chars,.globl.equST_STRING_START_ADDRESS,pushl
%esp,$0, #CounterstartsatmovlST_STRING_START_ADDRESS(%ebp), #Startingaddressofmovb(%edx),%alcmpb$0,%aljecount_loop
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024石材行業(yè)深度合作開發(fā)合同書3篇
- VI設(shè)計(jì)合同書模板標(biāo)準(zhǔn)
- 2025年度個(gè)人住宅陽臺(tái)防水改造合同范本8篇
- 個(gè)人間緊急貸款協(xié)議樣本2024年版版
- 2025年度新能源汽車充電設(shè)施運(yùn)營管理承包合同協(xié)議書模板1500字4篇
- 長沙文創(chuàng)藝術(shù)職業(yè)學(xué)院《藝術(shù)學(xué)理論》2023-2024學(xué)年第一學(xué)期期末試卷
- 家庭火災(zāi)自救技巧的普及與推廣
- 小空間大功能單身公寓的空間利用畢業(yè)設(shè)計(jì)
- 2025年度精密模具租賃服務(wù)合同模板4篇
- 2025年食品加工委托生產(chǎn)與食品安全合同3篇
- 氣動(dòng)調(diào)節(jié)閥調(diào)校
- 中考模擬考試化學(xué)試卷與答案解析(共三套)
- 新人教版五年級(jí)小學(xué)數(shù)學(xué)全冊奧數(shù)(含答案)
- 風(fēng)電場升壓站培訓(xùn)課件
- 收納盒注塑模具設(shè)計(jì)(論文-任務(wù)書-開題報(bào)告-圖紙)
- 博弈論全套課件
- CONSORT2010流程圖(FlowDiagram)【模板】文檔
- 腦電信號(hào)處理與特征提取
- 高中數(shù)學(xué)知識(shí)點(diǎn)全總結(jié)(電子版)
- GB/T 10322.7-2004鐵礦石粒度分布的篩分測定
- 2023新譯林版新教材高中英語必修一重點(diǎn)詞組歸納總結(jié)
評論
0/150
提交評論