Monday, 21 April 2014

EDITORS

EDITORS
...................................................................................................................................................................


       STUDY OF EDITORS AND TYPES OF EDITORS

Editor is a system program that interfaces a program with the entity that generates a data (originator). It also interfaces the results of the program with the entity that consumes them (consumer).There are a few steps in program development:
1)      program design, coding and documentation
2)      preparation of programs in machine readable form
3)      program translation, linking and coding
4)      program testing an d debugging
5)      performance enhancement of the program
6)      reforming the data or the result of  the program


ü Design and Coding:
There are two methods for design and coding:


ü Program   Generator:       
   It generates a program which performs a set of functions described in its specifications. The user has to only specify the functions to be performed and not how to perform them.

ü Program   Environment:
  It supports programming by including awareness of the programming language syntax and semantics in the language editor
 Program entry and editing:
The soft tools used are text editors. Editor function in two modes
1. Command Mode
It accepts the user commands specifying the editing function to be performed.
2. Data Mode
The user keys in the text to be added to the files.

ü Testing and Debugging:
Various task to be performed here are selection of test data for the programs, analysis of test results to detect errors if any and debugging. Software tools used to implement these steps are:
1.Test data generators
They help the user to select test data for the program. Test data is a set of input values that satisfy the conditions required for correct flow of data.
2.Automated test drivers
Here the program correctness is verified by subjecting is to a standard set of tests after every modification. This is called regression testing.
3.Debug Monitors
             It is a  software   which provides debugging support for a program. It  executes the program been debugged under its control. It also enables the monitor to perform dynamically specified debugging actions. They perform the following facilities for dynamic debugging:
a)Setting break points in a program.
b)      Initiate a debug conversation when the control reaches the break point.
c)Display the value of variables.
d)     Assign new values to variables.
e)Testing user defined assertions involving program variables.



Enhancement of program performance:
Program efficiency depends on efficiency of the algorithm and efficiency of the coding. Editor comes in different forms:
1)      Line editor
2)      Stream editor
3)      Screen editor
4)      Word processors
5)      Structure editor
6)      Graphical editors



Ø LINE EDITOR
The scope of edit operations on line editor is limited to line of text.
The line is designated:
a) Positionally
b) By specifying a serial number in text
Contextually
a) By specifying a unique character string in it.
The primary advantage of line editors is there simplicity.



Ø STREAM EDITOR
A stream editor views the entire text as a stream of character this permits edit operations to cross line boundaries. Stream editors typically supports character oriented , line oriented and context oriented modes. The current pointer can be manipulated using all these modes.


Ø SCREEN EDITORS
Line or stream editors do not display the text in manner it would appear if printed. Screen editor uses the “What-you-see-is-what-you-get principle. The editor displays a screen full of text at a time the user can move the cursor over the screen, position it at a point where we want to perform. Some editing proceeds with the editing directly. Thus it is possible to see the effect of an edit operation on screen.


Ø WORD PROCESSOR
Word processors are document editors with additional features to produce well formatted hard copy output. Essential features of word processor are command for moving, merging of texts and searching and replacing of words. Many word processors supports spell check options with the adventure of personal computers. Word processors have seen wide spread use among authors, office personal and computer professional.


Ø STRUCTURE EDITOR
A structure editor incorporate an awareness of the structure of a document .This is useful in browsing through a document


CASE STUDY OF MS-WORD, DOS EDITOR , VI –EDITOR


Ø DOS EDITOR

Introduction

1.How to start the Dos editor.
2.How to create a file in the editor.
3.What is a batch file.
4.How to create a batch file.
5.How to execute a batch file.

What is DOS Editor?

The DOS Editor is used to display , create , print , and modify files.
The DOS Editor looks a little like a word process  

EDIT

How do you access the DOS Editor?

Type EDIT at the command prompt and press the ENTER key.
To name a file before starting type EDIT and the filename. Press the ENTER key.

Why do you want to use DOS Editor?

You use the DOS Editor to create Batch Files.

What are Batch Files?

A batch file contains a series of DOS commands.
Batch files have a  .bat extension.

What do you do with a batch file?

Batch file are like icons on a toolbar. They simplify  your life.
Imagine if you had a room full of computers. You wanted ti perform the same function on each of the computers. You have a few options.
 Sit at each computer and perform the function.    
 Build a batch file. Execute the batch file. Have time to relax before your next project.

