Sei sulla pagina 1di 47

SIC MACHINE ARCHITECTURE SUGANYA KEERTHANA 1. Define system software?

System software consists of a variety of programs that support the operation of a computer. Examples: of System software are text editor, compiler, loader, linker, debugger , macro processors, operating system etc. Text editor is used to create and modify the program. Compiler translate the user program into machine language. Loaders are system programs that prepare machine language programs for execution. Debugger- helps to detect errors in the program. Create execution environment where all other applications to run. To get all the resources in the system. 2. Difference between application software and system software? System software : The most important characteristics in which most system software differ from application software. Its Machine dependent. Eg: Assembler translate mnemonic instructions into machine code. Eg: Compiler must generate machine language code. Application software: There are aspects of system software that do not directly depend upon the type of computing system. Eg: general design and logic of the assembler. Eg: code optimization techniques. 3. What is SIC? Simplified Instructional Computer(SIC) is a hypothetical computer that the hardware features most often found on real machines. Two versions of SIC: 1.SIC(Standard model). 2.SIC/XE(XE=Extra equipment). Both the versions are upward compatible, i.e.an object program written for standard SIC machine also execute properly on the other versions of the SIC/XE machine. 4. What is the memory capacity of SIC? Memory consists of 8-bits bytes. Any three consecutive bytes form a word(24 bits). All addresses are byte addresses. 1 word = 24 bits. Total of 32768 (32 k bytes) in the computer memory. 01 2 3 4 5 6 7

5. List the types of registers used in a SIC machine architecture? Registers are plays a vital role in SIC . There are totally 5 regisgters.24 bit in length. S.NO 1. Mnemonic Number Special Use A 0 Accumulator : to perform all the Arithmetic operations. 2. X 1 Index Register: Used for addressing. 3. L 2 Linkage register: jump to Subroutine . Used to stored the Return address. 4. PC 8 Program Counter: It stores the Address of the next instruction to Be executed. 5. SW 9 Status Word: It Stores the Conditional codes.eg: JNC,JEQ, JUMP. 6. What are the data Format available in SIC? Integers: Stored in 24 bit binary numbers. Negative number is represented by using 2s complement format. Characters: Stored in 8 bits ASCII format. Standard version of SIC does not support floating point hardware. 7. Explain the instruction format available in SIC machine? It is 24 bit on a standard version of SCI. Opcode (8) bits X(1) Address (15)

X indicates indexed addressing mode. 8. What are the addressing modes available in SIC machine? Addressing modes are two types: 1.direct addressing mode. 2.Indexed addressing mode. 9. How the target address calculated in direct and indexed addressing mode in SIC machine? If X=0, direct addressing mode . TA will be TA=address.

If X=1 ,indexed addressing mode . TA will be TA= address + X ( content of the indexed register). 10. List out the instruction set available in SIC machine? 1.load and store : LDA, LDX, STA, STX, etc. 2.Integer arithmetic operations: ADD, SUB, MUL, DIV , etc. All arithmetic operations involve register A and a word in memory with the result being left in the register. 3.Comparison: COMP COMP compares the value in register A with a word in memory ;this instruction sets a condition code CC to indicate the result. 4.Conditional jump instructions: JLT, JEQ, JGT. These instructions test the setting of CC and jump accordingly. 5.Subroutine linkage: JSUB, RSUB JSUB jumps to the subroutine , placing the return address in register L. RSUB returns by jumping to the address contained in register L. 11.Explain input and output device in SIC machine? Input and Output are performed by transferring 1 byte at a time to or from the rightmost 8 bits of register A. The Test Device (TD) instruction test whether the addressed device is ready to send or receive a byte of data. Read Data (RD) Write Data (WD). SIC/XE ARCHITECTURE: AMISHA K 1) What is the memory structure of SIC/XE? B1 The memory of SIC/XE consists of 8 bit bytes and is byte addressable. Three consecutive bytes or 24 bits form a word in the memory The maximum memory size on SIC/XE is 1megabytes(i.e) 220 A single byte in memory may be denoted as follows: B2 B3 B4 B5 B6 B7 B8

2) List all the register available in SIC/XE. MNEMONIC NUMBER NAME A 0 Accumulator X 1 Index Register L 2 Linkage Register B 3 Base Register USE For Arithmetic Operations For addressing Stores the return address For addressing

S T F PC SW

4 5 6 8 9

S register T register Floating point accumulator Program Counter Status Word

General working register-No special use General working register- No special use For floating point arithmetic instructions Contains the address of the next instruction to be fetched Contains a variety of information including Condition Codes

3) Explain the floating point data format The floating point data format is 48 bit long. 1 11 36 S Exponent fraction The fraction is interpreted as a value between 0 and 1(i.e) the assured binary point is immediately before the high-order bit. For normalized floating point numbers, the high-order bit of the fraction is 1. The exponent is an unsigned binary number between 0 and 2047. The absolute value of a number is represented by f * 2(e-1024) where, f=fraction value, e=exponent value The value of sdenotes the sign of the floating point number. 0=positive number, 1=negative number

4) Write short notes on format 1 and format 4 of SIC/XE. FORMAT 1: This format is used for instructions that have only the opcode value. The value of the operand is either implicitly specified or it may have no value. It is one byte long. 8 bits Opcode Example RSUB( Return to subroutine) FORMAT 4: This format extends the address field to 20 bits. When bit e is set to 1 it indicates format 4 or extended instruction format. The length of format 4 instructions is 4 bytes(ie) 32 bits. Format 4 instructions begin with +. 6 1 1 1 1 1 1 20

opcode

address

