12
USN PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Computer Science And Engineering INTERNAL ASSESSMENT TEST – 1 Date : 17/08/2016 Max Marks : 50 Subject & Code : System Software & 10CS52 Section : A, B and C Name of faculty : Dr. Sarasvathi V & Ms. Shanthala P T Time : 11:30-1:00 PM Solution Manual 1 . a What are system software and application software? Bring out the 4 differences between these two. System Software consists of a variety of programs that support the operation of a computer. Application software is primarily concerned with the solution of some problem, using the computer as a tool Differences : System software Application software Is a program which provides service to the system Is a program which provides services to the user The focus is on the computing system rather than any particular application Focus is on given problem rather than computing system Depends on the architecture of the machine on which they are used (M/c dependent) Machine independent While developing the system software the following factors are considered: - Number & types of registers - M/c instructions While developing application software we will consider: - programming language - operating system - complier - other supporting s/w 4 B.E/V Sem 1 P E

Date: 14-08-2012 - PESIT South Campuspesitsouth.pes.edu/pdf/SS.doc · Web viewWrite a sequence of instructions in SIC to clear a 20-byte string to all blanks LDX ZERO LOOP LDCH BLANK

  • Upload
    vokhanh

  • View
    215

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Date: 14-08-2012 - PESIT South Campuspesitsouth.pes.edu/pdf/SS.doc · Web viewWrite a sequence of instructions in SIC to clear a 20-byte string to all blanks LDX ZERO LOOP LDCH BLANK

USN

PESIT Bangalore South CampusHosur road, 1km before Electronic City, Bengaluru -100

Department of Computer Science And Engineering

INTERNAL ASSESSMENT TEST – 1Date : 17/08/2016 Max Marks : 50Subject & Code : System Software & 10CS52 Section : A, B and CName of faculty : Dr. Sarasvathi V & Ms. Shanthala P T Time : 11:30-1:00 PM

Solution Manual1. a What are system software and application software? Bring out the 4 differences between these two.

System Software consists of a variety of programs that support the operation of a computer.Application software is primarily concerned with the solution of some problem, using the computer as a toolDifferences :

System software Application software

Is a program which provides service to the system

Is a program which provides services to the user

The focus is on the computing system rather than any particular application

Focus is on given problem rather than computing system

Depends on the architecture of the machine on which they are used (M/c dependent)

Machine independent

While developing the system software the following factors are considered: - Number & types of registers - M/c instructions - instructions formats - addressing modes

While developing application software we will consider: - programming language - operating system - complier - other supporting s/w

4

b Give the target address generated for the following machine instructions.1) 032600 2) 03c300 3). 0310c303 4). 022030 5). 010030 6). 003600If (B)=006000H , (PC)=003000 , (x)=000090

6

B.E/V Sem

1 P E

Page 2: Date: 14-08-2012 - PESIT South Campuspesitsouth.pes.edu/pdf/SS.doc · Web viewWrite a sequence of instructions in SIC to clear a 20-byte string to all blanks LDX ZERO LOOP LDCH BLANK

USN

PESIT Bangalore South CampusHosur road, 1km before Electronic City, Bengaluru -100

Department of Computer Science And Engineering

2. a Explain the instruction formats and addressing modes available in SIC/XE architecture INSTRUCTION FORMATS The maximum memory available on a SIC/XE system is 1 megabyte (2 power 20 bytes).This increase leads to a change in instruction formats and addressing modes. The larger memory available on SIC/XE means that an address will no longer fit into 15-bit field; thus instruction format used on the standard version of SIC is no longer suitable. There are two possible options-either use some form of relative addressing or extend the address field to 20 bits. Both of these options are included in SIC/XE. SIC/XE provides some instructions that do not reference memory at all.

Format 1 and 2 in the following description are used for such instruction. Bit e is used to distinguish between format 3 and 4(e=0 means format 3, e=1 means format 4).

Format 1(1 byte) 8

Ex: FIX

Opcode

6

B.E/V Sem

1 P E

Op

Page 3: Date: 14-08-2012 - PESIT South Campuspesitsouth.pes.edu/pdf/SS.doc · Web viewWrite a sequence of instructions in SIC to clear a 20-byte string to all blanks LDX ZERO LOOP LDCH BLANK

USN

PESIT Bangalore South CampusHosur road, 1km before Electronic City, Bengaluru -100

Department of Computer Science And Engineering

0100 1100

Format 2(2 bytes)

8 4 4 Op R1 R2

Example: COMP A,S(Compare the contents of registers A and S) Opcode A S

1010 0000 0000 0100 8-bit 4-bit 4-bit A 0 0 4 object code

Format 3(3 bytes) 6 1 1 1 1 1 1 12

Op N i x b P e Disp

Example: LDA #3(load 3 to accumulator A) 6 1 1 1 1 1 1 12

0000 00 0 1 0 0 0 0 0000 0000 0011 0 1 0 0 0 3 object code

Format 4(4 bytes)

6 1 1 1 1 1 1 20 Op n i x b P e Address

Example: +JSUB RDREC(Jump to the address,1036)