How do you run or execute a batch file?
  
Type the batch file name.
  There is no need to type the .bat extension.

  How do you  stop or pause a batch file?

  Interrupt batch  file: CTRL+S
  Cancel  batch fil

What are some special batch file commands and what is the purpose of each?
ECHO OFF

This turns off all DOS commands after the ECHO OFF command.
If a DOS command has related questions you will  see the questions. The  only thing you do not see are the DOS commands.
@ ECHO OFF
This turn off all DOS commands including the ECHO OFF  command .

Now , do you understand the difference between ECHO OFF  and @ECHO OFF?

ECHO OFF  - You see ECHO OFF 
 @ECHO OFF  - You don’t see ECHO OFF 

ECHO.
  
This create a blank line.

ECHO

This display a message on a monitor.

PAUSE

This pause your computer until you press any key.




Ø VI EDITOR


INTRODUCTION

The VI editor is a screen based editor used by many Unix users . The VI editor has a powerful feature to aid programmer, but many beginning users avoid using VI because the different features overwhelm them. This tutorial is written to help beginning users get accustomed to using the VI editor , but also contains section relevant to regular users  of VI as well. Examples are provided , and the best way to learn is to try these examples as well………. There’s no better way than to experience things yourself.

  Starting the VI Editor

                  The VI editor lets a user create new files or edit existing files . The command to start the VI editor is vi, followed by the file name. For example to edit a file called temporary, you would type vi temporary and then return . You can start VI without a filename , but when you want to save your work , you will have to save your work , you will have to tell VI which filename to save it into later

The Two Modes of VI   

The first thing most users learn about the VI editor is that it has two modes : command and insert . The  command mode allows the entry of commands to manipulate text . these commands are usually one or  two characters long, and can be entered with few keystrokes. The insert mode puts anything typed on the  keyboard into the current  file. into insert mode . The most commonly used commands to get into insert mode are a and i . These  VI starts out in command mode. There are several  commands that put the VI editor  two commands are described below . Once you are in insert  mode , you get out of it by hitting the escape key . If your terminal does   not have an escape key , ^ [ should work(control-)]. You can hit escape two times in a row and VI  would definitely be in command mode . Hitting escape while you are already in  command mode doesn’t take the  editor out of command mode . It may beep to tell  you that you are already in that mode.

...............................................................................................................

..................................................................

Study OF VI Editor

 ..................................................................
.............................................................................................................................

Editor

               
                An editor allows the users to see a portion of a file on the screen and to modify characters and lines by simply typing at the cursor position.

Vi editor


¨       Vi stands for visual
¨       It is a full screen editor and allows the user to view and edit the entire document at the same time.
¨       Vi is case sensitive.
¨       It has powerful undo features.

Modes of Vi editor


             Vi editor works in 3 modes

Command mode

         In this mode all the keys pressed by the user are interpreted to be editor commands. No text is displayed on the screen even if corresponding keys is pressed on the keyboard.

Insert mode

        This mode permits to insert a new text, editing and replacement of existing text. When Vi editor is in insert mode the letters typed at the keyboard are echoed on the screen.

Escape mode

        Commands typed at the command line.

Starting with Vi editor

                                                                                                                                                                                                                                                                                                                         
                Syntax: vi filename


Moving the cursor

                The cursor movement commands are:

Command
Action
H or backspace
Left one character
l or spacebar
Right one character
K or -
Up one line
J or +
Down one line
I
Moves forward a word
#b
Moves back a word
#e
Moves to the last character in the word
F[character]
Moves right to the specified character in a line
T[character]
Moves right and places it one character before the specified character
0 or ^
Moves to the beginning of the file
#$
Moves to the end of the file
L
Moves to the last line of the file
G
Moves to the specified line number

Editing the file


¨       Open the file using $ vi filename
¨       To add text at the end of the file, position the cursor at the last character of the file.
¨       Switch from command mode to text input mode by pressing ‘a’.
¨       Here ‘a’ stands for append.
¨       Inserting text in the middle of the file is possible by pressing ‘i’. The editor accepts and inserts the typed character until Esc key is pressed.