Example +JSUB RDREC (Jump to subroutine) 0100 10 1 1 0 0 0 1 5) Give the format 2 and format 3 of SIC/XE.

0000 0001 0000 0011 0110

FORMAT 2: It is two bytes long. It is used for register to register instructions. It consist of three fields: one for opcode and the other two for the two registers. 8 Opcode Example COMPR A,S 1010 0000 4 r1 4 r2

0000

0100

FORMAT 3: Format 3 is three bytes in length. When bit e=0 it indicates format 3. The displacement field of this format is 12 bits long. It is used for relative addressing. 6 opcode Example LDA #3 0000 00 1 1 n i 1 1 1 1 x b p e 12 Displacement

0000 0000 0011

6) List the various addressing modes in SIC/XE. The various addressing modes available in SIC/XE are: Base relative addressing mode Program counter relative addressing mode Direct addressing mode Indexed addressing mode Indirect addressing mode Immediate addressing mode 7) How is the target address calculated for base relative addressing modes?

BASE RELATIVE Mode: base relative Indication: b=1,p=0 Target address calculation: TA=(B) + disp (0<=disp<=4095) Example LDA LENGTH 0000 00 1 1 0 1 0 0 0000 0000 0011 B=0030 DISP=0003 TA=(B) + DISP = 0030 + 0003 = 0033 8) How is the target address calculated for program counter relative addressing modes? PC RELATIVE Mode: program counter relative Indication: b=0, p=1 Target address calculation: TA=(PC) + disp (-2048<=disp<=2047) Example LDA LENGTH 0000 00 1 1 0 0 1 0 0000 0000 0111 PC=0021 DISP=0007 TA=(PC) + DISP = 0021 + 0007 = 0028 9) What is direct addressing mode? Explain. When both bits p=0, b=0 then the value present in the displacement field for format 3 amfd the value present in the address field for format 4 is taken as the target address. Such type of addressing is called as direct addressing as the target address is specified directly as part of the instruction. TA = DISP/ADDRESS Example LDA LENGTH 0000 00 1 1 0 0 0 0 0000 0000 1011 TA=DISP = 000B 10) What do u mean by immediate addressing mode? If bit i=1 and n=0, the target address itself is used as the operand value. Such type of addressing is called immediate addressing.

In immediate addressing mode no memory reference is performed. Example LDA #3 0000 00 1 1 0 0 0 0 0000 0000 0011 Now the accumulator contains 3. 11) Explain indirect addressing. If the bit n=1 and i=0 then the word at the location given by the target address is fetched. This value contained in the word is the address of the operand value. This is called indirect addressing. Example J @ RETADR 0011 11 1 0 0 0 1 0 0000 0000 1011 PC= 002D DISP=0003 TA= (P) + DISP = 0030 This TA does not contain the operand value. The content of 0030 memory location contains the actual operand value 12) List the various floating-point arithmetic instruction in SIC/XE. The various floating-point instructions are: ADDF- Add the floating point number with the F register content. SUBF- subtract the floating point number with the F register content. MULF- Multiply the floating point number with the F register content. DIVF- divide the floating point number with the F register content. 13) Give the various register to register arithmetic instructions. The various register to register arithmetic instructions are: ADDR: Add the contents of two registers. Example: ADDR A,S SUBR: subtract the contents of two registers. Example: SUBR T,S MULR: multiply the contents of two registers. Example: MULR A,T DIVR: divide the contents of two registers. Example: DIVR A,S 14) Explain SVC instruction. SVC stands for supervisor call.

It is a special instruction provided by SIC/XE. Executing this instruction generates an interrupt that can be used for communication with the operating system.

15) Write short notes about input-output using IO channels. The IO channels are used to perform input and output while the CPU is executing other instructions. This allows overlap of computing and IO, thus improving the efficiency of the system. The instructions SIO,TIO and HIO are used to start,test and halt the operations of IO channels.

SIC AND SIC/XE PROGRAMMING EXAMPLES: HARINI R ANBARASI A 1. What are the various operations available in sic and sic/xe? The various operations available are Data movement operations Arithmetic operations Looping and indexing operations Input and output operations 2. Mention some of the data movement operations in sic? The various data movement operations are LDA,STA,LDCH,STCH. LDA-load the content into register STA-store the content LDCH-load the char content into reg. STCH-store in char variable 3. What are the arithmetic operations available on sic and sic/xe? In sic: ADD,SUB,MUL,DIV,COMP In sic/xe: ADDR,SUBR,MULR,DIVR,COMPR 4. what are the register-to-register instructions available in sic/xe? ADDR-to add between the two register SUBR--to sub between the two register COMPR-to compare the value between two register TIXR-to increase the index value by 1 and compare with specified register

5. How i/o channels are used to perform input and output operations? I/O channels that can be used to perform input and output while the cpu is executing other instructions. this allows overlap of computing and i/o,resulting in more efficient system operations. the instruction SIO,TIO and HIO are used to start,test and halt the operation of i/o signals. 6. what is the function of TIX instruction? TIX command has 2 functions: it adds 1 to the value in register x and then it compares the new value of reg x to the value of the operand. 7. What is the advantage of TIXR instruction?

The main advantage of using TIXR instead of using TIX is that,except that the value used for comparison is taken from another reg,not from memory. This makes the loop more efficient,because the value does not have to be fetched from memory each time the loop is executed. 8. what are the various instructions used in i/o operations in sic and sic/xe? The instructions used are TD(test device),RD(read device) and WD(write device).TD is used to check whether the device is ready for i/o transfer. it sets condition codes. RD and WD are used for data transfer if device is ready. 9. What is the condition to be checked before starting an looping and indexing operation? The main condition is that ,the index register is initialized to 0 before the loop begins.thus when during the first execution of the loop the target address will be the address of the first byte. 10. write a program for data movement operation in sic? LDA FIVE STA ALPHA LDCH CHARZ STCH C1 load constant 5 into reg a store in alpha load char z into reg a store in char variable c1

