You are on page 1of 8

SYSTEM SOFTWARE Solution to TEST I B.

E 5th Semester

Q 1. Explain SIC Architecture Memory consists of 8 bit bytes,with 3 consecutive bytes forming a word byte addressable m/c total 32678 bytes in memory Registers there are 5 registers all with special uses each register is 24 bits in length accumulator,index register,link register,(for addressing),link register(to save return address),pc(program counter), SW(status word containing variety of info including condition codes) Data formats integers stored as 24 bit numbers,2s complement repsn for negative numbers ascii repsn of characters no floating point h/w Instruction formats only a single format

Index register mode bit

Opcode 8 bits

Address 15 bits

Addressing modes two addressing modes available direct mode x=0 ta=address indexed mode x=1 ta=address+(x) Instruction set load and store opns(lda,ldx sta,stx) arithmetic,logical opns(add,sub,mul,div) comp instruction to compare 2 values jlt,jeq,jgt conditional branch instns jsub,rsub for subroutine linkage i/p and o/p performed by transferring one byte at a time from rightmost parts of the register 3 instn each of which specifies the device td(test device),rd(read data),wd(write data) instructions for testing ,reading,writing data to devices

Q 2.Explain the instruction formats and addressing modes available in SIC/XE architecture Instruction formats : FORMAT 1 (1 BYTE): 8 OPCODE EXAMPLE: RSUB (RETURN TO SUBROUTINE) OPCODE 01 00 11 00 4
FORMAT 2 (2 BYTES):

(OBJ-CODE)

8 OPCODE

4 REG1

4 REG2

EXAMPLE: COMPR A, S (COMPARE TH CONTENTS OF REGISTERS A AND S) OPCODE 1010 0000 A 0 (8 BIT)
FORMAT 3 (3 BYTES):

A 0000 0 (4 BIT)

S 01 0 0 0 (4 BIT) (OBJ-CODE)

6 1 1 1 1 1 1 12 OPCODE N I X B P E DISPLACEMENT EXAMPLE: LDA #3 (LOAD 3 TO ACCUMULATOR A) 6 1 1 1 1 1 1 0000 0 0 1 0 0 0 0 0 OPCODE N I X B P E 0 1 0 0


FORMAT 4 (4 BYTES):

12 0000 0000 0

00 11

3 (OBJ-CODE)

1 1 OPCODE

1 N

1 I

1 X

20 B P E ADDRESS

EXAMPLE: +JSUB RDREC ( JUMP TO THE ADDRESS, 1036) 6 1 1 0100 10 1 1 1 1 1 1 0 0 0 1 20 0000 0001 0000 0001 0110

OPCODE 4

N I X B P E B 1 0 1 0 1 6 (OBJ-CODE)

ADDRESSING MODES: 1) DIRECT 2) INDEXED 3) BASE RELATIVE 4) PROGRAM COUNTER RELATIVE DIRECT EXAMPLE: LDA TEN 0000 0000 X 0 1 0 01 0 0000 0000 0 0000

0 0 OPCODE INDEXED STCH BUFFER, X 0101 5 OPCODE EA=1000+[X] BASE RELATIVE: MODE BASE RELATIVE INDICATION B=1 P=0 0100 4

0 TEN

1 X1

0 01

0000 0 0 BUFFER

0000 0

0000

TARGET ADDRESS CALCULATION TA = (B) + DISP (0 <= DISP <= 4095)

FOR BASE RELATIVE ADDRESSING MODE THE DISPLACEMENT FIELD DISP IN A FORMAT 3 INSTRUCTION IS INTERPRDTED AS A 12 BIT UNSIGNED INTEGER. 6 0001 0 OPCODE 1 1 0 1 1 1 1 1 0 1 1 1 0 P E 4 0 12 0000 0000 00 00

N 1 X B 3

0 OBJ-CODE

