UNIT II ASSEMBLERS. Figure Assembler

Size: px
Start display at page:

Download "UNIT II ASSEMBLERS. Figure Assembler"

Transcription

1 2.1 Basic assembler functions UNIT II ASSEMBLERS Assembler Assembler which converts assembly language programs into object files. Object files contain a combination of machine instructions, data, and information needed to place instructions properly in memory. Figure Assembler Assembler functions Convert mnemonic operation codes to their machine language equivalents Convert symbolic operands to their equivalent machine addresses. Build the machine instructions in the proper format. Convert the data constants to internal machine representations Write the object program and the assembly listing Error checking is provided Changes can be quickly and easily incorporated with a reassembly Features of assemblers Mnemonic operation codes Symbolic operations Data declarations Assembly Language Statements There are three types of statements are used in the assembly language. They are: 1. Imperative Statements 2. Declaration Statements 3. Assembler Directives Prepared by P.Vasantha kumari 14

2 1. Imperative statements It indicates an action to be performed during the execution of the assembled program. It focuses on how to solve a problem based on side effects on memory. Each imperative statement translates into one machine instruction. 2. Declaration Statements It focuses on what the problem is and leave the solution mechanism up to the language implementation. It is quite abstract and harder to implement efficiently. 3. Assembler Directives It instructs the assembler to perform certain actions during the assembly of a program. They can be used to declare variables, create storage space and declare constants. Some of the assembler directives are: START Specify name and staring address for the program END indicates the end of the source program and (optionally) specifies the first executable instruction in the program BYTE Generate character or hexadecimal constant, occupying as many bytes as needed to represent the constant WORD Generate one-word integer constant Statement Format All the statements in the assembly language program is in the form of [LABEL] <OPCODE> <OPERAND> COMMENTS Label: It is an identifier and an optional field. It remembers where the data or code is located. The maximum length of label which differs depends upon the assembler. Most of the assembler that supports 32 characters in length. It is suffixed by a colon (:) and begins with [A Z]. Example: START: LDA #24 OPCODE: It contains mnemonic. OPCODE stands for operation code or machine code instruction. It also requires operands. OPERAND: It specifies constants, labels or immediate data. Data contained in another accumulator or register and address. Prepared by P.Vasantha kumari 15

3 Advantages of assembler It reduced errors Faster translation times Changes could be made easier and faster Disadvantages of assembler Many instructions are required to achieve small tasks. Source Programs tend to be large and difficult to follow Programmers requires knowledge of the processor architecture and instruction set Programs are machine independent requires complete rewrites if the hardware is changed 2.2 A simple SIC assembler Assembler Function A simple SIC (Simplified Instructional Computer) assembler which performs following functions such as: Convert mnemonic operation codes to their machine language equivalents Convert symbolic operands to their equivalent machine addresses. Build the machine instructions in the proper format. Convert the data constants to internal machine representations Write the object program and the assembly listing Assembler directives The SIC assembler language has the following assembler directives. START Specify name and staring address for the program END Indicate the end of the source program and (optionally) specify the first executable instruction in the program BYTE Generate character or hexadecimal constant, occupying as many bytes as needed to represent the constant WORD Generate one-word integer constant Prepared by P.Vasantha kumari 16

4 RESB Reserve the indicated number of bytes for a data area RESW Reserve the indicated number of words for a data area Assemblers Assembler which converts the assembly language into machine cod or object code. There are two types of assemblers are there: o Two pass assembler Pass 1 assembler Pass 2 assembler o One pass assembler In two pass assembler, the first pass scans the source program for label definitions and assigns addresses whereas the second performs most of the actual translation. The assembler must process the assembler directives statements. These statements are not translated into machine instructions. They provide instructions to the assembler itself. The assembler directives SATRT specifies the starting address of the object program and END marks the end of the programs. Assembler must write object code onto some output device. This object program will later be loaded into memory for execution. An object program contains three types of records: Header Text End Header record contains the program name, starting address and length. Text record contains the translated instructions and data of the program, together with an indication of the addresses where these are to be loaded. End record marks the end of the object program and specifies the address in the program where execution is to begin. Prepared by P.Vasantha kumari 17

5 Functions of Assemblers Pass 1(define symbols) Assign addresses to all statements in the program. Save the values (addresses) assigned to all labels for use in Pass 2. Perform some processing of assembler directives. Include processing that affects address assignment such as determining the length of data areas defined by BYTE, RESW, etc. Pass 2 (assemble instructions and generate object program) Assemble instructions which translate operation codes and looking up addresses Generate data values defined by BYTE, WORD, etc. Perform processing of assembler directives not done during Pass 1. Write the object program and the assembly listing. Format of Object Program Header Record Col. 1 H Col. 2-7 Program Name Col Starting address of object program (hexadecimal) Col Length of object program in bytes (hexadecimal) Text Record Col. 1 Col. 2-7 Col. 8-9 Col T Starting address for object code in this record (hexadecimal) Length of object code in this record in bytes (hexadecimal) Object End Record Col. 1 Col. 2-7 E Address to first executable instruction in object program (hexadecimal) Prepared by P.Vasantha kumari 18

6 Example (i) Assembly Language Program with object Code LOOCTR LABEL OPCODE OPERAND OBJ.CODE MAIN START BEGIN LDA NUM C 2003 STA NUM2 0C200F 2006 LDCH CHAR STCH CHAR C NUM1 WORD F NUM2 RESW CHAR1 BYTE C A CHAR2 RESB END BEGIN (ii) Object Program H^MAIN^ ^ T^ ^0F^00 200C^0C 200F^ ^ ^ T^ ^01^ E^ Assembler algorithm and Data structures Internal data structures Operation Code Table (OPTAB) Symbol Table (SYMTAB) Location Counter (LOCCTR) OPTAB OPTAB is used to look up mnemonic operation codes and translate them to their machine language equivalents. Prepared by P.Vasantha kumari 19

7 In most cases, OPTAB is a static table. OPTAB must contain the mnemonic operation code and its machine language equivalent. In more complex assemblers, OPTAB also contains information about instruction format and length. OPTAB is usually organized as a hash table, with mnemonic operation code as the key. SYMTAB SYMTAB is used to store values (addresses) assigned to labels. SYMTAB includes the name and value (address) for each label in the source program together with flags to indicate error conditions. e.g., a symbol defined in two different places This table may also contain information, such as type or length, about the data area or instruction labeled. SYMTAB is usually organized as a hash table for efficiency of insertion and retrieval. the label is the key of SYMTAB. non-random key LOCCTR This is a variable that is used to help in the assignment of address. LOCCTR is initialized to the beginning address specified in the START statement. After each source statement is processed, the length of the assembled instruction or data area to be generated is added to LOCCRT. When a label is reached, the current value of LOCCTR gives the address to be associated with that label Two Pass Assemblers Two pass assembler that translates the assembly language program itno object code or machine in two passes i.e., pass 1 and pass 2. The pass 1 algorithm which scans the source program for label definitions and assigns addresses whereas pass 2 algorithm performs the actual translation. Prepared by P.Vasantha kumari 20

8 Figure 2.2 Two Pass Assembler Pass 1 of a two pass assembler Step 1: Read the input line. Step 2: Check to see if the opcode field in the input line is START. (i) Find if there is any operand field after START; initialize the LOCCTR to the operand value. (ii) Otherwise, if there is no value in the operand field the LOCCTR is set to zero. Step 3: Write the line to the intermediate file. Step 4: Repeat the following for the other lines in the program until the opcode field contains END directive. 1. If there is a symbol in the label field. i. Check the symbol table to see if has already been stored over there. If so then it is a duplicate symbol, the error message should be displayed. ii. Other wise the symbol is entered into the SYMTAB, along with the memory address in which it is stored. 2. If there is an opcode in the opcode field i. Search the OPTAB to see if the opcode is present, if so increment the location counter (LOCCTR) by three. ii. a) If the opcode is WORD, increment the LOCCTR by three. b) If the opcode is BYTE, increment the LOCTR by one. c) If the opcode is RESW, increment the LOCCTR by integer equivalent of the operand value *3. d) If the opcode is RESB, increment the LOCCTR by the integer equivalent of the operand value. 3. Write each and every line processed to the intermediate file along with their Prepared by P.Vasantha kumari 21

9 location counters. Step 5: Calculate the length of the program by subtracting the starting address of the program from the final value of the LOCCTR Algorithm Read first input line if OPCODE= START then Save #[OPERAND] a starting address Initialize LOCCTR to starting address Write line to intermediate file Read next input line End (if START) Else Initialize LOCCTR to 0 While OPCODE END do if this is not a comment line then if there is a symbol in the LABEL filed then Search SYMTAB for LABEL if found then Set error flag (duplicate symbol) else Insert (LABEL, LOCCTR) into SYMTAB End {if symbol} Search OPTAB for OPCODE if found then Prepared by P.Vasantha kumari 22