ALPHA RESW 1 one word variable FIVE WORD 5 one word constant CHARZ BYTE CZ one byte constant C1 RESB 1 one byte variable 11. write a program for data movement operation in sic/xe? LDA #5 STA ALPHA load 5 into reg a store in alpha

LDA #90 STCH C1

load ASCII for z into reg a store in char variable c1

ALPHA RESW 1 one word variable C1 RESB 1 one byte variable 12. write a program for arithmetic operation in sic/xe? LDS INCR LDA ALPHA ADDR S,A SUB #1 STA BETA load value of incr into register s load alpha into reg a add the value of incr subract 1 store in beta

13. give a sample looping and indexing operations in sic/xe? LDT #11 LDX #0 MOVECH LDCH STR1,X STCH STR2,X TIXR T JLT MOVECH 14. write a sample input program for sic? INLOOP initialize T to 11 initialize X to 0 load char str1 to a store char into str2 add 1 to X and compare loop if X<11

TD INDEV test input device JEQ INLOOP loop until device is ready RD INDEV read 1 byte into A STCH DATA store byte that was read 15. write a sample output program for sic? OUTLP TD OUTDEV test output device JEQ outlp loop until device is ready LDCH DATA load data byte into reg WD OUTDEV write 1 byte to outdevice

BASIC ASSEMBLER FUNCTIONS: P.R.MANASA DEVI 1. Define the basic functions of assembler.(or) Write the steps required to translate the source program to object program Convert mnemonic operation codes to their machine language equivalents. Convert symbolic operands to their equivalent machine addresses Build the machine instruction in the proper format. Convert the data constants specified in the source program into their internal machine

representation Write the object program and assembly listing. 2. Define Assembler. An assembler is a set of programs, which is used to translate the assembly language into machine language, and also gives the necessary information to the loader. 3. Write the uses of assembler Directives and give an Example. The Assembler Directives are used to give necessary information to the Assembler. They are the guidelines which instruct the asssember to perform some specific actions.The Assembler Directives are, START: Specifies name and starting address of the program. RESW: Reserves word RESB: Reserves byte END : Indicates the end of the source program 4.What is forward references? It is a reference to a label that is defined later in a program. Consider the statement 10 1000 STL RETADR .... .... 80 1036 RETADR RESW 1 The first instruction contains a forward reference RETADR.If we attempt to translate the program line by line,we will unable to process the statement in line10 because we do not know the address that will be assigned to RETADR .The address is assigned later(in line 80) in the program. 5.What are the three different records used in object program? The header record,text record and the end record are the three different records used in object program. The header record contains the program name,starting address and length of the program. Text record contains the translated instructions and data of the program. End record marks the end of the object program and specifies the address in the program where execution is to begin. 6.What are the parameters which assembler rely upon?

1.scanning 2.parsing 3.creating symbol table 4.resolving forward references 5.converting into machine language 7.How are assembler directives used ? They can be used to o To declare variables o Create storage space for results o To declare constants 8.What are the information contained in the records? Header record: Col 1: H Col 2-7: Program name Col 8-13:Starting address of object program(hexadecimal) Col 14-19:Length of object program in bytes(hexadecimal) Text record: Col 1: T Col 2-7: Starting address of object program(hexadecimal) Col 8-9: Length of object program in bytes(hexadecimal) Col 10-19: Object code,represented in hexadecimal(2 cols per byte of object code) End record: Col 1:E Col 2:Address of first executable instruction in obj program(hexadecimal) 9.Give a note on functions of two passess of simple assembler. Pass 1: 1.Assign addresses to all statements in the program. 2.Save the values assigned to all labels for use in Pass 2. 3.Perform some processing of assembler directives.

Pass 2: 1.Assembler instructions(translate operation codes and look-up addresses) 2.Generate data values defined by BYTE,WORD,etc 3.Perform processing of assembler directives not done during Pass 1. 4.Write the obj program and the assembly listing. DATA STRUCTURES AND ALGORITHMS 1. What is the data structure used to organize the SYMTAB and OPCODE table in a simple assembler? Why it is preferred? OPTAB is used to look up mnemonic operation codes and translate them to their machine language equivalents. SYMTAB is used to store values (addresses) assigned to labels. 2. Consider the following sequence

X EQU Y Y EQU Z Z RESW 1 In a 2-pass assembler can resolve such a sequence of definition. Justify your answer. No. The symbol Y cannot be assigned a value when it is encountered during the first pass because Z has not yet been defined. As a result, X cannot be evaluated during the second pass. This means that any assembler that makes only two sequential passes over the source program cannot resolve such a sequence of definitions. 3. What is SYMTAB? How it is useful? The Symbol table (SYMTAB) includes the name and value (addresses) for each label in the source program, together with flags to indicate error conditions. SYMTAB is usually organized as a hash table for efficiency of insertion and retrieval. 4. List out the machine independent assembler features 1. 2. 3. 4. 5. 5. The machine independent assembler features are Literals Symbol defining statements Expressions Program blocks Control Sections and Program Linking. What is the need for an assembler directive?