EA=LENGTH=0033=DISP+ [B] 0<=DISP<=4095 [B]=0033 DISP=0 THE CONTENT OF THE ADDRESS 0033 IS LOADED TO THE INDEX REGISTER X. PROGRAM COUNTER RELATIVE EA=(PC)+DISP -2048<=DISP<=2047

EXAMPLE: 1) LDA LENGTH

6 OPCODE N I X B P E 0 0000 0

1 0

1 1 1 1

1 1 0 0 0 0

12 0000 0011 00 11

ACCUMULATOR A CONTAINS THE CONTENT OF LENGTH 0033 2) STCH BUFFER,X 6 OPCODE N I X B P E 5 0101 1 7 1 0 1 1 1 1 1 1 1 1 1 0 0 12 0000 0000 00 11

BUFFER = 0036 [B] = 0033 DISP = 3 ACCUMULATOR A CONTAINS THE CONTENT OF BUFFER 0036 3) LDA #9 6 OPCODE N I X B P E 0 0000 0 0 1 1 0 1 1 1 0 1 1 0 0 0 12 0000 0000 10 01

ACCUMULATOR A CONTAINS 9. 4) 002A J @ RETADR 6 0011 1 1 1 1 1 1 1 0 1 1 0 0 1 0 12 0000 0000 00 11

Q 3. Write a sequence of instructions for SIC to set ALPHA equal to product of BETA and GAMMA . Assume ALPHA, BETA and GAMMA to be memory locations of one word each. Ans:LDA MUL STA RESW RESW BETA GAMMA ALPHA 1 1 load ALPHA into register A multiply the value of GAMMA to register A store register A contents to ALPHA one word variable one word variable

BETA GAMMA

ALPHA

RESW

one word variable

Q 4.Write a sequence of instructions in SIC to clear a 20-byte string to all blanks LDX LDA STCH TIX JLT WORD WORD BYTE RESB ZERO CHR STR1,X TWENTY MOVEC 0 20 C 20 INITIALIZE INDEX REGISTER TO ZERO STORE BLANK IN REGISTER A STORE CHARACTER INTO STR1 ADD 1 TO INDEX AND COMPARE WITH 20 LOOP IF LESS THAN 20 CONSTANT 0 CONSTANT 20 CONSTANT CHAR BLANK 20 BYTE STRING VARIABLE

MOVEC ZERO TWENTY CHR STR1

Q 5. a. Explain the steps involved in translating source program to object program. b. List & explain the assembler directives. Answer: The steps involved in translating a source program to object program are as follows: 1. Convert mnemonic operation codes to their machine language equivalents. 2. Convert symbolic operands to their equivalent machine addresses 3. Build the machine instructions in the proper format. 4. Convert the data constants specified in the source program into their internal machine representations. Eg., translate EOF to 454F46 5. Write the object program and the assembly listing. All of these steps except number 2 can be accomplished by sequential processing of the source program, one line at a time. The translation of addresses pose a problem if there is a forward reference, i.e, a reference to a label defined later in the program. If the program is translated line by line, it is not possible to process this statement because the address that will be assigned to the label will not be known. Because of this, most assemblers make two passes over the source program. The first pass scans the source program for label definitions and assigns addresses. The second pass performs most of the actual translation. The assembler also processes assembler directives. Finally, the assembler writes the generated object code into some output device. This object program will later be loaded into memory for execution. The simple object program format used consists of 3 types of records: Header, Text, and End. The Header record contains the program name, start address and length. Text records contain the translated instructions and data of the program with the addresses where these are to be loaded. The End record marks the end of the object program and specifies the addresses in the program where execution is to begin. b. Assembler Directives : START - Specify name and starting addresses for the program. END - Indicate the end of the source program and (optionally) specify the

First executable instruction in the program. - Generate character or hexadecimal constant, occupying as many Bytes as needed to represent the constant. WORD - Generate one-word integer constant. RESB - Reserve the indicated number of bytes for data area. RESW - Reserve the indicated number of words for a data area. BYTE