10 Add 3 {instruction length} to LOCCTR else if OPCODE= WORD then Add 3* # [OPERAND] to LOCCTR else if OPCODE= RESW then Add 3* # [OPERAND] to LOOCTR else if OPCODE= RESB then Add # [OPERAND] to LOOCTR else if OPCODE= BYTE then Find length of constant in bytes Add length to LOOCTR End {if BYTE} Else Set error flag (invalid operation code) End {if not c comment} Write line to intermediate file Read next input line End {while not END} Write last line to intermediate file Save (LOCCTR-starting address) as program length End {pass 1} Example Input - Assembly Language Program MAIN START 2000 BEGIN LDA NUM1 STA NUM2 LDCH CHAR1 STCH CHAR2 NUM1 WORD 5 NUM2 RESW 1 Prepared by P.Vasantha kumari 23

11 CHAR1 BYTE C A CHAR2 RESB 1 END BEGIN Output Assign addresses to instruction MAIN START BEGIN LDA NUM ** STA NUM ** LDCH CHAR ** STCH CHAR2 200C NUM1 WORD 5 200F NUM2 RESW CHAR1 BYTE C A 2013 CHAR2 RESB END BEGIN Output Symbol table BEGIN 2000 NUM1 200C NUM2 200F CHAR CHAR Pass 2 of a two pass assembler Step 1: Read the first line from the intermediate file. Step 2: Check to see if the opcode field in the input line is START, if so then write the line onto the final output file. Step 3: Repeat the following for the other lines in the intermediate file until the opcode field contains END directive. 1. If there is a symbol in the operand field, then the object code is assembled by combining the machine code equivalent of the instruction with the symbol address. 2. If there is no symbol in the operand field, then the operand address is assigned as zero and it is assembled with the machine code equivalent of the instruction. Prepared by P.Vasantha kumari 24

12 3. If the opcode field is BYTE or WORD or RESB, then convert the constants in the operand filed to the object code. 4. Write the input line along with the object code onto the final output file. Step 4: Close all the opened files and exit. Algorithm Read first input line {from intermediate file} if OPCODE= START then Write listing line Read next input line End {if START} Write Header Record to Object Program Initialize first Text Record While OPCODE END do if this is not a comment line then Search OPTAB for OPCODE if found then if there is a symbol in OPERAND filed then Search SYMTAB for OPERAND if found then Store symbol value as operand address else Store 0 as operand address Set error flag (undefined symbol) Prepared by P.Vasantha kumari 25

13 End End {if symbol} else Store 0 as operand address Assemble the object code instruction end {if opcode found} else if OPCODE= BYTE or WORD then convert constant to object code if object code will not fit into the current text Record then begin write Text record to object Program initialize new text Record end add object code to Text Record end {if not comment} write listing line read next input line end {while not END} write last Text Record to object program Write End Record to object program Write last listing line End {pas 2} Example Input Assembly Language Program with address MAIN START BEGIN LDA NUM ** STA NUM ** LDCH CHAR ** STCH CHAR2 200C NUM1 WORD 5 Prepared by P.Vasantha kumari 26

14 200F NUM2 RESW CHAR1 BYTE C A 2013 CHAR2 RESB END BEGIN Input Symbol table BEGIN 2000 NUM1 200C NUM2 200F CHAR CHAR Output Object Code MAIN START BEGIN LDA NUM C 2003 STA NUM2 0C200F 2006 LDCH CHAR STCH CHAR C NUM1 WORD F NUM2 RESW CHAR1 BYTE C A CHAR2 RESB END BEGIN 2.4 Machine Dependent Assembler Features Register-to-register instructions are shorter and do not require another memory reference. Use register-to-register instructions instead of register-to-memory instructions whenever possible. Most of register-to-memory instructions are assembled using either programcounter relative addressing or base relative addressing Prepared by P.Vasantha kumari 27

15 If the required displacement is too large, then the 4-byte extended instruction format must be used. The programmer must specify the 4-byte format by adding the prefix + to the operation code in the source statement. If the required displacement is out of range, the assembler then attempts to use base relative addressing. If neither form of relative addressing is applicable, then the instruction cannot be properly assembled and the assembler must generate an error message. The assembler directive BASE is used in conjunction with base relative addressing. Indirect addressing is indicated by adding the to the operand. Immediate addressing is specified with the prefix # to the immediate operands. There are two important assembler features are: Instruction Format and Addressing Modes Program Relocation (i) Instruction Format and Addressing Modes Instruction Format: The programmer must specify the 4-byte format by adding the prefix + to the operation code in the source statement. If the required displacement is too large, then the 4-byte extended instruction format must be used. If extended format is not specified, the assembler may first attempt to translate the instruction using programcounter relative addressing. Addressing Modes: Most of register-to-memory instructions are assembled using either program-counter relative addressing or base relative addressing. Immediate addressing is specified with the prefix # to the immediate operands. If neither program counter relative nor base relative addressing can be used, then 4 byte extended instruction format must be used which consists of 20 bit address filed. (a) Program counter relative addressing Consider the assembly language, LINE LOCCTR LABEL OPCODE OPERANDS FIRST STL RETADR LDB #LENGTH Prepared by P.Vasantha kumari 28

16 13 BASE LENGTH CLOOP +JSUB RDREC J CLOOP RETADR RESW LENGTH RESW RDREC CLEAR X C +LDT # E STCH BUFFER, X Example1: Consider the statement in Line 10. During the execution of instructions on SIC, the program counter is advanced after the instruction is fetched and before it is executed. RETADR is assigned the address Now, calculate the displacement value. For program counter addressing, TA= (PC) + Disp Target address (TA)=RETADR=030 and (PC)=003 (PC) = address of the next instruction of line number 10. Now displacement = TA-(PC) = TA= 030= (PC)= 003= (subtract) Disp= = 02D The instruction format for this instruction using program counter addressing is shown below Opcode n i x b p e Disp D Example2: Consider the statement in line 40, Jump to the label CLOOP which is already defined in the address For program counter addressing, TA= (PC) + Disp Target address (TA)=CLOOP=006 and (PC)=01A (PC) = address of the next instruction of line number 40. Prepared by P.Vasantha kumari 29

17 Now displacement = TA-(PC) = A TA= 006= (PC)= 01A= (subtract) Disp= = FEC The instruction format for this instruction using program counter addressing is shown below Opcode n i x b p e Disp 1 7 F E C (b) Base Relative addressing Consider the statement in line 160 it stores the value of base register to BUFFER. The base register which takes the value of LENGTH stored in the address For this instruction, the disp will be calculated using base relative addressing: TA= (B) + Disp Target address (TA)=BUFFER=036 and (B)=033 Now displacement = TA-(B) = =003 (c) Immediate Addressing Consider the statement in line 12, which stores the value of LENGTH to accumulator. In immediate addressing, this immediate value is assigned to the displacement field. If the value is fit into 12 bits then use format 3 type instruction. Otherwise format 4 instruction type is used. (ii) Program Relocation An object program that contains the information necessary to perform the modification is called a re-locatable program. The assembler can identify for the loader those parts of the object program that need modification. The memory address of operands should be modified according to the loaded address, while constant data should remain unchanged. In order to avoid the re- locatable problem, we use modification record. Program relocation is needed because of the following reasons: Prepared by P.Vasantha kumari 30

18 It is desirable to load and run several problems at the same time. The system must be able to load programs into memory wherever there is a room. The exact starting address of the program is not known until load time. The modification record The assembler produces a modification record describing the address and length of an address field to be modified. The loader will add the beginning address of the loaded program to the address field specified by a modification record. Col. 1 Col. 2-7 Col. 8-9 M Starting location of the address field to be modified, relative to the beginning of the program Length of the address field to be modified, in halfbytes Example Figure 2.3 Program Relocation Prepared by P.Vasantha kumari 31

19 2.5 Machine Independent Assembler Features (i) Literals Literals Symbol-defining statements Expressions Program blocks It is convenient for the programmer to be able to write the value of a constant operand as a part of the instruction that uses it. Such an operand is called a literal A ENDFIL LDA =C EOF In this assembler language notation, a literal is identified with the prefix=, which is followed by a specification of the literal value. The difference between a literal and an immediate operand With immediate addressing, the operand value is assembled as a part of the machine instruction LDA # With a literal, the assembler generates the specified value as a constant at some other memory location. The address of this generated constant is used as the target address for the machine instruction A ENDFIL LDA=C EOF Literal pool All of the literal operands used in the program are gathered together into one or more literal pools. Normally literals are placed into a pool at the end of the program. Sometimes, it is desirable to place literals into a pool at some other location in the object program. LTORG directive is introduced for this purpose. When the assembler encounters a LTORG, it creates a pool that contains all of the literals used since the previous LTORG. Literal for current value of location counter The value of the location counter can be denoted by a literal operand *. Prepared by P.Vasantha kumari 32