In addition to translating the instructions of the source program, the assembler must process statements called assembler directives or pseudo-instructions. These statements are not translated into machine instructions. Instead, they provide instructions to the assembler itself. Examples: 1. BYTE and WORD direct the assembler to generate constants as part of the object program. 2. RESB and RESW instruct the assembler to reserve memory locations without generating data values. 3. START specifies the starting memory address for the object program. 4. END marks the end of the program. 6. What is the use of location counter? 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 LOCCTR. Thus whenever we reach a label in the source program, the current value of LOCCTR gives the address to be associated with that label. 7. What does an assembler perform when it encounters LTORG assembler directive. When the assembler encounters a LTORG statement, it creates a literal pool that contains all of the literal operands used since the previous LTORG (or the beginning of the program). This literal pool is placed in the object program at the location where the LTORG directive was encountered. 8. Write down the pass numbers either (Pass 1 or Pass 2) of the following activities that occur in a 2-pass assembler. i) object code generation ii) Literals added to literal table iii) Printing assembly listing iv) address resolution of local symbols 9. List the types of assembler 1. 2. 3. one pass assembler two pass assembler multipass assembler. -

10. How can the assembler overcome the problem of forward reference? The assembler overcome the problem of forward reference through two pass and multipass assemblers.

The first pass does little more than scan the source program for label definitions an assign addresses. The second pass performs most of the actual translation previously described. 11. Write the uses of program relocation 1. 2. 3. Sharing the memory location for the different programs. Avoid the wastage of processing or execution time. Reduce the wastage of memory space.

12. How are jump instructions assembled? Jump instructions are assembled in two different ways, depending on whether the target of the jump is in the same code segment as the jump instruction. 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. 13. What are the functions required to translate source program to object code? It requires the following 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 specified in the source program into their internal machine representations. 5. Write the object program and the assembly listing. 1. 2. 3. 4. 14. What is forward reference? A reference to a label (RETADR) that is defined later in the program is called forward reference. 15. What is object program? What are the records used to write an object program The object program is a program written with the generated object codes for an assembly language program. There are three types of records 1. Header record 2. Text record and 3. End record. LITERALS 1. Define Literals. The constant operand is written as part of the instruction that uses it and is stated literally in the instruction is called literals.

This avoids having to define constant elsewhere in the program and make up a label for it. A literal is identified with a prefix '=' followed by a specification of the literal value. 2. What is the assembler notation? A literal is identified with a prefix = followed by a specification of the literal value. The notation used for literals varies from assembler to assembler. 3.Write an example code showing the difference between the noraml program and program using literals. NORMAL PROGRAM: LINE LOC LABEL 45 80 001A ENDFIL OPCODE LDA OPERAND EOF 032010 454F46 OBJECT CODE

002D EOF BYTE----> c'EOF'----->

PROGRAM USING LITERALS: LINE LOC LABEL 45 001A ENDFIL 002D * OPCODE LDA =C'EOF' OPERAND =C'EOF' OBJECT CODE 032010 454F46

* It is a convenient to write the value of a constant operand as a part of the instruction. * Object code for the program is same for the normal program as well as program using literals. 4. Write the difference and similarities between the literals and immediate operands. SIMILARITIES: Operand field contains constant values. DIFFERENCES: * Immediate addressing The assembler put the constant value as a part of the machine

instruction. LINE LOC LABEL 55 20 LDA OPCODE #B OPERAND 10003 OBJECT CODE

* Literals The assembler store the constant value elsewhere and put the address as part of the machine instruction. LINE LOC LABEL 45 001A ENDFIL OPCODE LDA OPERAND =C'EOF' OBJECT CODE 32010

5.Define Literalpools and where it is located? * All literal operands used in a program are gathered together into one or more literal pools. * Literals are placed into a pool at theend of the object program,generated immediately following the END statement. 6.What is the disadvantage of keeping the literal operand far away from the instruction referencing? The disadvantage is that large amount of storage has to be reserved which leads to use extended format instruction. 7.What is LTORG Assembler Directive. It is desirable to place literals into a pool at some other location in the object program.An assenbler directive LTORG is used to tell the assemble to generate a literal pool here. When the assembler encounter a LTORG statements,it generates a literal pool containing all literals used since previous LTORG. 8. What is the advantage of LTORG assembler? To keep the literal operand close to the instruction that uses it. 9. Define duplicate literals. The same literal used more than once in the program. For duplicate literals,only one copy of the specified data value can be stored to save space.

Most assembler can recognize duplicate literals. 10. How to recognize the duplicate literals? * Compare the character strings defining them - Easier to implement,but has potential problem. -EXAMPLE, ='05' * Compare the generated data value. -Better ,but will increase the complexity of the assembler. - EXAMPLE, =C'EOF' and =X'454F46' The assembler will avoid storing the literals if the assembler recognize their equivalence. 11. What is literal table? A literal table LITTAB is created by the assembler to handle the literal operands which are used in the program. 12. What is the Datastructure LITTAB? The literal table LITTAB contains the following: *Literal name *Operand value and length *Address assigned to the operand when it is placed in a literal pool. 13.How the literal table is implemented during pass-1? Search for the literal encountered in the literal table. * If the literal already present , no action is taken. * If it is not present,the literal is added to the LITTAB ad for the address value if waits till it encounters LTORG for literal definition. *When it encounters a LTORG statement or the end of the program , the assembler make a scan and at this time each literal currently in the LITTAB is assigned an address. Addresses are assigned ,the location counter is updated to reflect the number of

bytes occupied by each literal. 14. How is LITTAB is implemented during pass-2? *Search LITTAB for each literal operand encountered. *Generate data value using BYTE or WORD statements. *Generate modification record for literals that represent an address in the program.