Q 6. Describe the data structures used in two-pass assembler design. The data structures used in a two-pass assembler design are: 1. Location Counter (LOCCTR) 2. 3. 4. The Operation Code Table (OPTAB) The Symbol Table (SYMTAB) The Literal Table (LITTAB)

1.LOCCTR: It is a variable that is used to help in the assignment of addresses. LOCCTR is initialized to the beginning of the address specified in the START statement. After each source statement is processed, the length of the assembled instruction or data to be generated is added to LOCCTR. 2.OPTAB: It must contain the mnemonic operation code and its machine language equivalent. In complex assemblers , it also contains information about instruction format and length . During Pass1, OPTAB is used to look up and validate operation codes in the source program. In Pass 2, it is used to translate the operation codes to machine language. It is organized as a HASH TABLE, with mnemonic operation code as the key. Hash table is appropriate since it provides fast retrieval with a minimum searching. 3.SYMTAB: The symbol table includes the name and value (address) for each label in the source program, the flags to indicate error conditions, such as a symbol defined in two different places. It can as well contain information about the data area or instruction labeled- eg: its type and length. During Pass 1, labels are entered into SYMTAB as they are encountered in the source program, along with their assigned addresses from the location counter. In Pass 2, symbols used as operands are looked up in the SYMTAB to obtain the addresses to be inserted in the assembled instructions. The symbol table is organized as a hash table for efficiency of insertion and retrieval. Entries are rarely deleted from the SYMTAB. So efficiency of deletion is not an important consideration. 4.LITTAB: A literal table contains the details of literals used, such as the literal name, the operand value and length, and the address assigned to the operand when it is placed in a literal pool. The LITTAB is organized as a hash table, using the literal name or value as the key.

Q 7. What is program relocation? How is this handled by the assembler?

In a time sharing system it is often desirable to have more than one programs sharing the same memory and other resources of the machine. If we knew exactly which program were to be executed concurrently in a particular way in advance it would be easy to assign addresses when the programs were assembled so that they would fit together without overlap or wasted space. But as this is not possible most of the times the actual starting address of the program is not known most of the times. In some cases the program might also get relocated. In such situations the addresses allocated using absolute mode will change as well as the addresses of labels. EG: Absolute program, starting address 1000 e.g. 55 101B LDA THREE 00102D Relocate the program to 2000 e.g. 55 101B LDA THREE 00202D Hence each Absolute address (including labels) should be modified This problem of reallocation can be solved in the following way: 1. When the assembler generates the object code for the absolute addresses it will first enter the address relative to the start of the program. 2. The assembler will also produce a command for the loader instructing it to add the beginning address of the program to the address field in the required instructions at load time. This command for the loader is a part of the Object program and is present in the form of a modification record. Modification record *Col 1 M *Col 2-7 Starting location of the address field to be modified, relative to the beginning of the program

*Col 8-9 length of the address field to be modified, in halfbytes The length is stored in half bytes because the address field to be modified may not occupy an integral number of bytes. If the field comprises odd number of half bytes it is assumed to begin in the middle of the

LOCATION
0000 COPY 0000 FIRST 0003 LDB BASE 0006 CLOOP 000A LDA 000D COMP 0010 JEQ 0013 +JSUB 0017 J 001A ENDFIL LTORG 0020 STA 0023 LDA 0026 STA 0029 RETADR 002C LENGTH 002F BUFFER END first byte at the starting location.

SOURCE STATEMENT
START STL #LENGTH LENGTH +JSUB LENGTH #0 ENDFIL WRREC CLOOP LDA BUFFER,X #3 LENGTH RESW RESW RESB FIRST 0000 RETADR

OBJECT CODE
172026 692026 4B5100A 03201F 290000 332007 4B51031 3F2FEC 032003 0FC003 030003 0F2003 -

RDREC

=CEOF

1 1 4096

Q.8 Assemble the following instructions using SIC/XE architecture

You might also like