6 1 1 1 1 1 1 20 0100 10 1 1 0 0 0 1 0000 0001 0000 0011 0110

Opcode n i x b p e4 B 1 0 1 0 3 6 object codeADDRESSING MODES Two new addressing modes are available excluding direct and indexed addressing modes used in SIC. These are described in the following table:

B.E/V Sem

1 P E

Page 4: Date: 14-08-2012 - PESIT South Campuspesitsouth.pes.edu/pdf/SS.doc · Web viewWrite a sequence of instructions in SIC to clear a 20-byte string to all blanks LDX ZERO LOOP LDCH BLANK

USN

PESIT Bangalore South CampusHosur road, 1km before Electronic City, Bengaluru -100

Department of Computer Science And Engineering

MODE INDICATION TARGET ADDRESS

Base relative b=1,p=0

TA=(B)+disp(0<=disp<=4095)

Program counter relative b=0,p=1 TA=(PC)+disp(-2048<=disp<=2047)

base relative addressing For base relative addressing, the displacement field disp in a format 3 instruction is interpreted as 12-bit unsigned integer. program counter relative addressingFor program counter relative addressing, this field is interpreted as a 12-bit signed integer. With negative values represented in 2’s complement notation.direct addressing If bits b and p are both set to 0, the disp field from the format 3 instruction is taken to be the target address. For a format 4 instruction, bits b and p are normally set to 0, and the target address is taken from the address field of the instruction. This is direct addressing. Any of these addressing modes can be combined with indexed addressing if bit x is set to 1, the term(X) is added in the target address calculation. immediate addressing.Bits i and n in format 3 and 4 are used to specify how the target address is used. If bit i=1 and n=0, the target address itself is used as the operand value; no memory reference is performed. This is called immediate addressing. indirect addressing : If bit i=0 and n=1, the word at the location given by the target address is fetched; the value contained in this word is then taken as the address of the operand value. This is called indirect addressing. simple addressing :If bits n and i are both 0 or both 1, the target address is taken as the location of the operand; we will refer to this as simple addressing. Indexing cannot be used with immediate or indirect addressing modes. SIC/XE instructions that specify neither immediate nor indirect addressing are assembled with bits n and I both set to 1.Assemblers for the standard version of SIC set the bits to 0.If bits n and i are both 0, then bits b,p,e are considered to be the part of the addressing field of the instruction. This makes instruction format 3 identical to the format used on the standard version of SIC, providing the desired compatibility.

b Write a sequence of instructions in SIC to clear a 20-byte string to all blanks LDX ZEROLOOP LDCH BLANK STCH STR1,X

4

B.E/V Sem

1 P E

Page 5: Date: 14-08-2012 - PESIT South Campuspesitsouth.pes.edu/pdf/SS.doc · Web viewWrite a sequence of instructions in SIC to clear a 20-byte string to all blanks LDX ZERO LOOP LDCH BLANK

USN

PESIT Bangalore South CampusHosur road, 1km before Electronic City, Bengaluru -100

Department of Computer Science And Engineering

TIX TWENTY JLT LOOP : : STR1 RESW 20 BLANK BYTE C ‘ ‘ ZERO WORD 0TWENTY WORD 20

3. a.

Explain the concept of Regular Expression. Explain the 10 meta character that form the regular expression with example. A Regular Expression is a pattern description using a "meta" language, a language that you use todescribe particular patterns of interest. The characters used in this meta language are part of thestandard ASCII character set used in MS-DOS and UNIX.The characters of regular language are:. : Matches any single character except the newline character(\n)* : Matches zero or more copies of the preceding expression[ ]: A character class which matches any character within the brackets. If the first character is acircumflex (^) it changes the meaning to match any character except the ones within the brackets. A "-" inside the square brackets indicates a character range.^ : Matches the beginning of a line as a first character of a regular expression. Also used for negation within square brackets$: Matches the end of a line as the last character of a regular expression{ }: Indicates how many times the previous pattern is allowed to match when containing one or two numbersFor example A {1, 3} matches one to three occurrences of character A.\ : Used to escape metacharacters, and as part of the usual C escape sequencesExample "\n" is a new line character while "\*" is a literal asterisk+: Matches one or more occurrence of the preceding regular expression? : Matches zero or one occurrence of the preceding regular expressionFor example -? [0-9]+ matches a signed number including an optional leading minus|: Matches either the preceding regular expressions or the following regular expressionFor example cow|pipe|pig matches any of the three words"...” Interprets everything within the quotation marks literally-metacharacters other than C escape sequences lose their meaning/: Matches the preceding regular expression but only if followed by the following regular expressionFor example 0/1 matches "0" in the string "01" but would not match anything in the strings "0" or "02". The material matched by the pattern following the slash is not "consumed" and remains to be turned into subsequent tokens. Only one slash is permitted per pattern.(): Groups the series of regular expressions together into a new regular expression.For example (01) represents the character sequence 01.parantheses are useful when building up complex patterns with *, +,| Note that some of these operators operate on single characters

6

B.E/V Sem

1 P E