20 BASE * LDB =* The literal =* repeatedly used in the program that have identical names but different values, and both must be in the literal pool. Handling duplicate literal The assembler should avoid storing duplicate literals. The easiest way to recognize duplicate literals is by comparison of the character strings defining them. For example, WLOOP TD =X B WD =X 05 In this case, literal 05 is repeatedly used. In order to avoid the duplication enter the details of literal into the literal able LITTAB only once. Literal table (LITTAB) The basic data structure needed to process literal operands is a literal table (LITTAB). LITTAB is often organized as a hash table, using the literal name or value as the key. which consists of literal name, hexadecimal value, address and value fields. Example Literals Hexadecimal Length Address Value C EOF 454F D X Implementation of Literals Pass 1 For each recognized literal operand, search LITTAB. If the literal is already present in the table, no action is need; if it is not present, the literal is added to LITTAB without assigning its address. When a LTORG statement is encountered or the end of the program, the assembler makes a scan of LITTAB and assigns an address to each literal. Update the location counter to reflect the number of bytes occupied by each literal. Prepared by P.Vasantha kumari 33

21 Pass 2 Search LITTAB for each literal operand encountered. The data values specified by the literals in each literal pool are inserted at the appropriate places in the object program. In the same way as these values generated by BYTE or WORD statements. If a literal value represents an address in the program, the assembler must generate the appropriate Modification record. (ii) Symbol-Defining Statements EQU directives Assemblers provide an assembler directive EQU that allows the programmer to define the symbol and specify their values. The general syntax to use the EQU is: symbol EQU value When the assembler encounters the EQU statement, it enters symbol into SYMTAB with the value of symbol. Use of EQU (i) Establish symbolic names that can be used for improved readability in place of numeric. values. +LDT #4096 MAXLEN EQU LDT #MAXLEN (ii) Define mnemonic names for registers. A EQU 0 X EQU 1 L EQU 2 (iii) Establish and use names that reflect the logical function of the registers in the program. BASE EQU R1 COUNT EQU R2 INDEX EQU R3 Prepared by P.Vasantha kumari 34

22 ORG directives The assembler directive ORG is usually used to indirectly assign values to symbols. The general syntax to use the ORG directive is: ORG value value is a constant or an expression involving constants and previously defined symbols. When this statement is encountered, the assembler resets its location counter (LOCCTR) to the specified value. Since the values of symbols are taken from LOOCTR, the ORG statement will affect the values of all labels defined until the next ORG. Use ORG for label definition Suppose that we want to define a table with the following structure. SYMBOL field - 6 bytes VALUE field - 3 bytes or 1 word FLAG field - 2 bytes SYMBOL field contains user defined symbols. VALUE field defines the value assigned to the symbol and FALG field specifies the symbol type and other information. STAB (100 Entries) SYMBOL VALUE FLAGS To reserve the space for symbol table, we can write STAB RESB 1100 Totally, 1100 bytes are reserved for 100 entries. The EQU directive is used to define the labels for the symbol table such as SYMBOL, VALUE and FLAG using the following statements: STAB RESB 1100 SYMBOL EQU STAB VALUE EQU STAB+6 FLAGS EQU STAB+9 Prepared by P.Vasantha kumari 35

23 We can fetch the VALUE field from the table entry indicated by the contents of register X using LDA VALUE, X The same symbol definition using ORG is as follows: STAB RESB 1100 ORG STAB SYMBOL RESB 6 VALUE RESW 1 FLAGS RESB 2 ORG STAB+1100 The first ORG resets the LOOCTR to the value of STAB and the last ORG set the LLOCCR back to its previous value. Restrictions of EQU and ORG in an ordinary two-pass assembler For an ordinary two-pass assembler, all symbols must be defined during Pass 1. Hence, the following sequences could not be processed by an ordinary two-pass assembler. All terms used to specify the value of the new symbol must have been defined previously in the program. Example1: ALPHA EQU BETA BETA EQU DELTA DELTA RESW 1 (not valid) Example2: ORG ALPHA BYTE1 RESB 1 BYTE2 RESB 1 BYTE3 RESB 1 ORG ALPHA RESB 1 (not valid) Prepared by P.Vasantha kumari 36

24 Example3: BETA EQU ALPHA ALPHA RESW 1 (not valid) Example4: ALPHA RESW 1 BETA EQU ALPHA (valid) (iii) Expressions Most assemblers allow the use of expressions whenever a single operand such as a label or literal is permitted. Each such expression must be evaluated by the assembler to produce a single operand address or value. Assemblers generally allow arithmetic expressions formed according to the normal rule using the operators +,-,*, and /. Individual terms in the expression may be constants, user-defined symbols, or special terms. The most common special term is the current value of the location counter (often designated by *) Types of terms Absolute terms -> The value of an absolute term is independent of program location. Relative terms -> The value of a relative term is dependent on the beginning address of the program. Types of expressions By the type of value produced, expressions can classified as Absolute expressions: The value of an absolute expression is independent of the program location. The absolute expression may contains relative terms provided the relative terms occur in pairs and the terms in each such pair have opposite signs. No relative term can enter multiplication or division operation. e.g. MAXLEN EQU BUFEND-BUFFER Relative expressions: The value of a relative expression is relative the beginning address of the object program. Expressions that are neither relative nor absolute should be flagged by the assembler as errors. Relative expressions can be written as S+r where S is the starting address of the program r is the relative term related to the beginning of the program. Prepared by P.Vasantha kumari 37

25 (iv) Program Blocks It refers to segments of code that are rearranged within a single object program unit. The assembler directive USE is used to define the block for the program statements. The general syntax for USE directive is: USE [block name] Three blocks are used in the assembly language program. They are: o Unnamed Program block (default block) o CDATA block o CBLKS block At the beginning, statements are assumed to be part of the unnamed (default) block. If no USE statements are included, the entire program belongs to this single block. Each program block may actually contain several separate segments of the source program. Implementation of Program Blocks Pass 1 Each program block has a separate location counter Each label is assigned an address that is relative to the start of the block that contains it At the end of Pass 1, the latest value of the location counter for each block indicates the length of that block The assembler can then assign to each block a starting address in the object program Pass 2 The address of each symbol can be computed by adding the assigned block starting address and the relative address of the symbol to that block 2.6 One Pass Assembler The one-pass assembler is used if it is necessary and desirable to avoid a second pass over program. A one-pass assembler scans the program just once. The main problem in trying to assemble a program in one pass involves forward references. All storage reservation statements can be defined before they are referenced. But, forward references to labels on Prepared by P.Vasantha kumari 38

26 instructions cannot be eliminated as easily. The logic of the program often needs a forward jump. The one-pass assembler must make some special provision for handling forward references. Two types of one-pass assemblers 1. One type of one-pass assemblers produces object code directly in memory for immediate execution. No object program is written out. No loader is needed. 2. The other type of one-pass assemblers produces the usual kind of object program for later execution. Load-and-go assembler The assembler that does not write object program out and does not need a loader is called a Load -and-go assembler. It avoids the overhead of writing the object program out and reading it back in. It is useful in a system that is oriented toward program development and testing. A load-and-go assembler can be a one-pass assembler or a two-pass assembler. Handling of forward references in one-pass load-and-go assembler The assembler generates object code instructions as it scans the source program. If an instruction operand is a symbol that has not yet been defined, the symbol is entered into the symbol table with a flag indicating that the symbol is undefined; the operand address is omitted when the instruction is assembled; the operand address is added to a list of forward references associated with the symbol table entry. When the definition for a symbol is encountered, the forward reference list for that symbol is scanned, and the proper address is inserted into any instructions previously generated. Algorithm Read first input line if OPCODE= START then Prepared by P.Vasantha kumari 39

27 Save #[OPERAND] a starting address Initialize LOCCTR to starting address Write line to intermediate file Read next input line End (if START) Else Initialize LOCCTR to 0 While OPCODE END do if this is not a comment line then if there is a symbol in the LABEL filed then Search SYMTAB for LABEL if found then if <symbol value> as NULL set <symbol value> as LOCCTR and search the linked list with corresponding operand PTR addresses and generate operand addresses as corresponding symbol values set symbol values as LOOCTR in symbol table and delete linked list End else Insert (LABEL, LOCCTR) into SYMTAB End {if symbol} Search OPTAB for OPCODE if found then Prepared by P.Vasantha kumari 40

