系统程式.ppt

上传人:s****8 文档编号:67273125 上传时间:2022-12-24 格式:PPT 页数:63 大小:3.66MB
返回 下载 相关 举报
系统程式.ppt_第1页
第1页 / 共63页
系统程式.ppt_第2页
第2页 / 共63页
点击查看更多>>
资源描述

《系统程式.ppt》由会员分享,可在线阅读,更多相关《系统程式.ppt(63页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。

1、系統程式Chapter 2:Assemblers國立政治大學資訊科學系SP.Chap2.2Assembling Programs for ExecutionMacro ProcessorsExpanded Assembly ProgramsAssembly ProgramsCore AssemblersObject ProgramsLinkersLibrariesExecutablesLoaders國立政治大學資訊科學系SP.Chap2.3AssemblersInput and output of an assembler:nAssembly program for programmers(p

2、p.45)nObject code for hardware(pp.49)Types of“instructions”in a assembly program:nMnemonic machine instructions nAssembler directives(pp.44)Major functions of assemblers(pp.46)國立政治大學資訊科學系SP.Chap2.4Main()x=x +y;#ifdef DEBUG printf(“%d”,x);#endif Compiler Directives國立政治大學資訊科學系SP.Chap2.5Major Functions

3、 of AssemblersConversion of mnemonic op-codesConversion of machine instructionCreation of proper object fileConversion of data constantSave results in the object program國立政治大學資訊科學系SP.Chap2.6A Simple 80X86 ASM Program;This program displays“Hello,world!”.model small.stack 100h.datamessage db“Hello,wor

4、ld!”,0dh,0ah,$.codemain procmovax,datamovds,axmov ah,9movdx,offset messageint 21hmovax,4c00hint 21hmainendpend main國立政治大學資訊科學系SP.Chap2.7Some DetailsForward referenceAssembler directives(pseudo-instructions)Format of object program(pp.48-49)國立政治大學資訊科學系SP.Chap2.8A 2-Pass AssemblerPass 1nAssign address

5、es to statementsnRecord addresses for labelsnProcess assembler directivesPass 2nAssemble instructionsnGenerate data valuesnFinish processing of assembler directivesnWrite output files國立政治大學資訊科學系SP.Chap2.9The First PassCOPY =1000SYMBOL TABLE(SYMTAB)FIRST =1000CLOOP =1003ENDFIL=1015STL RETADR1000LDA L

6、ENGTH1006JUSB RDREC1003JEQ ENDFIL100CCOMP ZERO1009JSUB WRREC100FJ CLOOP1012LDA EOF1015國立政治大學資訊科學系SP.Chap2.10Translating to SIC instructionsDuring the first pass,the assembler collects addresses for symbolsGiven this information,we can translate assembly instructions to their machine code counterpart

7、.ExamplenSTL RETADR (line 10)wSTL:opcode=14wRETADR:1033wThis instruction does not use index mode.(why?)wAccording to the instruction format of SIC,the machine code for this instruction is 141033.(ref.pp6)國立政治大學資訊科學系SP.Chap2.11More Examples for SICExamplesnJSUB RDREC(line 15)wJSUB:OPCODE=48wRDREC:203

8、9wNOT INDEXED MODEwMACHINE CODE 482039nSTCH BUFFER,X(line 160)wSTCH:OPCODE=54(0101 0100)wBUFFER:1039(001 0000 0011 1001)wINDEXED MODE(BECAUSE OF“,X”):x bit=1wMACHINE CODE 0101 0100 1001 0000 0011 1001(549039)nLDCH BUFFER,X國立政治大學資訊科學系SP.Chap2.12Object ProgramWhy do we need to specify and standardize

9、the format?nFor communication between assemblers and linkers/loadersnFor linking object programs created by different assemblers/compilersThe formatnHeader recordnText recordnEnd record國立政治大學資訊科學系SP.Chap2.13Standardizing Object Programs AssemblersAssembly ProgramsObject ProgramsLinkersLoadersObject

10、ProgramsC/C+.ProgramsCompilersLibraries國立政治大學資訊科學系SP.Chap2.14%ps u sp10USER PID%CPU%MEMsp10 xxx 98%50%sp10 yyy 2%1%Standardizing Object Programs(2)國立政治大學資訊科學系SP.Chap2.15Object Program(2)Reasons for having multiple Text records in the object programnLine width limitation(The author arbitrarily choose

11、s 1E bytes.)nEnd of object codenReserving memory spacenPutting the object code for a source statement in one text recordnProgram blocks(pp.83,Section 2.3.4)國立政治大學資訊科學系SP.Chap2.16Figure 2.3H,COPY ,001000,00107AT,001000,1E,141033,482039,001036,00102DT,00101E,15,0C1036,482061,000000T,002039,1E,041030,0

12、01030,T,002057,1C,101036,4C0000,F1,2C1036T,002073,07,382064,4C0000,05E,001000國立政治大學資訊科學系SP.Chap2.17Algorithm and Data StructureOperation table(OPTAB)Symbol table(SYMTAB)nHash tables for OPTAB and SYMTABLocation counter(LOCCTR)Intermediate filesSkeleton of the algorithm(Figure 2.4)國立政治大學資訊科學系SP.Chap2

13、.18Assembler for SIC/XEContinue to use the 2-pass approachNeed to enhance the assembler for SICnmore registersnmore complex instruction set(addressing modes):,+,#,BASEnlarger available memoryImproved efficiency due to better architecture.Multiprogramming and multiprocessing國立政治大學資訊科學系SP.Chap2.19Asse

14、mbler for SIC/XE(2)The author arbitrarily chooses to use pc relative before base relative.(second paragraph on page 59)Examples:(pp.57-61)nformat 4(pp.57)npc relative(pp.59)nbase relative(pp.60):BASE,NOBASEnothers國立政治大學資訊科學系SP.Chap2.20Translating Format 1/2 InstructionsFormat 1nSimply find the opcod

15、e of the instruction from the OPTABFormat 2nFind the opcode of the instructionnConvert register names to register numbersnExamplewCOMPR A,S(line 150,pp 55)AO048 bits國立政治大學資訊科學系SP.Chap2.21Translating Format 3 InstructionsSteps:nDetermine the format(+for format 4),and set e bit.nFind and set the opcod

16、enDetermine if indexed mode(“,X”for indexed),and set x bitnDetermine the addressing mode(for indirect and#for immediate),and set bits n and i accordinglynIf immediate mode:If a constant follows the#sign,set b=0 and p=0,set disp to the constant,and then process the next instruction.Otherwise,carry th

17、e translation of the symbol that follows#with the methods described in the following step.nTry program-counter relative addressing.If feasible,set b=0,p=1,and disp.Otherwise,try base relative addressing.If feasible,set b=1,p=0,and disp.Report error if neither succeeds.國立政治大學資訊科學系SP.Chap2.22Translati

18、ng Format 3 InstructionsExample:STL RETADR(line 10,pp.58)nFormat 3 e bit=0nOpcode=14 00010100nNot indexed x bit=0nNeither indirect nor immediate n=i=1nNot immediatenTry pc-relativewRETADR=0030(TA)w(PC)=0003(How do we know?)wTA=(PC)+disp disp=TA-(PC)=02D 0000 0010 1101w-2048 02D(45)2047 b=0 and p=1nS

19、TL RETADR 000101 1 1 0 0 1 0 0000 0010 1101 17202D00010111 0 0 1 0?國立政治大學資訊科學系SP.Chap2.23Translating Format 3 Instructions(2)Example:J CLOOP(line 40,pp.58)nFormat 3 e bit=0nOpcode=3C 00111100nNot indexed x bit=0nNeither indirect nor immediate n=i=1nNot immediatenTry pc-relativewCLOOP=0006(TA)w(PC)=0

20、01AwTA=(PC)+disp disp=TA-(PC)=FEC 1111 1110 1100w-2048 FEC(-14h)2047 is good b=0 and p=1nSTL RETADR 001111 1 1 0 0 1 0 1111 1110 1100 3F2FEC001111 1 1 0 0 1 0?國立政治大學資訊科學系SP.Chap2.24Translating Format 3 Instructions(3)Example:STCH BUFFER,X(line 160,pp.58)nFormat 3 e bit=0nOpcode=54 01010100nIndexed x

21、 bit=1nNeither indirect nor immediate n=i=1nNot immediatenTry pc-relativewBUFFER=0036(TA)w(PC)=1051wTA=(PC)+disp disp=TA-(PC)=-(101Bh)w-(101Bh)-2048,2047 cannot use pc-relative addressingwMust resort to based relative addressing010101 1 1 1 0 1 0?國立政治大學資訊科學系SP.Chap2.25Translating Format 3 Instructio

22、ns(4)Example:STCH BUFFER,X(line 160,pp.58)nFormat 3 e bit=0nOpcode=54 01010100nIndexed x bit=1nNeither indirect nor immediate n=i=1nNot immediatenWe try base relative addressing this time.wBUFFER=0036(TA)w(B)=0033(How do we know?)wTA=(B)+disp disp=TA-(B)=003 0000 0000 0011w003 0,4095 set b=1 and p=0

23、nSTCH BUFFER,X 010101 111100 0000 0000 0011 57C003010101 1 1 1 1 0 0?國立政治大學資訊科學系SP.Chap2.26Translating Format 3 Instructions(5)Example:LDA#3(line 55,pp.58)nFormat 3 e bit=0nOpcode=00 00000000nNot indexed x bit=0nImmediate n=0 and i=1nSince it is immediate mode,set b=0,p=0,and disp=operand=3nLDA#3 00

24、0000 0 1 0 0 0 0 0000 0000 0011 0 1 0 0 0 3國立政治大學資訊科學系SP.Chap2.27Translating Format 3 Instructions(6)Example:LDB#LENGTH(line 12,pp.58)nFormat 3 e bit=0nOpcode=68 01101000nNot indexed x bit=0nImmediate n=0 and i=1nSince it is immediate mode,but LENGTH is not a constantwTry pc-relativewTA=LENGTH=0033w

25、(PC)=0006wTA=(PC)+disp disp=TA (PC)=02Dw02D -2048,2047 set b=0 and p=1nLDB#LENGTH 011010 0 1 0 0 1 0 0000 0010 1101 69202D國立政治大學資訊科學系SP.Chap2.28Translating Format 3 Instructions(7)Example:J RETADR(line 70,pp.58)nFormat 3 e bit=0nOpcode=3C 00111100nNot indexed x bit=0nIndirect n=1 and i=0nTry pc-rela

26、tivewTA=RETADR=0030w(PC)=002DwTA=(PC)+disp disp=TA (PC)=003w003 -2048,2047 set b=0 and p=1nJ RETADR 001111 1 0 0 0 1 0 0000 0000 0011 3E2003國立政治大學資訊科學系SP.Chap2.29Translating Format 4 InstructionsExample:+JSUB RDREC(line 15,pp.58)nFormat 4 e bit=1nOpcode=48 01001000nNot indexed x bit=0nNeither indire

27、ct nor immediate n=i=1nNot immediaten(Twenty bits are sufficient to record any SIC/XE address,so there is no need to employ displacement.)b=p=0,address=RDREC=01036n+JSUB RETADR 010010 1 1 0 0 0 1 0000 0001 0000 0011 0110 4 B 1 01036國立政治大學資訊科學系SP.Chap2.30Translating Format 4 Instructions(2)Example:+L

28、DT#4096(line 12,pp.58)nFormat 4 e bit=1nOpcode=74 01110100nNot indexed x bit=0nImmediate n=0 and i=1nImmediate mode and a constant following#wSet b=0 and p=0w4096=01000hnLDT#4096 011101 0 1 0 0 0 1 0000 0001 0000 0000 0000 7 5 1 01000國立政治大學資訊科學系SP.Chap2.31Compiling Programs for ExecutionC/C+Programs

29、Macro ProcessorsExpanded C/C+ProgramsCompilation ProgramsAssembly ProgramsAssemblersObject ProgramsLinkersLibrariesExecutablesLoadersIn reality,compilers may not use assembly programs for this intermediate step.This step may be skipped in some rare cases.國立政治大學資訊科學系SP.Chap2.32Assembling Programs for

30、 ExecutionMacro ProcessorsExpanded Assembly ProgramsAssembly ProgramsCore AssemblersObject ProgramsLinkersLibrariesExecutablesLoadersThis step may be skipped in some rare cases.Notice that a complete assembler may include a macro processor.國立政治大學資訊科學系SP.Chap2.33Program RelocationWhy bother?nDo we re

31、ally know where our programs will be placed in memory beforehand?nEfficient memory managementnMultiprogramming and multiprocessingnLoad timeChallenges(pp.62-63):relative and absoluteThe algorithm:mark memory reference that needs to be modified before run time(pp.63)國立政治大學資訊科學系SP.Chap2.34Figure 2.8H,

32、COPY ,000000,001077T,000000,1D,17202D,69202D,4B101036,032036,290000,332007,4B10105D,M,000007,05M,000014,05M,000027,05E,001000國立政治大學資訊科學系SP.Chap2.35Multiprogramming?國立政治大學資訊科學系SP.Chap2.36Relocation(2)ExamplesnFigure 2.7nThe third paragraph counted from the bottom of page 62.Modification recordsnPage

33、64nHalf bytes國立政治大學資訊科學系SP.Chap2.37LiteralsWhat?Examples:page 66(=)nDifference between literals and immediate constants(size)Why?Allow programmers to avoid defining constants in their programs.國立政治大學資訊科學系SP.Chap2.38Literals(2)How?Literal poolsnNormally put at the end of the programnLTORG(used when i

34、t is desirable to keep the literal operand close to the instruction that uses it)nDuplicate literals(pros and cons)nLiteral for location counter:*(pp.70)wBASE*wLDB=*nTaking care of literals(pp.70-71)國立政治大學資訊科學系SP.Chap2.3945001A ENDFILLDA=CEOF70002AJRETADR93LTORG2151062 WLOOPTD=X05255END國立政治大學資訊科學系SP

35、.Chap2.4045001A ENDFILLDA=CEOF70002AJRETADR93LTORG002D*=CEOF2151062 WLOOPTD=X05255END1076*=X05 032010_454F46E3201105國立政治大學資訊科學系SP.Chap2.41#define in A Simple C Program#define ABC 5main()int x,y,z;x=3;y=ABC+x;z=3*x+ABC;printf(“%d%d%dn”,x,y,z);return;We define symbols with the#define command in C.國立政治

36、大學資訊科學系SP.Chap2.42Symbol-Defining StatementsSymbol-defining statementsnWhat?(pp.71)wSimilar to#define command for C preprocessorwsymbol EQU valuenWhy?Easy to maintain programswprogram parameterswregisters(pp.72)ORG (origin)nORG value (indirectly assign value to symbol)NO forward reference in EQU and

37、 ORG statements(pp.74-75)nWhy not?!Our 2-pass assembler requires ALL symbols be defined during Pass 1!nDiscuss examples on page 75國立政治大學資訊科學系SP.Chap2.43ALPHA RESW 1BETA EQU ALPHABETA EQU ALPHAALPHA RESW 1 ORG ALPHABETA1 RESB 1BETA2 RESB 1BETA3 RESB 1 ORGALPHA RESB 1ALPHA EQU BETABETA EQU DELTADELTA

38、RESW 1國立政治大學資訊科學系SP.Chap2.44ExpressionsnWhat?w107 MAXLEN EQU BUFEND-BUFFERnValidity checkingwrelative and absolute expressionswAbsolute exp may contains paired relative terms that have opposite signswA relative expression is one in which all relative terms,except one with positive sign,are paired.wN

39、o relative terms may enter into multiplication and division.nDiscuss examples on page 77.國立政治大學資訊科學系SP.Chap2.45Program blocksProgram blocks and control sectionsninternal identity vs.external identityWhat?pp.81nSeparate the spatial relationship between source code and their object codeWhy?nprogram re

40、adabilitynMay reduce the usage of format 4 instructionsHow?nUSE nThe assembler will rearrange the segments國立政治大學資訊科學系SP.Chap2.46Program blocks(2)How?(Contd)nNeed to maintain a separate table for data about blocksnCalculation of address(page 82)nWhy again!Program readability and reducing complexity i

41、n assembled code(avoid extended format)nDiscuss Figure 2.13 for code generation(no need to rewrite code generation;the loader is supposed to put things in their places)國立政治大學資訊科學系SP.Chap2.47Memory AppropriationBUFFERSTLJSUBLDACLEARCLEAR?RETADR?LENGTH?INPUTEOF05defaultCDATACBLKS0066國立政治大學資訊科學系SP.Chap

42、2.48國立政治大學資訊科學系SP.Chap2.49Control SectionsWhat?nEach control section can be loaded and relocated independently.nLinking is required(to resolve external references)nEXTDEF,EXTREFWhy?flexibilityHow?nLeave the longest space for external referencesA relative C example國立政治大學資訊科學系SP.Chap2.50A C Example#in

43、clude extern int outside(int x);int inside(int y);main()int i=3;printf(%d,outside(i);return 0;int inside(int y)return 2*y;extern int inside(int z);intoutside(int x)return(x+inside(x);gcc c p1.cgcc c p2.cgcc o go p1.o p2.ogo?國立政治大學資訊科學系SP.Chap2.51Control Sections(2)How(contd)nDefine and Refer records

44、nModification recordnNotice that each control section has its own object codenLinking the sections(page 90-91)nThe revised modification record is still good for relocation.Expression revisitednpaired reference must be relative within a control section國立政治大學資訊科學系SP.Chap2.52Linking Loader 1st PassRefe

45、r to object programs on page 90COPY 005000BUFFER 005033BUFEND 006033LENGTH 00502DRDREC 006033WRREC 00605EPROGRAM LENGTH=607A COPYRDREC10335000WRREC002B001C國立政治大學資訊科學系SP.Chap2.53Linking Loader 2nd Pass17500020274B10002023200300071000003F2FEC01000320160F20334B501060331016Refer to object programs on pa

46、ge 90COPY 005000BUFFER 005033BUFEND 006033LENGTH 00502DRDREC 006033WRREC 00605EPROGRAM LENGTH=107A 0000290F20030A1000003E20004F?4B5023?46?455030605E10605E10國立政治大學資訊科學系SP.Chap2.5400Linking Loader 2nd Pass(2)B4603310B400B4771FE3FA2040DB15A0043320093B2F57900000B82F20604350339050Refer to object programs

47、 on page 90COPY 005000BUFFER 005033BUFEND 006033LENGTH 00502DRDREC 006033WRREC 00605EPROGRAM LENGTH=107A 1B33201310E9000000F100000020107710004F605700332F12FAE3603300502D10B4605E100000國立政治大學資訊科學系SP.Chap2.55Linking Loader 2nd Pass(3)B4605E10771000E31233002000002008B8503B2FEE4F00000590DF606E502D10Refer

48、 to object programs on page 90COPY 005000BUFFER 005033BUFEND 006033LENGTH 00502DRDREC 006033WRREC 00605EPROGRAM LENGTH=107A FA532F503390REPEATED FROM THE LAST PAGE國立政治大學資訊科學系SP.Chap2.5650001720274B20232003073360331000002950103F2FEC01000320160F204B160F20030A605E106045B410B400B4771FE3FA2040DB152F201B3

49、3206057A0043320093B2F57B85033905013E9502D10606A0000F12010774F332F12FAE3B4100000502D102008B8503B2FEE4F000005DF535033905023Loading Completed60334F?46?3E2000?4B?605E10?45國立政治大學資訊科學系SP.Chap2.57Assembler Design OptionsOne-pass assemblersnforward referenceswprohibit forward referencesnload and go assemble

50、rwsave object code in memory(an easier task than generating code on secondary storage)ngenerating object code on secondary storagewduplicate T record for instructions that use forward referencenTrace the examples in Section 2.4.1Multi-pass assemblersnTrace the example in Section 2.4.2國立政治大學資訊科學系SP.C

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 生活常识

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知得利文库网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号-8 |  经营许可证:黑B2-20190332号 |   黑公网安备:91230400333293403D

© 2020-2023 www.deliwenku.com 得利文库. All Rights Reserved 黑龙江转换宝科技有限公司 

黑龙江省互联网违法和不良信息举报
举报电话:0468-3380021 邮箱:hgswwxb@163.com