Command
Purpose
I
Inserts text to the left of the cursor
I
Inserts text at the beginning of the line
A
Append text to the right of the cursor
A
Appends text at the end of the line
O
Appends a new line below
O
Appends a line above

Deleting Text

For deleting a character, move the cursor to the character , press ‘x’. The
character will disappear.
Command
Purpose
X
Deletes one character
Nx
Deletes n number of characters
#x
Deletes on character at the cursor position
#X
Deletes on the character before the cursor position
 D$ or d
    
Deletes a line from the cursor position to the end of the line
D0
Deletes from the cursor position to the starting of the line
#dd
Deletes the current line where the cursor is positioned
#dw
Deletes the word from the cursor position to the end of the word

 

The undo features

                u-undo the recent changes
                U- undo all changes in the current line

Saving text

                :w – save the file and remains in edit mode
                :wq – save the file and quits from edit mode
                :q – quit without changes from edit mode

Quitting vi

                Press zz or ‘:wq’ in command mode.

Monday, 7 April 2014

Assembler

Introduction to Assemblers and 
Assembly Language 


Encoding instructions as binary numbers is natural and efficient for computers. Humans, however, have a great deal of difficulty understanding and manipulating these numbers. People read and write symbols (words) much better than long sequences of digits. 

This topic describes the process by which a human-readable program is translated into a form that a computer can execute, provides a few hints about writing assembly programs and how to run them. 
What is an assembler ? 

A tool called an assembler translates assembly language into binary instructions. 
Assemblers provide a friendlier representation than a computer’s 0s and 1s that simplifies writing and reading programs. 

Symbolic names for operations and locations are one fact of this representation. Another fact is programming facilities that increase a program’s clarity. 

An assembler reads a single assembly language source file and produces an object file containing machine instructions and bookkeeping information that helps combine several object files into a program. 

Figure illustrates how a program is built. 



Most programs consist of several files—also called modules— that are written, compiled, and assembled independently. A program may also use pre written routines supplied in a program library . A module typically contains References to subroutines and data defined in other modules and in libraries. The code in a module cannot be executed when it contains unresolved References to labels in other object files or libraries. 

Another tool, called a linker, combines a collection of object and library files into an executable file , which a computer can run. 



1) Assembler :
                     a program to handle all the tedious mechanical translations 

2) Allows you to use: 

symbolic opcodes 
• symbolic operand values 
• symbolic addresses 

3) The Assembler 

keeps track of the numerical values of all symbols 
• translates symbolic values into numerical values 
 4) Time Periods of the Various Processes in Program Development



 5) The Assembler Provides: 

a. Access to all the machine’s resources by the assembled program. 
This includes access to the entire instruction set of the machine. 
b. A means for specifying run-time locations of program and data in 
memory. 
c. Provide symbolic labels for the representation of constants and 
addresses. 
d. Perform assemble-time arithmetic. 
e. Provide for the use of any synthetic instructions. 
f. Emit machine code in a form that can be loaded and executed. 
g. Report syntax errors and provide program listings 
h. Provide an interface to the module linkers and program loader. 
i. Expand programmer defined macro routines.






Syntax: 

Label OPCODE Op1, Op2, ... ; Comment field 
Pseudo-operations (sometimes called “pseudos,” or directives) are 
“opcodes” that are actually instructions to the assembler and that do 
not result in code being generated. 
Assembler maintains several data structures 

• Table that maps text of opcodes to op number and instruction format(s) 
• “Symbol table” that maps defined symbols to their value



Disadvantages of Assembly 

• programmer must manage movement of data items between memory locations and the ALU. 
• programmer must take a “microscopic” view of a task, breaking it down to manipulate individual memory locations. 
• assembly language is machine-specific. 
• statements are not English-like (Pseudo-code)

The 2-Pass Assembly Process 

• Pass 1: 
             1. Initialize location counter (assemble-time “PC”) to 0
             2. Pass over program text: enter all symbols into symbol table
                            a. May not be able to map all symbols on first pass
                            b. Definition before use is usually allowed
             3. Determine size of each instruction, map to a location
                            a. Uses pattern matching to relate opcode to pattern
                            b. Increment location counter by size
                            c. Change location counter in response to ORG pseudos

• Pass 2:
            1. Insert binary code for each opcode and value
            2. “Fix up” forward references and variable-sizes instructions