28 Search SYMTAB for OPERAND addresses If found then If symbol value not equal to NULL then Store symbol value as OPERAND address Else Insert at the end of the linked list with a node with address as LOCCTR Else Insert (symbol name, NULL) LOCCTR+=3 End else if OPCODE= WORD then Add 3 to LOCCTR and convert comment to object code else if OPCODE= RESW then Add 3* # [OPERAND] to LOOCTR else if OPCODE= RESB then Add # [OPERAND] to LOOCTR else if OPCODE= BYTE then Find length of constant in bytes Add length to LOOCTR Convert constant to object code End If object code will not fit into current Text Record then Write Text Record to object program initialize new Text Record End Add object code to Text Record End Write listing line Prepared by P.Vasantha kumari 41

29 Read next input line End Write last Text Record to object program Write End Record to object program Write last listing line End {one pass} Explanation Step 1: Read the input line. Step 2: Check to see if the opcode field in the input line is START. 1. Find if there is any operand field after START; initialize the LOCCTR to the operand value. 2. Otherwise if there is no value in the operand field the LOCCTR is set to zero. Step 3: Write the line onto the output file. Step 4: Repeat the following for the other lines in the input file until the opcode field contains END directive. 1. If there is a symbol in the label field. i. Check the symbol table to see if has already been stored and if it is marked as undefined entry. If so then update the symbol table with the proper address and mark it as defined entry. ii. Other wise the symbol is entered into the symbol table along with the memory address in which it is stored. 2. If there is an opcode in the opcode field i. Search the OPTAB to see if the opcode is present, if so increment the location counter (LOCCTR) by three. ii. a) If the opcode is WORD, increment the LOCCTR by three and convert the constants in the operand field to the object code. b) If the opcode is BYTE, increment the LOCTR by one and convert the constants in the operand field to the object code. c) If the opcode is RESW, increment the LOCCTR by integer equivalent of the operand value *3 and convert the constants in the operand field to the object Prepared by P.Vasantha kumari 42

30 code. d) If the opcode is RESB, increment the LOCCTR by the integer equivalent of the operand value and convert the constants in the operand field to the object code. 3. If there is a symbol in the operand field. i. Check the symbol table to see if has already been stored. If so, then assemble the object code by combining the machine code equivalent of the instruction with the symbol address. ii. Other wise the symbol is entered into the symbol table and it is marked as undefined entry. 4. If there is no symbol in the operand field, then operand address is assigned as zero, and it is assembled with the machine code equivalent of the instruction. 5. Write the input line along with the object code onto output file. Step 5: Close all the opened files and exit. Example Source Program with object code Prepared by P.Vasantha kumari 43

31 Memory Address Contents F xxxxxx xxxxxxxx 1010 xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxx C C2012. Symbol Table 2.7 Multi Pass Assembler Multi pass assembler which translate the assembly language program into the machine code or object code in multiple passes. It is used to eliminate forward references in symbol definition. It creates a number of passes that is necessary to process the definition of symbols. It is unnecessary for a multi-pass assembler to make more than two Prepared by P.Vasantha kumari 44

32 passes over the entire program. Instead, only the parts of the program involving forward references need to be processed in multiple passes. The method presented here can be used to process any kind of forward references. If we use a two-pass assembler, the following symbol definition cannot be allowed. ALPHA EQU BETA BETA EQU DELTA DELTA RESW 1 This is because ALPHA and BETA cannot be defined in pass 1. Actually, if we allow multipass processing, DELTA is defined in pass 1, BETA is defined in pass 2, and ALPHA is defined in pass 3, and the above definitions can be allowed. This is the motivation for using a multi-pass assembler. Multi pass assembler uses a symbol table to store symbols that are not totally defined yet. For a undefined symbol, in its entry, We store the names and the number of undefined symbols which contribute to the calculation of its value. We also keep a list of symbols whose values depend on the defined value of this symbol. When a symbol becomes defined, we use its value to reevaluate the values of all of the symbols that are kept in this list. The above step is performed recursively. Example The following symbols defining statements which involves forward references. HALFSZ EQU MAXLEN/2 MAXLEN EQU BUFEND-BUFFER PREVBT EQU BUFFER-1 BUFFER RESB 4096 BUFEND EQU * These statements would not assign the address for labels within two passes. The following figure displays the symbol table entries resulting from pass 1 processing the first statement. HALFSZ EQU MAXLEN/2 Prepared by P.Vasantha kumari 45

33 MAXLEN has not yet been defined so the value for HALFSZ is not computed. Expression for HALFSZ is stored in the symbol table in place of its value. The entry and 1 indicates that one symbol in the defining expression is undefined. For the next statement, MAXLEN EQU BUFEND-BUFFER There are two undefined symbols involved in the definitions. They are BUFFEND and BUFFER. Both of these are entered into SYMTB with lists indicates the dependence of MAXLEN upon them. The definition of the second statement is shown in the following figure. The next figure shows the defining symbol details of the third statement PREVBT EQU BUFFER-1 Prepared by P.Vasantha kumari 46

34 In this case, a new undefined symbol PREVBT is added to the symbol table and it is also defined from the symbol BUFFER. So, it can be added to the list. The next figure shows that when BUUFEND is defined, MAXLEN and HALFSZ The following figure shows the symbol definitions for the statement BUFFER RESB 4096 In this case, BUFFER symbol is defined. From this symbol definition, PREVBT can be defined accordingly. The next figure shows the complete symbol table entries after defining the statement BUFEND EQU * In this case, BUFFEND symbol is defined. The current value of LOCCTR will be assigned to BUFFEND. From this symbol definition, MAXLEN and HALFSZ can be determined Prepared by P.Vasantha kumari 47

35 accordingly. This completes the symbol definition process. If any symbols remains undefined at the end of the program, the assembler would flag them as errors. 2.8 Implementation Examples MASM Assembler An MASM assembler language program is written as a collection of segments. Each segment is defined as belonging to a particular class, corresponding to its contents. Commonly used classes are CODE, DATA, CONST and STACK. Segments are addressed via x86 segment registers during the program execution. Code segments are addressed using code segment register CS, and stack segments are addressed using stack segment register SS. Thee segment registers are automatically set by the system loader when a program is loaded for execution. Register CS is set to indicate the segment that contains the starting address specified in the END statement of the program. Data segments including constants segments are addressed using DS, ES, FS, or GS. The segment register can be specified explicitly by the programmer. If the programmer does not specify a segment register, one is selected by the assembler. By default, the assembler assumes the default register is DS. The register can be changed using the assembler directive ASSUME. For example, ASSUME ES: DATASEG1 Prepared by P.Vasantha kumari 48

36 tells the assembler to assume the register ES indicates the segment DATASEG1. Jump instructions are assembled in two different ways, depending on whether the target of the jump is in the same code segment or in different code segment. A near jump is a jump to a target in the same code segment; a far jump is a jump to a target in a different code segment. A near jump is assembled using current code segment register CS and far jump must be assembled using different segment register, which is specified in an instruction prefix. Near jump instruction occupies 2 or 3 bytes of memory (depending upon whether the jump address s within 128 bytes of the current instruction) where as far jump occupies 5 bytes of memory. By default, MASM assumes that a forward jump is near jump. If the target of the jump is in another code segment, the programmer must warn the assembler by writing JMP FAR PTR TARGET If the jump address is within 128 bytes of the current instruction, the programmer can specify the shorter (2-bytes) near jump by writing JMP SHORT TAGET If the JMP to TARGET is a far jump, and the programmer does not specify PTR, a problem occurs. During pass 1, the assembler reserves 3 bytes for the jump instruction. The actual assembled instruction requires 5 bytes. In the earlier version, it causes an error. In later versions, the MASM assembler can repeat pass 1 to general location counter values. The length of the instruction depends on the operands that are used. Immediate operands may occupy from 1to 4 bytes in the instruction. An operand that specifies a memory location may take various amount of space in the instruction. Segments in an MASM can be written in more than one part. If a segment directive specifies the same name a s a previously defined segment, it is considered to be a continuation of that segment. References between the segments are handled by assembler and the external references are handled by the linker. Prepared by P.Vasantha kumari 49

37 MAM assembler which allows easy and efficient execution of the program in a variety of operating system environments. It also produce an instruction timing listing that shows the number of clock cycles required to execute each machine instruction. Prepared by P.Vasantha kumari 50

Chapter 2. Assembler Design

Chapter 2. Assembler Design Chapter 2 Assembler Design Assembler is system software which is used to convert an assembly language program to its equivalent object code. The input to the assembler is a source code written in assembly

