DOC PREVIEW
Princeton COS 217 - Assembler Directives

This preview shows page 1-2-3 out of 8 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

1AssemblerDirectivesCS217AssemblerDirectives• Identifysections• Allocate/initializememory• Makesymbolsexternallyvisible2IdentifyingSections• Text(.section“.text”)Containscode(instructions)Defaultsection• Read-OnlyData(.section“.rodata”)Containsconstants• Read-WriteData(.section“.data”)Containsuser-initializedglobalvariables• BSS(.section“.bss”)BlockstartingsymbolContainszero-initializedglobalvariables00xffffffffTextDataBSSStackHeap0x2000OS01Sections(cont)• EachsectionhasownlocationcounterLocationcounterisupdatedwhenassemblerprocessesdirectiveorinstructionText Datasethiorldaddandtext_lcdata_lc3Allocatingmemory• Incrementlocationcounterbynbytes.skip nbytes.section“.bss”var1:.skip16.section“.data”var2:.skip4Initializingmemory• Incrementlocationcounterandinitializedata.bytebyteval1[,byteval2...].halfhalfval1[,halfval2...].wordwordval1[,wordval2...].section“.data”sum:.word0.section“.text”setsum,%o0ld[%o0],%i1Text Data0sethiorldsum:4InitializingASCIIData• Specialdirectivesforasciidata.byte150,145,154,154,157,0.ascii“hello”.byte0.asciz “hello”MakingSymbolsExternallyVisible• Markvariablesasglobal.global.section“.data”.align4.globalmonthmonth:.wordjan,feb,mar,apr,may,jun.wordjul,aug,sep,oct,nov,decjan:.asciz “January”feb:.asciz “February”mar:.asciz “March”apr:.asciz “April”may:.asciz “May”jun:.asciz “June”jul:.asciz “July”...5MakingSymbolsExternallyVisible• Markfunctionsasglobal.global.section“.rodata”fmt:.asciz “Hello,world\n”.section“.text”.align4.globalmainmain:save%sp,-96,%spsetfmt,%o0callprintfnopmov1,%g1ta0retrestoreExample1inta[100];main(){…}.section“.bss”a:.skip4*100.section“.text”.globalmainmain:save%sp,-96,%spclr %l0L1: cmp %l0,%l1bge L2;nop...sll%l0,2,%l2ld[a+%l2],%l3...inc%l0ba L1; nopL2:mov 1,%g1ta 0retrestore6Example2inta[100];voidswap(int *x,int *y){inttemp;temp=*x;*x=*y;*y=temp;}main(){…swap(&a[1],&a[2]);…}.section“.bss”a:.skip4*100.section“.text”.globalswapswap:ld[%o0],%o2ld[%o1],%o3st%o2,[%o1]retlst%o3,[%o0].globalmainmain:save%sp,-96,%sp…seta,%l0add%l0,4,%o0callswapadd%l0,8,%o1…mov 1,%g1ta 0retrestoreExample3structexample{inta,b;chard;shortx,y;intu,v;};structexamplea={1,2,‘C’,4,5,6,7};main(){…}.section“.data”a:.word1,2.byte`C’.align2.half3,4.align4.word6,7.section“.text”.align4.globalmainmain:save%sp,-96,%spseta,%l0ld[%l0+0],%l1ld[%l0+4],%l2ldub [%l0+8],%l3ldsh [%l0+10],%l4mov 1,%g1ta 0retrestore7Example4main(){t(1,2,3,4,5,6,7,8);}int t(inta1,inta2,inta3,inta4,inta5,inta6,inta7,inta8){intb1=a1;returns(b1,a8);}staticint s(intc1,intc2){returnc1+c2;}Example4(cont).globalmainmain:save%sp,-104,%spset1,%o0set2,%o1set3,%o2set4,%o3set5,%o4set6,%o5set7,%i5st%i5,[%sp+4*6+68]set8,%i5st %i5,[%sp+4*7+68]callt;nopmov 1,%g1ta 0ret;restore.globaltt:save%sp,-96,%spst%i0,[%fp-4]ld[%fp-4],%o0ld[%fp+4*7+68],%o1calls;nopmov%o0,%i0ret;restores:add%o0,%01,%o0retl;nop8a8a7a6a5a4a3a2a116wordsstruct *b1c2c116wordsstruct *tmain%sp%fp-4+96+92+88+64+88+84+64StackFramelocal&tempvarsarguments7,8,…argument5argument4argument6ptr tostructrtrnargument3argument2argument116wordstoholdsavedin/outregs%fp%sp%fp - offset%sp + offset%sp + offsetlocal&tempvarsarguments7,8,…argument5argument4argument6ptr tostructrtrnargument3argument2argument116wordstoholdsavedin/outregs%fp +


View Full Document

Princeton COS 217 - Assembler Directives

Documents in this Course
Summary

Summary

4 pages

Lecture

Lecture

4 pages

Generics

Generics

14 pages

Generics

Generics

16 pages

Lecture

Lecture

20 pages

Debugging

Debugging

35 pages

Types

Types

7 pages

Lecture

Lecture

21 pages

Assembler

Assembler

16 pages

Lecture

Lecture

20 pages

Lecture

Lecture

39 pages

Testing

Testing

44 pages

Pipeline

Pipeline

19 pages

Lecture

Lecture

6 pages

Signals

Signals

67 pages

Building

Building

17 pages

Lecture

Lecture

7 pages

Modules

Modules

12 pages

Generics

Generics

16 pages

Testing

Testing

22 pages

Signals

Signals

34 pages

Lecture

Lecture

19 pages

Load more
Download Assembler Directives
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Assembler Directives and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Assembler Directives 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?