Page 6: Date: 14-08-2012 - PESIT South Campuspesitsouth.pes.edu/pdf/SS.doc · Web viewWrite a sequence of instructions in SIC to clear a 20-byte string to all blanks LDX ZERO LOOP LDCH BLANK

USN

PESIT Bangalore South CampusHosur road, 1km before Electronic City, Bengaluru -100

Department of Computer Science And Engineering

(example [ ]) while others operate on regular expressions.

B Write a LEX program to count number of comment lines from a C file. %{int cc=0;%}%x comment%%“//”.* cc++;“/*” {BEGIN comment; cc++;}<comment>.* ;<comment>\n ;<comment>”*/” cc++; BEGIN 0;}%%

main(int argc, char *argv[]){ If (argc!=3){ printf(“no file:”); exit(0);}yyin = fopen(argv[1],“r”);yyout = fopen(argv[2],“w”);yylex();printf(“The number of comment lines are = %d”,cc);}

4

4. a Define the following terms:yytext , yyleng, yylex(), yyparse() and start states.yylex( ) -The scanner created by Lex has the entry point yylex(). So we call yylex() to start scanning. All code in the rule section is copied into yylex().yytext - where text matched most recently is storedyyleng -number of characters in text most recently matched.Yyparser(): The routine yyparse() is a parser generated by yacc. When the user inputs a specification to yacc, the output is a file of C programs called y.tab.c. The function produced by yacc is called yyparse(). when yyparse() is called it goes to grammar part, when it needs any tokens for parsing, it calls yylex() to get the tokens. If it detects any error it goes to error part yyerror(). yyerror() is a subroutine and prints a message when a syntax error is detectedStart states: each start condition must be introduced to Lex in the definitions section with a line reading

4+2

B.E/V Sem

1 P E

Page 7: Date: 14-08-2012 - PESIT South Campuspesitsouth.pes.edu/pdf/SS.doc · Web viewWrite a sequence of instructions in SIC to clear a 20-byte string to all blanks LDX ZERO LOOP LDCH BLANK

USN

PESIT Bangalore South CampusHosur road, 1km before Electronic City, Bengaluru -100

Department of Computer Science And Engineering

%Start name1 name2 ... where the conditions may be named in any order. The word Start may be abbreviated to s or S or x. The conditions may be referenced at the head of a rule with the <> brackets: <name1> expression is a rule which is only recognized when Lex is in the start condition name1. To enter a start condition, execute the action statement BEGIN name1; which changes the start condition to name1.

b Write a regular expression for the following: C variable, decimal numberVariable: [a-z_][_a-z0-9]*

Decimal number:[+-]?[0-9]+(\.[0-9]+)?([eE][+-]?[0-9]+)?

1+3

5. a With an example explain the structure of YACC.

Ex:Program to test for a validity of simple expression involving +,-,* and /%{

07

B.E/V Sem

1 P E

Page 8: Date: 14-08-2012 - PESIT South Campuspesitsouth.pes.edu/pdf/SS.doc · Web viewWrite a sequence of instructions in SIC to clear a 20-byte string to all blanks LDX ZERO LOOP LDCH BLANK

USN

PESIT Bangalore South CampusHosur road, 1km before Electronic City, Bengaluru -100

Department of Computer Science And Engineering

#include<stdio.h> #include<ctype.h>%}%token NUMBER LETTER%left ‘+’ ‘-’ lower precedency %left ‘*’ ‘/’ higher precedency %%e : e ‘+’ e | e ‘-’ e | e ‘*’ e | e ‘/’ e | ‘(‘ e ‘)’ |NUM | ID ;%%main( ){ printf(“ enter the expression:\n”); yyparse(); printf(“valid expression:\n”);}}yyerror(){ printf( “invalid expression:\n”,);}LEX part:%{#include “y.tab.h”%}%%[0-9]+(\.[0-9]+) ? {return NUM;}[a-zA-Z][_a-zA-Z0-9]* return ID;[ \t] ;\n return 0; //logical EOF. return yytext[0];%%

B.E/V Sem

1 P E

Page 9: Date: 14-08-2012 - PESIT South Campuspesitsouth.pes.edu/pdf/SS.doc · Web viewWrite a sequence of instructions in SIC to clear a 20-byte string to all blanks LDX ZERO LOOP LDCH BLANK

USN

PESIT Bangalore South CampusHosur road, 1km before Electronic City, Bengaluru -100

Department of Computer Science And Engineering

b Explain grammar with an example.A grammar specifies a set of production rules, which define a language. A production rule specifies a sequence of symbols, sentences, which are legal in the language.Each rule starts with a nonterminal symbol and a colon followed by terminals or nonterminals.Ex: E:E’+’EBlanks, tabs, and new lines are ignored except that they may not appear in names or multi-character reserved word.literal consists of a character enclosed in single quotes. Each rule is terminated by a ;%%production : symbol1 symbol2 … { action } | symbol3 symbol4 … { action } | … ;production1: symbol1 symbol2 { action } ;%%

Consider the example grammarA : B C D;A : E F;A : G;Can be written asA : B C D | E F | G ;

03

* * * * * * * *

B.E/V Sem

1 P E