More information

Unit 2 -- Outline. Basic Assembler Functions Machine-dependent Assembler Features Machine-independent Assembler Features Assembler Design Options

Unit 2 -- Outline. Basic Assembler Functions Machine-dependent Assembler Features Machine-independent Assembler Features Assembler Design Options Unit 2 -- Outline Basic Assembler Functions Machine-dependent Assembler Features Machine-independent Assembler Features Assembler Design Options Introduction to Assemblers Fundamental functions translating

More information

Assemblers. System Software by Leland L. Beck. Chapter 2

Assemblers. System Software by Leland L. Beck. Chapter 2 Assemblers System Software by Leland L. Beck Chapter 2 1 Role of Assembler Source Program Assembler Object Code Linker Executable Code Loader 2 Chapter 2 -- Outline Basic Assembler Functions Machine-dependent

More information

UNIT II ASSEMBLERS www.noyesengine.com www.technoscriptz.com 1 1. BASIC ASSEMBLER FUNCTIONS 2. A SIMPLE SIC ASSEMBLER 3. ASSEMBLER ALGORITHM AND DATA STRUCTURES 4. MACHINE DEPENDENT ASSEMBLER FEATURES

More information

Gechstudentszone.wordpress.com

Gechstudentszone.wordpress.com CHAPTER -2 2.1 Basic Assembler Functions: The basic assembler functions are: ASSEMBLERS-1 Translating mnemonic language code to its equivalent object code. Assigning machine addresses to symbolic labels.

More information

INTERNAL TEST (SCHEME AND SOLUTION)

INTERNAL TEST (SCHEME AND SOLUTION) PES Institute of Technology, Bangalore South Campus (Formerly PES School of Engineering) (Hosur Road, 1KM before Electronic City, Bangalore-560 100) Dept of MCA INTERNAL TEST (SCHEME AND SOLUTION) 1 Subject

More information

Introduction SIC, RISC & CISC 0. Introduction to Systems Programming This course aims at: Understanding what is going on behind the scenes The design and implementation of system software, such as Assemblers

More information

Chapter 2 Assemblers Machine-Dependent Assembler Features

Chapter 2 Assemblers Machine-Dependent Assembler Features Chapter 2 Assemblers -- 2.2 Machine-Dependent Assembler Features Outline Instruction format and addressing mode Program relocation Instruction format and addressing mode PC-relative or Base-relative addressing

More information

CS2422 Assembly Language & System Programming

CS2422 Assembly Language & System Programming CS2422 Assembly Language & System Programming November 30, 2006 Today s Topic Assembler: Basic Functions Section 2.1 of Beck s System Software book. Reading Assignment: pages 43-52. Role of Assembler Source

More information

1.Program to find factorial of a given number

1.Program to find factorial of a given number 1.Program to find factorial of a given number DATA SEGMENT X DW 06H FACT DW? DATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA START: MOV AX,DATA MOV DS,AX MOV AX,01H ;Set the value of AX as 01H. MOV CX,X

More information

DHANALAKSHMI SRINIVASAN INSTITUTE OF RESEARCH AND TECHNOLOGY SIRUVACHUR, PERAMBALUR DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

DHANALAKSHMI SRINIVASAN INSTITUTE OF RESEARCH AND TECHNOLOGY SIRUVACHUR, PERAMBALUR DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING DHANALAKSHMI SRINIVASAN INSTITUTE OF RESEARCH AND TECHNOLOGY SIRUVACHUR, PERAMBALUR 621113. DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING CS2304- SYSTEM SOFTWARE PART-B QUESTIONS 1. EXPLAIN THE ARCHITECTURE

More information

Chapter 2 Assemblers Assembler Design Options

Chapter 2 Assemblers Assembler Design Options Chapter 2 Assemblers -- 2.4 Assembler Design Options Outline One-pass assemblers Multi-pass assemblers Two-pass assembler with overlay structure Load-and-Go Assembler Load-and-go assembler generates their

More information

CS2304-SYSTEM SOFTWARE 2 MARK QUESTION & ANSWERS. UNIT I INTRODUCTION

CS2304-SYSTEM SOFTWARE 2 MARK QUESTION & ANSWERS. UNIT I INTRODUCTION CS2304-SYSTEM SOFTWARE 2 MARK QUESTION & ANSWERS. UNIT I INTRODUCTION 1. Define System Software. System software consists of a variety of programs that supports the operations of a computer. Eg. Compiler,

More information

CS2422 Assembly Language & System Programming

CS2422 Assembly Language & System Programming CS2422 Assembly Language & System Programming December 7, 2006 Today s Topic Assembler: Machine Dependent Features SIC/XE Program Relocation Modification Records in an Object File. Study Guide Sections

More information

Chapter 1. Introduction

Chapter 1. Introduction Chapter 1 Introduction This Chapter gives you System Software & Machine Architecture The Simplified Instructional Computer SIC and SIC/XE Traditional (CISC) Machines - Complex Instruction Set Computers

More information

UNIT I - INTRODUCTION

UNIT I - INTRODUCTION UNIT I - INTRODUCTION 1. Define system software. It consists of variety of programs that supports the operation of the computer. This software makes it possible for the user to focus on the other problems

More information

Assembler Design Options

Assembler Design Options Assembler Design Options One and Multi-Pass Assembler So far, we have presented the design and implementation of a two-pass assembler. Here, we will present the design and implementation of One-pass assembler

More information

2.1. Basic Assembler Functions:

2.1. Basic Assembler Functions: 2.1. Basic Assembler Functions: The basic assembler functions are: Translating mnemonic language code to its equivalent object code. Assigning machine addresses to symbolic labels. SOURCE PROGRAM ASSEMBLER

More information

UNIT 1: MACHINE ARCHITECTURE

UNIT 1: MACHINE ARCHITECTURE VTU QUESTION PAPER SOLUTION UNIT 1: MACHINE ARCHITECTURE 1. a) Give the target address generated for the following machine instruction: (i) 032600h (ii) 03C300h (iii) 0310C303h if (B)=006000, (PC)=003000,

More information

Machine dependent Assembler Features

Machine dependent Assembler Features Machine dependent Assembler Features Assembler Features Machine Dependent Assembler Features Instruction formats and addressing modes (SIC/XE) Program relocation Machine Independent Assembler Features

More information

CSI 402 Lecture 5 (Assemblers Continued) 5 1 / 18

CSI 402 Lecture 5 (Assemblers Continued) 5 1 / 18 CSI 402 Lecture 5 (Assemblers Continued) 5 1 / 18 Program Relocation Example 1: Consider the SIC instruction LDA THREE Assume the following: The START directive specifies the value 100 (decimal) The LC

More information

PESIT SOUTHCAMPUS 10CS52: SYSTEM SOFTWARE QUESTION BANK

PESIT SOUTHCAMPUS 10CS52: SYSTEM SOFTWARE QUESTION BANK CS52: SYSTEM SOFTWARE QUESTION BANK Chapter1: MACHINE ARCHITECTURE OBJECTIVE: Main Objective is to Know about the system software and architecture of Various Machines Like SIC, SIC/XE and Programming examples

More information

Chapter 3 Loaders and Linkers -- Machine-Dependent Loader Feature

Chapter 3 Loaders and Linkers -- Machine-Dependent Loader Feature Chapter 3 Loaders and Linkers -- Machine-Dependent Loader Feature Motivation Shortcoming of an absolute loader Programmer needs to specify the actual address at which it will be loaded into memory. It

More information

UNIT 1: MACHINE ARCHITECTURE

UNIT 1: MACHINE ARCHITECTURE VTU QUESTION PAPER SOLUTION UNIT 1: MACHINE ARCHITECTURE 1. Give the target address generated for the following machine instruction: (i) 032600h (ii) 03C300h (iii) 0310C303h if (B)=006000, (PC)=003000,

More information

Gechstudentszone.wordpress.com

Gechstudentszone.wordpress.com UNIT - 1 MACHINE ARCHITECTURE 11 Introduction: The Software is set of instructions or programs written to carry out certain task on digital computers It is classified into system software and application

More information

AS-2883 B.Sc.(Hon s)(fifth Semester) Examination,2013 Computer Science (PCSC-503) (System Software) [Time Allowed: Three Hours] [Maximum Marks : 30]

AS-2883 B.Sc.(Hon s)(fifth Semester) Examination,2013 Computer Science (PCSC-503) (System Software) [Time Allowed: Three Hours] [Maximum Marks : 30] AS-2883 B.Sc.(Hon s)(fifth Semester) Examination,2013 Computer Science (PCSC-503) (System Software) [Time Allowed: Three Hours] [Maximum Marks : 30] Note: Question Number 1 is compulsory. Marks : 10X1