EXPRESSIONS 1. What are expressions? Expression is one of the machine independent features of an assembler. It can be formed using constants, data areas and labels. These expressions are evaluated by the assembler to produce a single operand address or value. Assembler permits these expressions to be placed in the operand field instead of a single operand. Eg: MAXLEN EQU BUFFEND-BUFFER 2. What are the terms that can be included in an expression? A symbols value can be classified as a. Relative term: i. Its value is relative to the beginning of the object program, and thus its value is dependent of program location. ii. E.g., labels , external references, data areas or reference to location counter (*) b. Absolute term: i. Its value is independent of program location ii. The value of the absolute term does not depend on the starting address of the program block iii. E.g., a constant. 3. What are the types of expressions? Define. Depending on the type of value expressions produce, they are classified as: a. Absolute expression: An absolute expression is one that produces an absolute value. Eg: MAXLEN EQU BUFFEND-BUFFER LENGTH EQU BUFFEND+MAXLEN-BUFFER b. Relative expression: A relative expression is one that produces a relative value. Eg. BUFFEND EQU *

RETADR

EQU

BUFFEND-BUFFER+CLOOP

4. What are the conditions for absolute and relative expressions? Absolute: An absolute expression contains only absolute terms, or An expression that contains relative terms but the relative terms occur in pairs and the terms in each pair have opposite signs. (/ and * operations are not allowed) Relative: A relative expression must have at least one unpaired relative term. All unpaired relative terms in the expression must have positive signs.(/ and * operations are not allowed) It is not necessary that the paired terms be adjacent to each other.

5. Give an example for absolute and relative expression. Justify them. Absolute expression: Eg: MAXLEN EQU BUFEND BUFFER Although BUFEND and BUFFER are relative terms (because their values will change when the program is loaded into a different place in memory), the expression (BUFEND BUFFER) is an absolute expression. The value of this expression is 0x1000, which is the same no matter where this program is loaded. Because BUFEND and BUFFER can be represented as (starting address + x) and (starting address + y), BUFEND BUFFER becomes (x y), which is a constant. Relative expression: Eg: LENGTH EQU BUFEND BUFFER+RETADR BUFEND, BUFFER and RETADR are relative terms. But BUFEND-BUFFER will produce an absolute value. , RETADR is a relative unpaired term with positive sign. Therefore the above expression will produce a relative term. 6. What is the necessity of an additional flag in a symbol table? In the case of an absolute expression, there is no requirement of modification record. On the other hand, relative expression needs modification record. So, it is necessary to inform the assembler the type of expression. To determine the type of an expression, we must keep track of the types of all symbols defined in the program, Therefore, we need a flag in the symbol table to indicate type of value (absolute or relative) in addition to the value itself.

Eg:

Program Relocation 1. what is program relocation ? The load address of an object program is unknown at assembly time if the system implements the multiprogramming feature. The assembler generates addresses relative to starting address in the object program. At load time, relocation is performed by adding the load address to the relative addresses. Operands of instructions that use direct addressing must be relocated, and the assembler provides the relocation information in the object program in the form of modification record. Operands of instructions that use relative addressing do not need to be relocated. Relocation can be processed by the loader or by the CPU using relocation registers. 2.why do we need program relocation ? ANS: 1. to increase productivity of machine. 2. Want to load and run several programs at same time (multiprogramming) 3. Must be able to load programs into memory wherever there is enough space. 4. Actual starting address of program is not known until load time. 3.what are the types of programs? Ans: 1. Absolute programs 2. Relocatable programs The program with starting address specified at assembly time is absolute program. An object program that contains the information necessary to perform address modification is called a relocatable program. 4.Define Modification Record ? A modification record is a record that is generated by the assembler as a part of the object code whenever program relocation occurs.

The format of Modification Record 1. Column1 M 2. COLUMN 2-7 : starting location of address field to be modified ,relative to beginning of the programs hexadecimal value 3. COLUMN 8-9:length of address field to be modified ,in half byes - hexadecimal value 5. how to relocate address for assembler? ANS:produce a modification record to store starting address and length of the address field to be modified. 6.how to relocate address for loader? ANS:for each modification record ,add actual beginning address of program to address field at load time . 7.what can be modified and not be modified in a modification record ? Address portions of those instructions that use absolute addresses can be modified. Register to register instructions cannot be modified . PC or Base relative addressing cannot be modified . ONE-PASS ASSEMBLERS 1) Define One pass assembler. One-pass assemblers go through the source code only once. Any symbol used before it is defined will require "errata" at the end of the object code (or, at least, no earlier than the point where the symbol is defined) telling the linker or the loader to "go back" and overwrite a placeholder which had been left where the as yet undefined symbol was used.

2) Define Load-and-Go Assembler. Load-and-go assembler generates their object code in memory for immediate execution. No object program is written out, no loader is needed. It is useful in a system oriented toward program development and testing such that the efficiency of the assembly process is an important consideration.

3) What are the main types of One pass assembler? One type produces object code directly in memory for immediate execution. The other type produces usual kind of object program for later execution.

4) How forward references is handled by one pass assembler? Omits the operand address if the symbol has not yet been defined. Enters this undefined symbol into SYMTAB and indicates that it is undefined. Adds the address of this operand address to a list of forward references associated with the SYMTAB entry. Scans the reference list and inserts the address when the definition for the symbol is encountered. Reports the error if there are still SYMTAB entries indicated undefined symbols at the end of the program. Search SYMTAB for the symbol named in the END statement and jumps to this location to begin execution if there is no error.

5) What are the problems faced during assembling of a program in one pass? Forward references to Data items. Forward references to Labels on instructions.