Examples include variable-sized branch offsets and
constant fields 

Pass 1 illustration by diagram ::




1. Input Source Program.
2. A Location Counter ( LC ), is used to keep track of each instruction's location.
3. A Table, the Machine Operation Table ( MOT ), that indicates the symbolic mnemonic for each instruction and its length ( two or six bytes ).
4. A Table, the Pseudo Code Table ( POT ), that indicates the symbolic mnemonic and action to be taken for each pseudo-op in pass 1.
5. A Table, the Symbol Table ( ST ), that is used to store each label and its corresponding value.
6. A Table, the Literal Table ( LT ), that is used to store each literal encountered and its corresponding assigned location.
7. A copy of the input to be used by pass 2. This may be stored in a secondary storage device , such as magnetic tape , disk , drum or the original source deck may be read by the assembler a second time for pass 2.


Pass 2 illustration by diagram :: 


  1. Copy the source program into pass 1.
  2. Location Counter (LC).
  3. A table, the Machine Operation Table (MOT) , that indicates (a) symbolic mnemonic (b) length (c) binary machine op-code (d) format.
  4. A table, Pseudo Operation Table (POT), that indicates for each pseudo-op the symbolic mnemonic and the action to be taken in pass 2.
  5. The Symbol Table , prepared by pass 1, containing each label and its corresponding value.
  6. A table, the Base Table ( BT ), that indicates which registers are currently specified as base registers by USING pseudo-ops and what are specified contents of these registers.
  7. A work-space, INST , that used to hold each instruction as its various parts (e.g. ,binary op-code, register field, length field, displacement field) are being assembled together.
  8. A work-space, PRINT LINE, used to produce a printed listing .
  9. A work-space, PUNCH CARD, used prior to actual outputting for converting the assembled instructions into the format needed by the loader.
  10. An output deck of assembled instructions in the format needed by the loader. 


Directives Assembler 
1. Directives are commands to the Assembler 
2. They tell the assembler what you want it to do, 
e.g. 
     a. Where in memory to store the code 
     b. Where in memory to store data 
     c. Where to store a constant and what its value is 
     d. The values of user-defined symbols 
Object File Format 

Assemblers produce object files. An object file on Unix contains six distinct sections (see Figure ): 

• The object file header describes the size and position of the other pieces of the file. 
• The text segment contains the machine language code for routines in the source file. These routines may be not executable because of unresolved references.
 • The data segment contains a binary representation of the data in the source file. The data also may be incomplete because of unresolved references to labels in other files. 
• The relocation information identifies instructions and data words that depend on absolute addresses. These references must change if portions of the program are moved in memory. 
• The symbol table associates addresses with external labels in the source file and lists unresolved references. 
• The debugging information contains a concise description of the way in which the program was compiled, so a debugger can find which instruction addresses correspond to lines in a source file and print the data structures in readable form.




The assembler produces an object file that contains a binary representation of the program and data and additional information to help link pieces of a program. This relocation information is necessary because the assembler does not know which memory locations a procedure or piece of data will occupy after it is linked with the rest of the program. Procedures and data from a file are stored in a contiguous piece of memory, but the assembler does not know where this memory will be located. The assembler also passes some symbol table entries to the linker. In particular, the assembler must record which external 
symbols are defined in a file and what unresolved references occur in a file. 




Assembler Data Structure and Variable

Two major data structures:
¨ Operation Code Table (OPTAB): is used to look up mnemonic 

operation codes and translate them to their machine language equivalents

¨ Symbol Table (SYMTAB): is used to store values (addresses) 

assigned to labels
Variable:
¨ Location Counter (LOCCTR) is used to help the assignment of

 addresses

¨ LOCCTR is initialized to the beginning address specified in 

the START statement

¨ The length of the assembled instruction or data area to be 

generated is added to LOCCTR


OPTAB and SYMTAB


OPTAB must contain the mnemonic operation code and

 its machine language

In more complex assembler, it also contain information 

about instruction format and length

For a machine that has instructions of different length, 

we must search OPTAB in the first pass to find the instruction 

length for incrementing LOCCTR

n  SYMTAB includes the name and value (address) for each 

label, together with flags to indicate error conditions

OPTAB and SYMTAB are usually organized as hash 

tables, with mnemonic operation code or label name as the

 key, for efficient retrieval