More information

Chapter 3 Loaders and Linkers

Chapter 3 Loaders and Linkers Chapter 3 Loaders and Linkers Outline 3.1 Basic Loader Functions 3.2 Machine-Dependent Loader Features 3.3 Machine-Independent Loader Features 3.4 Loader Design Options 3.5 Implementation Examples Introduction

More information

Chapter 3 Loaders and Linkers

Chapter 3 Loaders and Linkers Chapter 3 Loaders and Linkers Outline 3.1 Basic Loader Functions 3.2 Machine-Dependent Loader Features 3.3 Machine-Independent Loader Features 3.4 Loader Design Options 3.5 Implementation Examples Introduction

More information

UNIT III - LOADERS AND LINKERS

UNIT III - LOADERS AND LINKERS 3.1 Introduction to Loaders UNIT III - LOADERS AND LINKERS A loader is the part of an operating system that is responsible for loading programs into memory and prepares them for execution. Loading a program

More information

Systems Programming Assemblers Part 3-3 Program Blocks

Systems Programming Assemblers Part 3-3 Program Blocks Systems Programming Assemblers Part 3-3 Program Blocks Prof. Dr. Hani Mahdi Department of Computer Science Al-Isra University, Amman, Jordan Assembler Design 2. Basic Assembler Functions 2.2 Machine Dependent

More information

Systems Programming Assemblers Part 4 Control Sections

Systems Programming Assemblers Part 4 Control Sections Systems Programming Assemblers Part 4 Control Sections Prof. Dr. Hani Mahdi Department of Computer Science Al-Isra University, Amman, Jordan 1 1 Control Sections A Control Section is a part of the program

More information

Chapter 1: Background

Chapter 1: Background Chapter 1: Background Hsung-Pin Chang Department of Computer Science National Chung Hsing University Outline 1.1 Introduction 1.2 System Software and Machine Architecture 1.3 The Simplified Instructional

More information

ASSEMBLERS. Prof. S.J. Soni, SPCE, Visnagar

ASSEMBLERS. Prof. S.J. Soni, SPCE, Visnagar ASSEMBLERS Prof. S.J. Soni, SPCE, Visnagar Design Specifications Identify the information necessary to perform a task Design a suitable data structure to record the information Determine the processing

More information

ORG ; TWO. Assembly Language Programming

ORG ; TWO. Assembly Language Programming Dec 2 Hex 2 Bin 00000010 ORG ; TWO Assembly Language Programming OBJECTIVES this chapter enables the student to: Explain the difference between Assembly language instructions and pseudo-instructions. Identify

More information

UNIT I. Pune Vidyarthi Griha s COLLEGE OF ENGINEERING, NASHIK-4. 1

UNIT I. Pune Vidyarthi Griha s COLLEGE OF ENGINEERING, NASHIK-4. 1 Pune Vidyarthi Griha s COLLEGE OF ENGINEERING, NASHIK-4. 1 UNIT I Introduction: Components of System Software: Text editors, Loaders, Assemblers, Macro processors, Compilers, Debuggers. Machine Structure,

More information

UNIT III LOADERS AND LINKERS

UNIT III LOADERS AND LINKERS UNIT III LOADERS AND LINKERS INTRODUCTION Loader is a system program that performs the loading function. Many loaders also support relocation and linking. Some systems have a linker (linkage editor) to

More information

CS1203-SYSTEM SOFTWARE UNIT I-INTRODUCTION

CS1203-SYSTEM SOFTWARE UNIT I-INTRODUCTION CS1203-SYSTEM SOFTWARE UNIT I-INTRODUCTION 1. Define system software. It consists of variety of programs that supports the operation of the computer. This software makes it possible for the user to focus

More information

Chapter 2 Assemblers. PDF created with FinePrint pdffactory Pro trial version

Chapter 2 Assemblers. PDF created with FinePrint pdffactory Pro trial version Chapter 2 Assemblers 1 PDF created with FinePrint pdffactry Pr trial versin www.pdffactry.cm Outline 2.1 Basic Assembler Functins 2.2 Machine-Dependent Assembler Features 2.3 Machine-Independent Assembler

More information

SRI VENKATESWARA COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF ECE EC6504 MICROPROCESSOR AND MICROCONTROLLER (REGULATION 2013)

SRI VENKATESWARA COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF ECE EC6504 MICROPROCESSOR AND MICROCONTROLLER (REGULATION 2013) SRI VENKATESWARA COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF ECE EC6504 MICROPROCESSOR AND MICROCONTROLLER (REGULATION 2013) UNIT I THE 8086 MICROPROCESSOR PART A (2 MARKS) 1. What are the functional

More information

Chapter 3 Loaders and Linkers

Chapter 3 Loaders and Linkers Chapter 3 Loaders and Linkers Three fundamental processes: Loading brings the object program into memory for execution. Relocation modifies the object program so that it can be loaded at an address different

More information

Lecture-30 Assemblers To assemble a program automatically the assembler needs information in the form of assembler direct that controls the assembly.

Lecture-30 Assemblers To assemble a program automatically the assembler needs information in the form of assembler direct that controls the assembly. Lecture-30 Assemblers To assemble a program automatically the assembler needs information in the form of assembler direct that controls the assembly. E.g. the assembler must be told at what address to

More information

Compiler, Assembler, and Linker

Compiler, Assembler, and Linker Compiler, Assembler, and Linker Minsoo Ryu Department of Computer Science and Engineering Hanyang University msryu@hanyang.ac.kr What is a Compilation? Preprocessor Compiler Assembler Linker Loader Contents

More information

COMPILERS BASIC COMPILER FUNCTIONS

COMPILERS BASIC COMPILER FUNCTIONS COMPILERS BASIC COMPILER FUNCTIONS A compiler accepts a program written in a high level language as input and produces its machine language equivalent as output. For the purpose of compiler construction,

More information

國立嘉義大學資訊工程學系系統程式期中考考卷

國立嘉義大學資訊工程學系系統程式期中考考卷 國立嘉義大學資訊工程學系系統程式期中考考卷 學號 : 姓名 : 1. Please write the content in the lines. (25%) PROGB START EXTDEF B1, B2 EXTREF A1 LDA B1 +LDA A1 STA B1 +STA A1 B1 WORD 7 BUF RESB 1 B2 RESW 1 MAX EQU 1 END H^PROGA^^

More information

The Instruction Set. Chapter 5

The Instruction Set. Chapter 5 The Instruction Set Architecture Level(ISA) Chapter 5 1 ISA Level The ISA level l is the interface between the compilers and the hardware. (ISA level code is what a compiler outputs) 2 Memory Models An

More information

Prepared By : Ms. Sanchari Saha ( Asst. Professor) Department : Computer Science & Engineering

Prepared By : Ms. Sanchari Saha ( Asst. Professor) Department : Computer Science & Engineering Subject Name: System Software Subject Code: 10CS52 Prepared By : Ms. Sanchari Saha ( Asst. Professor) Department : Computer Science & Engineering Date : 20-10-2014 UNIT-4 LOADERS & LINKERS Engineered for

More information

SPOS MODEL ANSWER MAY 2018

SPOS MODEL ANSWER MAY 2018 SPOS MODEL ANSWER MAY 2018 Q 1. a ) Write Algorithm of pass I of two pass assembler. [5] Ans :- begin if starting address is given LOCCTR = starting address; else LOCCTR = 0; while OPCODE!= END do ;; or

More information

Computer Organization & Assembly Language Programming. CSE 2312 Lecture 15 Addressing and Subroutine

Computer Organization & Assembly Language Programming. CSE 2312 Lecture 15 Addressing and Subroutine Computer Organization & Assembly Language Programming CSE 2312 Lecture 15 Addressing and Subroutine 1 Sections in 8088 Code TEXT section, for the processor instructions. DATA section for the initialization

More information

8086 ALP TOOLS (CH 2) CHAPTER 2

8086 ALP TOOLS (CH 2) CHAPTER 2 1 CHAPTER 2 In this chapter, we shall discuss the Assembly Language Program development tools, PC memory structure and Assembler directives. Books to be Referred: 1. Microprocessors and Interfacing 2nd

More information

Question Bank Part-A UNIT I- THE 8086 MICROPROCESSOR 1. What is microprocessor? A microprocessor is a multipurpose, programmable, clock-driven, register-based electronic device that reads binary information

More information

We briefly explain an instruction cycle now, before proceeding with the details of addressing modes.

We briefly explain an instruction cycle now, before proceeding with the details of addressing modes. Addressing Modes This is an important feature of computers. We start with the known fact that many instructions have to include addresses; the instructions should be short, but addresses tend to be long.