6) How forward references is eliminated on Data items? The forward references on data items are eliminated by defining all such data areas in the source program before they are referenced. 7) How the one pass assembler overcomes the forward references due to the presence of labels? Forward jump to instruction items cannot be easily eliminated. Therefore the assembler must make special provisions for handling forward references on labels. Insert (label, address to be modified) to SYMTAB. Usually, address to be modified is stored in a linked-list. When the definition for the symbol is encountered, scans the reference list and inserts the address. At the end of the program, reports the error if there are still SYMTAB entries indicated undefined symbols.

8) What is the difference between one pass and two pass assemblers is basically in the name? One-pass assemblers go through the source code only once. Any symbol used before it is defined will require "errata" at the end of the object code (or, at least, no earlier than the point where the symbol is defined) telling the linker or the loader to "go back" and overwrite a placeholder which had been left where the as yet undefined symbol was used. A two pass assembler does two passes over the source file. In the first pass it assigns addresses to all statements in the program and saves the addresses assigned

to all labels for use in Pass 2. The second pass, it assembles the instruction and generate the object code. 9) What is the advantage of one pass assembler? Advantages: One-pass assemblers are used when it is necessary or desirable to avoid a second pass over the source program. Onepass assemblers go through the source code only once. the external storage for the intermediate file between two passes is slow or is inconvenient to use. 10) What is the disadvantage of one pass assembler? Disadvantages: Main problem: Forward references to both data items and instructions One simple way to eliminate this problem: require that all areas be defined before they are referenced. a. It is possible, although inconvenient, to do so for data items. b. Forward jump to instruction items cannot be easily eliminated.

PROGRAM BLOCKS(2 marks) 1)What is a program block? Ans. Program blocks refer to segment of code that are rearranged within a single object program unit Sometimes it is required for certain instructions and data to appear in the object program in a different order from the corresponding source statements thus this accomplished using a program block.

2)Which table is generated at the end of pass1 by the assembler? What information does it provide? Ans. Block table is generated at the end of pass1 by the assembler. It provides the block name ,block number ,address ,length. Block name: provides the name of the block

Block number : each block is assigned a number by the assembler which is put in this table Address: the starting address of the particular block is specified here. Hence all the instructions placed in the block will be loaded with that address as the stating address(relative + starting address) Length : gives the length of program block

3)what are the problems solved by program blocks? Ans. 1.solves the problem of using extended format instructions 2.the problem of placement of literals is also solved

MASM ASSEMBLER: 1.What is 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. 2. How are the segments in MASM addressed? CODE segments are addressed using register CS. STACK segments are addressed using register SS. DATA segments are addressed using DS, ES, FS or GS. 3. How is the DATA segment addressed by default? How can it be changed? DATA segments, normally, are addressed using DS, ES, FS or GS. By default, the assembler assumes that all references to data segments use DS. This assumption can be changed by the assembler directive ASSUME. 4. What is similarity between BASE directive in SIC/XE and ASSUME in MASM assembler? The BASE directive in SIC/XE assembler tells the assembler the contents of register B; the programmer must provide executable instructions to load this value into the register.

The ASSUME in MASM assembler tells the assembler the contents of a segment register; the programmer must provide instructions to load this register when program is executed. 5. How is JUMP instruction assembled? Depending on the target of JUMP, it is assembled in two different ways. Near jump Far jump. 6. What is NEAR JUMP ? A NEAR JUMP is a jump to a target in the same code segment as the jump instruction . It is assembled using the current code segment register CS. The assembled machine instruction for a near jump occupies 2 or 3 bytes. By default, MASM assembler assumes a forward jump as NEAR JUMP. 7. What is FAR JUMP? A FAR JUMP is a jump to a target in different code segment as the jump instruction. It is assembled using segment register which is specified in an instruction prefix. The assembled instruction requires 5 bytes. 8. How does the programmer control timing-critical sections of code? MASM produce an instruction timing listing that shows the number of closk cycles required to execute each machine instruction. This allows programmer to exercise a great deal of control in optimizing timing critical section of code.

BOOTSTRAP LOADER 1. What is bootstrap loader? The bootstrap loader loads the first program to be run by the computer, usually it is an operating system. 2. Which loader loads the first program to be run by the computer.Give reason ? This Bootstrap loads the first program to be run by the computer-usually an operating system,from the boot disk (e.g., a hard disk or a floppy disk) ROM is installed by the manufacturer ROM contains bootstrapping program and some other routines that controls hardware (e.g. BIOS) 3. Define the term bootstrap. If the loading process requires more instructions that can be read in a single record, this first record causes the reading of others, and these in turn can cause the reading of still more records hence the term bootstrap. 4. Define the term bootstrap loader. Or Write short notes on Bootstrap loader. If the loading process requires more instructions that can be read in a single record, this first record causes the reading of others, and these in turn can cause the reading of still more records hence the term bootstrap. The first record or these records are generally referred to as a bootstrap loader. 5. Wtite the Algorithm for SIC/XE bootstrap loader ? Begin X=0*80(the address of the next memory location to be loaded) Loop A<-GETC(and convert it from the ASCII character code to the value of the Hexadecimal digit) Save the value in the high-order 4 bits of S A<-GETC Combine the value to form one byte A<-(A+S) Store the value (in A) to the address in register X X<-X+1 End 6. Write the SIC Example of bootstrap loader ? The bootstrap itself begins at address 0 It loads the OS from disk into memory starting address 0*80 No header record or control information,the object code is consecutive bytes of memory

7.

After load the OS,the control is transformed to the instruction at address 80 Why not just load the operating system directly ?

