You are on page 1of 6


Title of Assignment: Write a TSR Program to implement Real Time Clock (RTC). Read the Real time from CMOS chip by suitable INT & display the RTC at the top right corner on the screen. Access the video RAM directly in your routine

Relevant Theory:

Difference between .EXE and .COM Files

No 1 2

.EXE program These programs can have multiple code, data and stack segments. .EXE programs can be as large as available memory. .EXE programs fit in the small, medium or large model. NEAR and FAR calls can be used. Due to the file header .EXE programs is larger than corresponding .COM program The entry point of .EXE program will never be fixed and varies according to the file header size. .EXE files contains unique header, a relocation map and other information used by DOS along with the execution code.

3 4 5 6 7

.COM program Max only one segment is present. Data ,code and stack reside in one segment. .COM program can have maximum size of 64KB. (Actual Size is 64KB - Size of PSP 2 Bytes for stack) .COM programs fit in the tiny model, in which all segment registers contain the same value. Only NEAR calls. File header is not present in .COM programs hence it always compact than .EXE. The entry point of .COM program is 0100H (the length of PSP) which is always fixed. The .COM files are compact and are loaded slightly faster then equivalent .EXE file since these contain only the execution code.

Method: .COM files are created

To convert .COM program it is necessary to create .EXE program

Step 1) To create .EXE, .ASM program is first assembled using macro assembler to produce .OBJ program. Step 2) The object program is linked with the help of linker to produce .EXE program.

Step 3) A Program named EXE2BIN converts .EXE programs to .COM. EXE2BIN specifies that convert exe to binary format (.COM). Since the operand of the command always references an .EXE file, it is not necessary to write .EXE extension. The second operand could be a name of .COM file. If we omit the extension EXE2BIN assumes BIN which we want to rename as .COM in order to execute the program.

For MASM Assembler : C:\masm61\bin\>MASM sample.asm C:\masm61\bin\>LINK sample.obj C:\masm61\bin\>EXE2BIN sample

For TASM Assembler C:\TASM> TASM sample.asm C:\TASM> TLINK sample.obj C:\TASM> EXE2BIN sample or C:\TASM> TLINK /T sample

The conditions for .COM Files. 1. 2. 3. It must be less than 64KB in length (tiny model) It cannot contain more then one segment It must have an origin at 0100H. (ORG 100H statement must be present)

EXEC Function The DOS EXEC function (INT 21H Function 4BH) allows to load .COM and .EXE programs from disk files, execute it and then regain control when the program is finished. It also allows a program (called the parent) to load any other program (called the child) from disk, execute it and then regain control when the child program is finished.

Step 1) Creates special data structure called a program segment prefix (PSP) in the

transient program memory (TPA). Step 2) EXEC function loads the program, just before the PSP and performs any relocation if required in case of .EXE only. Step 3) It then sets up the segment registers and stack and transfers the control to the program.

For .EXE programs the EXEC function may also do some additional processing like passing parameters from parent to child through the environmental block. This block holds certain information used by the system's command interpreter (usually COMMAND.COM) and may also hold information to be used by transient programs (.COM and .EXE).

PSP: The PSP contains various linkages and pointers needed by the application programs. It is a special data structure of 256 bytes. This structure is loaded by DOS before the transient program is loaded. It occupies the base of the memory block allocated to a transient program.

What is FCB: FCB block is a special data structure used to access a file and contains FCB functions which allow the programmer to create, open, close and delete files and to read or write records of any size at any record position within such files.

TSR: Programs which remain running and resident in memory while other programs are running are known as a "Terminate and Stay Resident" or "TSR" program. Example: Doskey, background printing or popping off a calculator on a screen etc. Thus TSR is an ordinary program which terminates not through the usual DOS terminate function, but through the DOS "keep" function - interrupt 27H. This function reserves an area of memory, used by the program so that no other programs will overwrite it. The terminate-and-stay-resident function (Function 31H) is one of the MS-DOS services invoked through Interrupt 21H.

Structure of a TSR:

TSR s consist of two distinct parts that execute at different times. The first part is the installation section, which executes only once, when MS-DOS loads the program. The installation code performs any initialization tasks required by the TSR and then exits through the terminate-and-stay-resident function.

The second part of the TSR, called the resident section, consists of code and data left in memory after termination. The TSR s resident code must be able to regain control of the processor and execute after the program has terminated.

Types of TSR: The simplest way to execute a TSR is to transfer control to it explicitly from another program. Because the TSR in this case does not solicit processor control, it is said to be passive. If the calling program can determine the TSR s memory address, it can grant control via a far jump or call. More commonly, a program activates a passive TSR through a software interrupt. The installation section of the TSR writes the address of its resident code to the proper position in the interrupt vector table. Any subsequent program can then execute the TSR by calling the interrupt.

The second method of executing a TSR involves signaling it through some hardware event, such as a predetermined sequence of keystrokes. This type of TSR is active because it must continually search for its startup signal. The advantage of active TSR lies in their accessibility. They can take control from any running application, execute, and return, all on demand. An active TSR, however, must not seize processor control blindly. It must contain additional code that determines the proper moment at which to execute. The extra code consists of one or more routines called interrupt handlers, .

CMOS RTC: CMOS is always present on Motherboard is of 64 bytes long. (MC146818) which stores date and time. There are total 64 registers are present. There are also two ports which are used 70H and 71H . 70H is write CMOS address port and 71H is data port which is used to read or set data. In order to read seconds our code will looks like this :


;02 transmitted to 70H to read seconds from 71H, 04 for min,06 for hrs.

IN AL, 71H

;returns seconds in AL registers.

Example: Screen Saver While implementing Screen saver, 08 and 09 Interrupts are used. INT 08H is timer interrupt and INT 09H is KB interrupt. INT 08H is generated after every 55 ms and thus in 1 second, 08H interrupt get generated for 18.2 times. INT 09H is generated after every press or release of a key.

When the machine is idle for specified time duration, screen saver pops up which could be a blank screen or some data or picture displayed on screen. When the key is pressed, original data get displayed on the screen by removing screen saver.

Design Analysis/ Implementation Logic:


1. ISR for INT 08H 1. Decrement the counter by 1 every time until it reaches zero. Also check the count value. For non zero value - go to the end and for zero value - proceed. 2. Save entire screen contents into buffer (4000 Bytes) 3. Send any specific character (Blank space) over the entire screen (4000 Bytes) 3. Set the flag for indication that screen saver is on.

2. ISR for INT 09H 1. Check the flag status whether the screen saver is on. If yes proceed else set the counter value to its original value and go to the end. 2. Entire buffer contents are transferred on to the screen

3. Reset the flag used for indication of screen saver. 4. Also set the counter value to its original value. Counter value is decided as (Idle time for screensaver / 55 ms ). For example, 5 second idle time, counter values is closer to 100.


The RTC gets displayed on the screen and gets continuously updated.


TSR for RTC is successfully implemented.