More information

UNIT-IV: MACRO PROCESSOR

UNIT-IV: MACRO PROCESSOR UNIT-IV: MACRO PROCESSOR A Macro represents a commonly used group of statements in the source programming language. A macro instruction (macro) is a notational convenience for the programmer o It allows

More information

Lecture #2 January 30, 2004 The 6502 Architecture

Lecture #2 January 30, 2004 The 6502 Architecture Lecture #2 January 30, 2004 The 6502 Architecture In order to understand the more modern computer architectures, it is helpful to examine an older but quite successful processor architecture, the MOS-6502.

More information

PSD1C SYSTEM SOFTWAE UNIT: I - V PSD1C SYSTEM SOFTWARE

PSD1C SYSTEM SOFTWAE UNIT: I - V PSD1C SYSTEM SOFTWARE PSD1C SYSTEM SOFTWAE UNIT: I - V 1 Syllabus Unit-I Language Processors Types of Language Processors Language Processing Activities Fundamentals of Language Processing Language Specification Data Structures

More information

reply db y prompt db Enter your favourite colour:, 0 colour db 80 dup(?) i db 20 k db? num dw 4000 large dd 50000

reply db y prompt db Enter your favourite colour:, 0 colour db 80 dup(?) i db 20 k db? num dw 4000 large dd 50000 Declaring Variables in Assembly Language As in Java, variables must be declared before they can be used Unlike Java, we do not specify a variable type in the declaration in assembly language Instead we

More information

Machine and Assembly Language Principles

Machine and Assembly Language Principles Machine and Assembly Language Principles Assembly language instruction is synonymous with a machine instruction. Therefore, need to understand machine instructions and on what they operate - the architecture.

More information

TRB-COMPUTER INSTRUCTOR COMPUTER SCIENCE UNIT IV. SYSTEM SOFTWARE 10% DISCOUNT FOR ALL PGTRB MATERIALS WITH QUESTION BANK.

TRB-COMPUTER INSTRUCTOR COMPUTER SCIENCE UNIT IV.  SYSTEM SOFTWARE 10% DISCOUNT FOR ALL PGTRB MATERIALS WITH QUESTION BANK. N COACHING CENTRE-TRICHY- TRB- COMPUTER INSTRUCTOR-COMPUTER SCIENCE STUDY MATERIAL-CONTACT: 822006 2017 N TRB-COMPUTER INSTRUCTOR COMPUTER SCIENCE UNIT IV SYSTEM SOFTWARE 10% DISCOUNT FOR ALL PGTRB MATERIALS

More information

CPU. Fall 2003 CSE 207 Digital Design Project #4 R0 R1 R2 R3 R4 R5 R6 R7 PC STATUS IR. Control Logic RAM MAR MDR. Internal Processor Bus

CPU. Fall 2003 CSE 207 Digital Design Project #4 R0 R1 R2 R3 R4 R5 R6 R7 PC STATUS IR. Control Logic RAM MAR MDR. Internal Processor Bus http://www.engr.uconn.edu/~barry/cse207/fa03/project4.pdf Page 1 of 16 Fall 2003 CSE 207 Digital Design Project #4 Background Microprocessors are increasingly common in every day devices. Desktop computers

More information

EECE416 :Microcomputer Fundamentals and Design. X86 Assembly Programming Part 1. Dr. Charles Kim

EECE416 :Microcomputer Fundamentals and Design. X86 Assembly Programming Part 1. Dr. Charles Kim EECE416 :Microcomputer Fundamentals and Design X86 Assembly Programming Part 1 Dr. Charles Kim Department of Electrical and Computer Engineering Howard University www.mwftr.com 1 Multiple Address Access

More information

68000 Architecture, Data Types and Addressing Modes. 9/20/6 Lecture 2 - Prog Model 1

68000 Architecture, Data Types and Addressing Modes. 9/20/6 Lecture 2 - Prog Model 1 68000 Architecture, Data Types and Addressing Modes 9/20/6 Lecture 2 - Prog Model 1 Lecture Overview Assembler Language Programmers Model Registers Addressing Modes 9/20/6 Lecture 2 - Prog Model 2 Assembler

More information

Computer Architecture 1 ح 303

Computer Architecture 1 ح 303 Lecture 4 A. Addressing MODES 1. Introduction to assembly language programming: Program is a sequence of commands used to tell a microcomputer what to do. Each command in a program is an instruction Programs

More information

Summary: Direct Code Generation

Summary: Direct Code Generation Summary: Direct Code Generation 1 Direct Code Generation Code generation involves the generation of the target representation (object code) from the annotated parse tree (or Abstract Syntactic Tree, AST)

More information

The Assembly Language Level. Chapter 7

The Assembly Language Level. Chapter 7 The Assembly Language Level Chapter 7 Definitions Translator Converts user program to another language Source language Language of original program Target language Language into which source code is converted

More information

CC411: Introduction To Microprocessors

CC411: Introduction To Microprocessors CC411: Introduction To Microprocessors OBJECTIVES this chapter enables the student to: Describe the Intel family of microprocessors from 8085 to Pentium. In terms of bus size, physical memory & special

More information

Microprocessor. By Mrs. R.P.Chaudhari Mrs.P.S.Patil

Microprocessor. By Mrs. R.P.Chaudhari Mrs.P.S.Patil Microprocessor By Mrs. R.P.Chaudhari Mrs.P.S.Patil Chapter 1 Basics of Microprocessor CO-Draw Architecture Of 8085 Salient Features of 8085 It is a 8 bit microprocessor. It is manufactured with N-MOS technology.

More information

Microprocessor and Assembly Language Week-5. System Programming, BCS 6th, IBMS (2017)

Microprocessor and Assembly Language Week-5. System Programming, BCS 6th, IBMS (2017) Microprocessor and Assembly Language Week-5 System Programming, BCS 6th, IBMS (2017) High Speed Memory Registers CPU store data temporarily in these location CPU process, store and transfer data from one

More information

Blog -

Blog - . Instruction Codes Every different processor type has its own design (different registers, buses, microoperations, machine instructions, etc) Modern processor is a very complex device It contains Many

More information

The A ssembly Assembly Language Level Chapter 7 1

The A ssembly Assembly Language Level Chapter 7 1 The Assembly Language Level Chapter 7 1 Contemporary Multilevel Machines A six-level l computer. The support method for each level is indicated below it.2 Assembly Language Level a) It is implemented by

More information

SCRAM Introduction. Philipp Koehn. 19 February 2018

SCRAM Introduction. Philipp Koehn. 19 February 2018 SCRAM Introduction Philipp Koehn 19 February 2018 This eek 1 Fully work through a computer circuit assembly code Simple but Complete Random Access Machine (SCRAM) every instruction is 8 bit 4 bit for op-code:

More information

COMPUTER ORGANIZATION & ARCHITECTURE

COMPUTER ORGANIZATION & ARCHITECTURE COMPUTER ORGANIZATION & ARCHITECTURE Instructions Sets Architecture Lesson 5a 1 What are Instruction Sets The complete collection of instructions that are understood by a CPU Can be considered as a functional

More information

Chapter 11. Instruction Sets: Addressing Modes and Formats. Yonsei University

Chapter 11. Instruction Sets: Addressing Modes and Formats. Yonsei University Chapter 11 Instruction Sets: Addressing Modes and Formats Contents Addressing Pentium and PowerPC Addressing Modes Instruction Formats Pentium and PowerPC Instruction Formats 11-2 Common Addressing Techniques

More information

CS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng.

CS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng. CS 265 Computer Architecture Wei Lu, Ph.D., P.Eng. Part 5: Processors Our goal: understand basics of processors and CPU understand the architecture of MARIE, a model computer a close look at the instruction

More information

VARDHAMAN COLLEGE OF ENGINEERING (AUTONOMOUS) Shamshabad, Hyderabad

VARDHAMAN COLLEGE OF ENGINEERING (AUTONOMOUS) Shamshabad, Hyderabad Introduction to MS-DOS Debugger DEBUG In this laboratory, we will use DEBUG program and learn how to: 1. Examine and modify the contents of the 8086 s internal registers, and dedicated parts of the memory

More information

Chapter 2 Instruction Set Architecture

Chapter 2 Instruction Set Architecture Chapter 2 Instruction Set Architecture Course Outcome (CO) - CO2 Describe the architecture and organization of computer systems Program Outcome (PO) PO1 Apply knowledge of mathematics, science and engineering

More information

CPU ARCHITECTURE. QUESTION 1 Explain how the width of the data bus and system clock speed affect the performance of a computer system.