An operating system loader cannot be stored in a small space(usally a disk block). The operating system loader contains sophisticated code The first-level loader typically is only able to load a single-segment program from a file with a fixed name in the top-level directory of the boot disk. 8. Give the intermediate solution of bootstrap loader ? Have a built-in hardware function(or very short ROM program)that reads a fixed-length record from some device into memory at a fixed location The device can be selected via console switches Control is transferred to the record The record contains instructions that load the absolute program that follows If the loading requires more than single record, the first record causes the reading of others,and these in turn causes the reading of more records.

RELOCATION 1. What is relocating loader? Loaders that allow program relocation are called relocating or relative loader. The relocation loader is a loader which loads the object program at an address different from the location specified in the program. 2. Program relocation a machine dependent feature. Justify. One of the machine dependent feature of loader is relocation. Relocation depends on certain features of the machine namely addressing mode and instruction format. In case of SIC/XE, relocation can be achieved through modification records. On the other hand, SIC requires modification for almost all the instructions. Instead of generating modification records for all the instructions that require modification, the concept of relocation bits is used. Thus it varies from machine to machine. 3. What are the two methods for implementing program relocation during loading process? Relocation depends on the type of machine used. There are two methods for implementing program relocation during loading process. They are a. Modification record method - for SIC/XE machine b. Relocation bit method for SIC machine. 4. How the problem of relocation can be solved in the case of SIC/XE machine?

In SIC/XE machine apart from those instructions that are assembled using relative and Immediate addressing requires modification. This relocation problem can be resolved using modification record. Column 1 M Column 2-7 Starting location of the address field to be modify(relative to the beginning of the program). Column 8-9 Length of the address field to be modified in half bytes. 5. Machine X has fixed instruction format and direct addressing mode. How relocation can be achieved? Since machine X uses fixed instruction format and direct addressing mode almost all the instructions require modification. So, it is not possible to generate modification record for all the instructions. In such a case, relocation bit can be used. Text records are the same as in SIC/XE except that there is a relocation bit associated with each word of object code. The relocation bits are gathered together into a bit mask. If the relocation bit corresponding to a word of object code is set to 1, the programs starting address is to be added to this word when the program is relocated. If it is set to 0, no modification is required. 6. Which Addressing modes are never suffered by Relocation Problem? In SIC/XE instructions are assembled using various addressing modes. The instruction that do not refer to the memory directly ,does not requires relocation. E.g. Immediate, Relative. 7. Explain relocation bit with an example. In SIC there is a relocation bit associated with each word of object code. The relocation bits are gathered together into a bit mask. If the relocation bit corresponding to a word of object code is set to 1, the programs starting address is to be added to this word when the program is relocated. If it is set to 0, no modification is required. E.g. T^001057^0A^800^100036^4C0000^F1001000 800 > 1000 0000 0000. So only the word of the particular object code requires modification. DYNAMIC LINKING 1. Define dynamic linking. If the subroutine is loaded and linked to the program during its first call(run time),then it is called as dynamic loading or dynamic linking. 2. Write the advantages of dynamic linking.

a. It has the ability to load the routine only when they are needed b. The dynamic linking avoids the loading of entire library for each execution 3. Uses of dynamic linking Dynamic linking is often used to allow several executing programs to share one copy of a subroutine or library. For example, run-time support row times for a high-level language like in dynamic link-library 4. How dynamic linking is used in Object-oriented systems? In an Object-oriented system, dynamic linking is often used for references to software objects. This allows the implementation of the object and its methods to be determined at the time the program is run. The implementation can be changed at any time, without affecting the program that makes use of the object. 5. Advantages of Dynamic Linking over Static Linking i) Multiple processes that load the same DLL at the same base address share a single copy of the DLL in physical memory. Doing this saves system memory and reduces swapping. ii)When the functions in a DLL change, the applications that use them do not need to be recompiled or relinked as long as the function arguments, calling conventions, and return values do not change. In contrast, statically linked object code requires that the application be relinked when the functions change. iii) A DLL can provide after-market support. For example, a display driver DLL can be modified to support a display that was not available when the application was initially shipped. iv) Programs written in different programming languages can call the same DLL function as long as the programs follow the same calling convention that the function uses. The calling convention (such as C, Pascal, or standard call) controls the order in which the calling function must push the arguments onto the stack, whether the function or the calling function is responsible for cleaning up the stack, and whether any arguments are passed in registers. For more information, see the documentation included with your compiler. MS-DOS LINKER 1. What is Ms-DOS Linker? Basically in MS-DOS compilers and assemblers object modules are created instead of executable machine language programs. MS- DOS linker is a linkage editor that combines one or more object modules to produce a complete executable program. This executable module has the file name extension .exe. 2. Illustrate MS-DOS object module format?

Record Types THEADR EXTDEF PUBDEF LNAMES SEGDEF LEDATA FIXUPP MODEND

Description - Translator Header - External symbols and references - Public symbols and references - List of names record - Segment definition and grouping - Translated instructions and data - Relocation and linking information End of object module

3. Describe THEADR object module format. The THEADR record specifies the name of the object module. It is derived by the translator from the source file. This name is used by the linker to report errors. 8O H length T-module name Check-sum

4. Describe LNAMES object module format. The LNAMES record lists the names for use by SEGDEF record. 96 H length Name list Check-sum

5. Describe SEGDEF object module format. SEGDEF records describe the segments in the object module , including their name, length and alignment. It designates a segment name using an index into NAMELIST of LNAMES record. The attributes field indicates whether the segment is relocatable or absolute, alignment specification and other details. It also contains the origin specification for an absolute segment. 98 H length Attributes (1-4) Segment length Name (2) index (1) Check-sum

6. Describe EXTDEF object module format. The EXTDEF record contains a list of the external references used by the programs of this module.

8CH

length

External reference list

Check-sum

7. Describe PUBDEF object module format. 9O H The PUBDEF record contains a list of the external symbols (called public names) that are declared in a segment of the object module. Length Base (2-4) name Offset (2) Check sum

8. Describe LEDATA object module format. LEDATA records contains translated instructions and data from the source program.

9. Describe FIXUPP object module format. FIXUPP records are used to resolve external references, and to perform address modification that are associated with relocation. 9CH length locat (1) Fix dat Frame Target Target offset (1) (1) datum (1) datum (1) Check sum

Locat field: it contains a numeric code called loc code to indicate the type of a fixup. Frame datum field: it refers to a SEGDEF record and identifies the segment to which the fixup location belongs.

Target datum & target offset field: specifies the relocation or linking information. The target datum contains a segment/external index. The target offset contains an offset from the name indicated in target datum. Fix dat field: indicates the manner in which the target datum & target offset fields are to be interpreted.

10. Describe MODEND object module format. The MODEND specifies the end the object module. The Type Field indicates whether it is the main program. This record also optionally indicates the execution start address. 8A H length Type (1) Start addr (5) Check sum

11. Give a sample MS-DOS assembly language program. Sr. no. 0001 0002 COMPUTE 0003 0004 0007 ALPHA : 0012 : 0029 : 0036 COMPUTE 37 END Statement offset NAME FIRST SEGMENT EXTERN BETA:BYTE, GAMMA:WORD PUBLIC ALPHA 0015 .. .. : MOV AX, SEG BETA 0028 : JMP GAMMA 0056 : ENDS

12. Explain the process of MS-DOS Linker. MS-DOS LINK performs linking, like compiling or assembling, in fundamentally a two pass process. Pass 1 In the first pass, object modules are processed to collect information concerning segments and public definations. Pass 2 It performs relocation and linking. DATA STRUCTURES AND ALGORITHM 1. How many passes does a linking loader needs?

A linking loader usually makes two passes over its input, just as an assembler does. In terms of general function, the two passes of a linking loader are quitesimilar to the two passes of an assembler: Pass 1 assigns addresses to all external symbols. Pass 2 performs the actual loading, relocation, and linking.
2. What are the data structures needed for the linking loader?

The main data structure needed for our linking loader is an external symbol table ESTAB. Two other important variables are PROGADDR (program load address) and CSADDR (control section address). 3. What is ESTAB? Give an example. ESTAB which is analogous to SYMTAB in our assembler algorithm, is used to store the name and address of each external symbol in the set of control sections being loaded. A hashed organization is typically used for this table.

4. Explain CSADDR and PROGADDR? PROGADDR is the beginning address in memory where the linked programis to be loaded. Its value is supplied to the loader by the OS. CSADDR contains the starting address assigned to the control sectioncurrently being scanned by the loader. This value is added to all relativeaddresses within the control section to convert them to actual addresses. 5. What does a loader do in its PASS 1?

During Pass 1, the loader is concerned only with Header and Define record typesin the control sections. 1) The beginning load address for the linked program (PROGADDR) is obtained fromthe OS. This becomes the starting address (CSADDR) for the first control section in theinput sequence.

2) The control section name from Header record is entered into ESTAB, with value given by CSADDR. All external symbols appearing in the Define record for the control section are also entered into ESTAB. Their addresses are obtained by adding the valuespecified in the Define record to CSADDR. 3) When the End record is read, the control section length CSLTH (which was savedfrom the End record) is added to CSADDR. This calculation gives the starting address for the next control section in sequence. At the end of Pass 1, ESTAB contains all external symbols defined in the set of control sections together with the address assigned to each. Many loaders include as an option the ability to print a load map that shows thesesymbols and their addresses. UNIT IV MACRO WITHIN MACRO (NESTED MACROS) SAHIL JAIN 1. What do you mean by macro within macro or nested macros? Ans: A macro defined in definition of an another macro is known as macro within macro or nested macros. There may be two or more than two nested macros as reqired by the application. Example: MACROS MACRO (OUTER MACRO) RDBUFF MACRO &X,&Y (INNER MACRO) . . . MEND (END OF INNER MACRO) . . . MEND (END OF OUTER MACRO) 2. Why nested macros are not supported by two pass macro processor? How this problem is overcame?

Ans: A two pass macro processor cannot support since it requires all the macros to be defined before any macro invocation statement is encountered. The above problem is overcame by making use of one pass macro processor that can alternate between macro definition and macro invocation. Here the concept of LEVEL is used. LEVEL is a variable that is incremented by 1 every time MACRO keyword is identified and decremented by 1 for every MEND keyword. 3. What is a nested macro call? Ans: A macro invocation statement calls a particular macro which may contain call to another macro and so on. This is known as nested macro call. Example: MACROS MACRO &X,&Y,&Z (MACRO DEFINITION) . . . RDCHAR &Z (CALL TO OTHER MACRO) MEND RDCHAR DEFINITION) . . . MEND MACROS INVOCATION) 4. What is the major problem associated in implementing macro calls within macro? Ans: Recursion is the major problem associated with implementing macro calls within macro. To handle nested macro calls the macro processor must be able to handle macro definitions recursively i.e. to process one macro before it is finished with another, then to continue with the previous one. 5. How the nested macro calls are executed? What is the significance of nested macros? Ans: The execution of nested macro calls follow the LIFO(Last In First Out) rule i.e. the macro call encountered at last(innermost macro) is expanded first. A,B,C (MACRO MACRO &T (MACRO

The nested macros help the programmer to achieve recursive macro invocation without need of explicitly invocating each macro. It provides more readability, simplicity and efficiency.

Potrebbero piacerti anche