CPU ARCHITECTURE. QUESTION 1 Explain how the width of the data bus and system clock speed affect the performance of a computer system. CPU ARCHITECTURE QUESTION 1 Explain how the width of the data bus and system clock speed affect the performance of a computer system. ANSWER 1 Data Bus Width the width of the data bus determines the number

More information

icroprocessor istory of Microprocessor ntel 8086:

icroprocessor istory of Microprocessor ntel 8086: Microprocessor A microprocessor is an electronic device which computes on the given input similar to CPU of a computer. It is made by fabricating millions (or billions) of transistors on a single chip.

More information

Chapter Three Addressing Mode MOV AX, BX

Chapter Three Addressing Mode MOV AX, BX Chapter Three The 8086 The 8086 When the 8086 executes an instruction, it performs the specified function on data. The data are called its operands and may be part of the instruction reside in one of the

More information

William Stallings Computer Organization and Architecture 8 th Edition. Chapter 11 Instruction Sets: Addressing Modes and Formats

William Stallings Computer Organization and Architecture 8 th Edition. Chapter 11 Instruction Sets: Addressing Modes and Formats William Stallings Computer Organization and Architecture 8 th Edition Chapter 11 Instruction Sets: Addressing Modes and Formats Addressing Modes Immediate Direct Indirect Register Register Indirect Displacement

More information

EEM336 Microprocessors I. Data Movement Instructions

EEM336 Microprocessors I. Data Movement Instructions EEM336 Microprocessors I Data Movement Instructions Introduction This chapter concentrates on common data movement instructions. 2 Chapter Objectives Upon completion of this chapter, you will be able to:

More information

An Assembler Written in SAS Ed Heaton, Westat, Rockville, MD

An Assembler Written in SAS Ed Heaton, Westat, Rockville, MD Paper 607 An Assembler Written in SAS Ed Heaton, Westat, Rockville, MD ABSTRACT Is SAS a programming language, i.e. can it handle problems typically in the domain of a real language like C? To prove the

More information

ELEG3924 Microprocessor

ELEG3924 Microprocessor Department of Electrical Engineering University of Arkansas ELEG3924 Microprocessor Ch.2 Assembly Language Programming Dr. Jing Yang jingyang@uark.edu 1 OUTLINE Inside 8051 Introduction to assembly programming

More information

3.0 Instruction Set. 3.1 Overview

3.0 Instruction Set. 3.1 Overview 3.0 Instruction Set 3.1 Overview There are 16 different P8 instructions. Research on instruction set usage was the basis for instruction selection. Each instruction has at least two addressing modes, with

More information

We will study the MIPS assembly language as an exemplar of the concept.

We will study the MIPS assembly language as an exemplar of the concept. MIPS Assembly Language 1 We will study the MIPS assembly language as an exemplar of the concept. MIPS assembly instructions each consist of a single token specifying the command to be carried out, and

More information

ELEG3923 Microprocessor Ch.2 Assembly Language Programming

ELEG3923 Microprocessor Ch.2 Assembly Language Programming Department of Electrical Engineering University of Arkansas ELEG3923 Microprocessor Ch.2 Assembly Language Programming Dr. Jingxian Wu wuj@uark.edu OUTLINE 2 Inside 8051 Introduction to assembly programming

More information

Assembling, Linking and Executing 1) Assembling: .obj obj .obj.lst .crf Assembler Types: a) One pass assembler:

Assembling, Linking and Executing 1) Assembling: .obj obj .obj.lst .crf Assembler Types: a) One pass assembler: Assembling, Linking and Executing 1) Assembling: - Assembling converts source program into object program if syntactically correct and generates an intermediate.obj file or module. - It calculates the

More information

Computer Organization & Assembly Language Programming

Computer Organization & Assembly Language Programming Computer Organization & Assembly Language Programming CSE 2312 Lecture 11 Introduction of Assembly Language 1 Assembly Language Translation The Assembly Language layer is implemented by translation rather

More information

Model Answer of System Software B. Tech. (4 th Semester Examination) Paper Code: AR Branch: Information Technology

Model Answer of System Software B. Tech. (4 th Semester Examination) Paper Code: AR Branch: Information Technology Model Answer of System Software B. Tech. (4 th Semester Examination) Paper Code: AR-9083 Branch: Information Technology Time Allowed: 3hours Maximum Marks: 100 Part-A (All questions are compulsory) Objective

More information

1 Lexical Considerations

1 Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler

More information

Microcontroller Systems

Microcontroller Systems µcontroller systems 1 / 43 Microcontroller Systems Engineering Science 2nd year A2 Lectures Prof David Murray david.murray@eng.ox.ac.uk www.robots.ox.ac.uk/ dwm/courses/2co Michaelmas 2014 µcontroller

More information

Practical Malware Analysis

Practical Malware Analysis Practical Malware Analysis Ch 4: A Crash Course in x86 Disassembly Revised 1-16-7 Basic Techniques Basic static analysis Looks at malware from the outside Basic dynamic analysis Only shows you how the

More information

CHAPTER ASSEMBLY LANGUAGE PROGRAMMING

CHAPTER ASSEMBLY LANGUAGE PROGRAMMING CHAPTER 2 8051 ASSEMBLY LANGUAGE PROGRAMMING Registers Register are used to store information temporarily: A byte of data to be processed An address pointing to the data to be fetched The vast majority

More information

UNIT 4. Modular Programming

UNIT 4. Modular Programming 1 UNIT 4. Modular Programming Program is composed from several smaller modules. Modules could be developed by separate teams concurrently. The modules are only assembled producing.obj modules (Object modules).

More information

Programming in C++ 5. Integral data types

Programming in C++ 5. Integral data types Programming in C++ 5. Integral data types! Introduction! Type int! Integer multiplication & division! Increment & decrement operators! Associativity & precedence of operators! Some common operators! Long

More information

UNIT-II. Part-2: CENTRAL PROCESSING UNIT

UNIT-II. Part-2: CENTRAL PROCESSING UNIT Page1 UNIT-II Part-2: CENTRAL PROCESSING UNIT Stack Organization Instruction Formats Addressing Modes Data Transfer And Manipulation Program Control Reduced Instruction Set Computer (RISC) Introduction:

More information

Principles of Compiler Design

Principles of Compiler Design Principles of Compiler Design Code Generation Compiler Lexical Analysis Syntax Analysis Semantic Analysis Source Program Token stream Abstract Syntax tree Intermediate Code Code Generation Target Program

More information

MIPS (SPIM) Assembler Syntax

MIPS (SPIM) Assembler Syntax MIPS (SPIM) Assembler Syntax Comments begin with # Everything from # to the end of the line is ignored Identifiers are a sequence of alphanumeric characters, underbars (_), and dots () that do not begin

More information

4- MACHINE LANGUAGE CODING 4-1THE INSTRUCTION SET:

4- MACHINE LANGUAGE CODING 4-1THE INSTRUCTION SET: 4- MACHINE LANGUAGE CODING 4-1THE INSTRUCTION SET: The microprocessor's instruction set defines the basic operations that a programmer can specify to the device to perform. Table 4-1 contains list basic

More information

COMPILER CONSTRUCTION LAB 2 THE SYMBOL TABLE. Tutorial 2 LABS. PHASES OF A COMPILER Source Program. Lab 2 Symbol table

COMPILER CONSTRUCTION LAB 2 THE SYMBOL TABLE. Tutorial 2 LABS. PHASES OF A COMPILER Source Program. Lab 2 Symbol table COMPILER CONSTRUCTION Lab 2 Symbol table LABS Lab 3 LR parsing and abstract syntax tree construction using ''bison' Lab 4 Semantic analysis (type checking) PHASES OF A COMPILER Source Program Lab 2 Symtab

More information

Sardar Vallabhbhai Patel Institute of Technology (SVIT), Vasad M.C.A. Department COSMOS LECTURE SERIES ( ) (ODD) Code Optimization

Sardar Vallabhbhai Patel Institute of Technology (SVIT), Vasad M.C.A. Department COSMOS LECTURE SERIES ( ) (ODD) Code Optimization Sardar Vallabhbhai Patel Institute of Technology (SVIT), Vasad M.C.A. Department COSMOS LECTURE SERIES (2018-19) (ODD) Code Optimization Prof. Jonita Roman Date: 30/06/2018 Time: 9:45 to 10:45 Venue: MCA

More information

Machine Language Instructions Introduction. Instructions Words of a language understood by machine. Instruction set Vocabulary of the machine

Machine Language Instructions Introduction. Instructions Words of a language understood by machine. Instruction set Vocabulary of the machine Machine Language Instructions Introduction Instructions Words of a language understood by machine Instruction set Vocabulary of the machine Current goal: to relate a high level language to instruction

More information