home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
magazine
/
c_news
/
02
/
cnews002.nws
Wrap
Text File
|
1988-06-22
|
18KB
|
410 lines
Volume 1, Number 2 10 January 1988
+---------------------------------------------------------------+
| |
| |
| |
| - C News - |
| |
| |
| International |
| C Programming & Compiler Review |
| Newsletter |
| |
| |
| |
+---------------------------------------------------------------+
US Office:
Editor Barry Lynch
Reston, VA
Foreign Office:
Editor David Nugent
Melbourne, Australia
C News is published once a month by the C BBS as its official
newsletter. You are encouraged to submit articles for publication
in C News. Articles should be related to C programming and can be
Tutorials, reviews or articles of interest to the C programming
community. All Operating systems are fairly represented and this
newsletter shows no favoritism to any one in particular.
C News is the property of the C BBS and is Copyright 1988 by the
the C BBS. All rights are reserved and distribution is limited to
electronic distribution and personal printed copies. C News cannot
be resold at any profit, by any organization. All material enclosed
within the newsletter is the opinions of the writers and not the
C BBS or it's Sysop.
Table of Contents
1. EDITORIAL
The Heap: messages from the editor.................... 1
2. BOOK REVIEWS
C: The Complete Reference
reviewed by Tom Leonard .............................. 2
TurboC Programmer's Reference Book
reviewed by Tom Leonard .............................. 2
Crafting C Tools for the IBM PC.
reviewed by Mike Shaw ................................ 3
3. ARTICLES
TurboC & TSR's: A few Questions
by Arnie Cherdak ......... ........................... 4
C News 1-02 Page 1 10 Jan 1988
=================================================================
EDITORIAL
=================================================================
The HEAP: Messages from the Editor.
Well with only one issue under my belt, the C News -letter is
already expanding. David Nugent has voluntered to be a contributing
editor for future issues of C News. Since David is located in
Melbourne, Australia I figured that he could head the foreign office
there for us. Gee, the C BBS is now international in scope.
Besides, David other C BBS users are pitching in to contribute
reviews, tutorials and other information to this newsletter. Three
users as of this issue have contributed, with others planning to in
future issues. Keep in mind that this Newletters letter is for all
C programmers, and I hope that you will send in questions, articles,
book reviews and sample programs that you might like to show off.
Each article has the author's name included in the byline. Any
comments on any of the articles should be sent to the those individuals,
direct if you would like, or to the C BBS.
I started an article on the "Legal Aspects of Software Design",
but decided to get some legal counsel before I put anything on paper.
Never fear that article will be finished by the next issue. Speaking
of which the next issue is scheduled for publication two weeks from
today - 17 January. If you would like to submit an article to C News,
it must be here by the 14th to be included. Thanks
B C'ing U..
Barry
C News 1-02 Page 2 10 Jan 1988
======================================================================
BOOK REVIEWS
======================================================================
______________________________________________________________________
Title: C: The Complete Reference
Author/s: Herbert Schildt
Publisher: Osborne McGraw-Hill
2600 Tenth Street
Berkeley, California 94710
ISBN #: 0-07-881263-1
If you are just starting into the C langugage you should get a
copy of this book. This book tries to be the COMPLETE REFERENCE TO C
and to a large extent it is. When I need to known how to use a
multidimensional array or when I want a library routine that will
copy a string this is the book I look in first.
"C: The Complete Reference" is a large book. It is over 700 pages
and it will probably take you a few weeks to read through it but it is
worth the effort.
_______________________________________________________________________
Title: Turbo C Programmer's Resource Book
Author/s: Fredrick Holtz
Publisher: TAB books Inc
P.O. Box 40
Blue Ridge Summit, PA 17214
ISBN #: 0-8306-3030-9
If you are not sure of the differents between a string and a
character array or if the following line of codes makes your eyes cross
int x=0;
while((a[x] += (a[x]>='A' && a[x]<='Z') ? ' ':0)) ++x;
Then this books should help quite a bit. While the title says TURBO C
the book will be of value with any C compiler. It very gently and
carefully explains the C languages. This is not a complete reference
to C but is an excellent tutorial for someone just starting into the
languages.
Hint: The above code converts the lower case letters in a string to
upper case letters.
C News 1-02 Page 3 10 Jan 1988
======================================================================
BOOK REVIEWS
======================================================================
______________________________________________________________________
Title: Crafting C Tools for the IBM PCs
Author: Joe Campbell
Publisher: Prentice-Hall Software Series
ISBN #: 0-13-188418-2
This book is an excellent one to read if you want to understand the
internal workings of the 8086/8088 processor and MS-DOS. The author
provides valuable insites into how programs are loaded and executed
by DOS and how Assembler-to-C module communication occurs. Sections
are included on directory structure, keyboard input handling,
standard output as well as direct video access, and advanced video
topics such as coding window subroutines. The last topics covered
include coding your own interrupt handling routine and serial
communication processor.
Despite its title, this book is almost one-third Assembler routines.
Many Assembler and C routine examples are included; the examples are
built up chapter-to-chapter, eventually resulting in a
sophisticated directory listing program.
A section is included on C compiler differences, memory model
considerations for C programs, and the complete 8086 instruction
set.
I recommend this book to anyone who wants to use C and Assembler to
write DOS utility programs.
_____________________________________________________________________
C News 1-02 Page 4 10 Jan 1988
======================================================================
TurboC and TSR's by Arnie Cherdak..
======================================================================
It is unfortunate that Borland's documentation of their INTERRUPT type
function is rather sketchy. Certain features appear to be a mystery
and I wanted to share some of the insights I have had. My problem
related to the code generated by the Turbo C compilers.
INTRODUCTION
An interrupt service routine (ISR) terminates with an "iret" assembly
language instruction. The difference between this and a regular "ret"
instruction used to return from a regular function call is shown below.
CPU Action Instructions>>> ret far ret iret
pop instruction pointer value YES Y Y
pop code segment value NO Y Y
pop flags N N Y
Functions compiled in the Tiny, Small, and Compact models would use
the "ret" instruction since they have <= 64K of code. Medium, Large,
and Huge model functions would use the far ret instruction to allow
function calls beyond the 64K limit.
The values on the stack get there through the normal action brought
about by the instructions used to get to the functions. A simple call
within a 64K segment causes the instruction pointer to be pushed onto
the stack while a far call causes the code segment value to be added.
Indirect calls are a bit different but result in the same stack
configuration. An interrupt service routine is executed through an
"int" instruction which causes the flags, segment, and instruction
pointer to be pushed on the stack before the CPU is sent off to execute
the routine.
OBSERVATION
I recently bought Al Stevens' book, "Turbo C -- Memory-Resident
Utilities, Screen I/O and Programming Techniques." In my opinion,
he has written an exceptionally clear and understandable text and
has produced a fine bit of programming that works extremely well.
He has my congratulations on a job well done.
In going through Stevens' code for interrupt type functions, I saw
that he invokes ISR's within those functions with simple function
calls and apparently without accomodation for the iret instruction
that must appear at the exit point of the ISR. An example:
C News 1-02 Page 5 10 Jan 1988
======================================================================
TurboC and TSR's by Arnie Cherdak..
======================================================================
/***************************************************************
QUEST.C -- Test program to examine ISR return code
****************************************************************/
#include <stdio.h>
#define intnum 0x16
void interrupt (*oldisr)(); /* prototype and declaration of oldisr */
/* which is a variable declared as a */
/* pointer to an interrupt function. */
void interrupt newisr() /* new isr is executed each time */
{ /* interrupt intnum is executed */
(*oldisr)();
}
main() /* saves old isr vector & installs new */
{
oldisr = getvect(intnum);
setvect(intnum,newisr);
}
/******************** End of Quest.c **************************/
Here, the value of the vector for interrupt, intnum, is retrieved and
saved and it is then replaced with a vector pointing to the new isr,
"newisr." OK so far!
Here's where my understanding goes to pot. The new isr calls the old
isr which is a construct Stevens uses quite frequently although there
is generally other code within the new isr as might be expected. I left
it out here to simplify matters. Now regardless which memory model is
applied here, it seems that the function call to oldisr should result
in a far call instruction being pushed onto the stack by Turbo C and,
as I know from my travels through the BIOS listings, oldisr invariably
returns with an iret. It seems that the thing should blow up with the
stack underflowing almost immediately but it doesn't. It works just
fine.
C News 1-02 Page 6 10 Jan 1988
======================================================================
TurboC and TSR's by Arnie Cherdak..
======================================================================
Obviously, I missed something. The Turbo C manuals don't clarify this
or even seem to mention it. TC must make an accomodation for the type
of the called isr vector but I was baffled. Anybody have any insights
to share?
I'm going to compile the above example using the TCC switch to yield
an assembly language output. I should be able to see what's happening
from that.
/***************** TIME PASSES *********************************/
THE ANSWER
Well, I used the "-S" switch on TCC, the command line compiler, and I
got my answer. As you can see from the resulting assembly language
output below, Turbo C inserts a "pushf" instruction ahead of the call
to "oldisr" which causes the flags to be pushed onto the stack. Next,
notice that the call to oldisr is an indirect call using the value of
the vector to oldisr stored in memory. In effect, Turbo C has
circumvented the effects of the compilation memory model type by
using the pushf and the indirect call which created a stack configuration
exactly like that produced by an "int" instruction and allowed the "iret"
in the oldisr to execute without bombing the system.
MYSTERY SOLVED!!!
;=====================================================================
;
; ASSEMBLY LANGUAGE OUTPUT FROM TCC FOR COMPILATION OF
; ISR ROUTINE, QUEST.C
;
;=====================================================================
name quest
_TEXT segment byte public 'CODE'
DGROUP group _DATA,_BSS
assume cs:_TEXT,ds:DGROUP,ss:DGROUP
_TEXT ends
_DATA segment word public 'DATA'
_d@ label byte
_DATA ends
_BSS segment word public 'BSS'
_b@ label byte
_BSS ends
_TEXT segment byte public 'CODE'
; Line 11
_newisr proc far
push ax
push bx
push cx
push dx
push es
push ds
push si
push di
push bp
mov ds,cs:DGROUP@
C News 1-02 Page 7 10 Jan 1988
======================================================================
TurboC and TSR's by Arnie Cherdak..
======================================================================
; Line 12
pushf ; <============== LOOK HERE!!!!!
call dword ptr DGROUP:_oldisr ; <============== Turbo C Did It!
; Line 13
@1:
pop bp
pop di
pop si
pop ds
pop es
pop dx
pop cx
pop bx
pop ax
iret
_newisr endp
; Line 16
_main proc near
; Line 17
mov ax,22
push ax
call near ptr _getvect
pop cx
cwd
mov word ptr DGROUP:_oldisr+2,dx
mov word ptr DGROUP:_oldisr,ax
; Line 18
mov ax,offset _newisr
mov dx,cs
push dx
push ax
mov ax,22
push ax
call near ptr _setvect
add sp,6
; Line 19
@2:
ret
_main endp
_TEXT ends
_BSS segment word public 'BSS'
public _oldisr
_oldisr label dword
db 4 dup (?)
_BSS ends
_DATA segment word public 'DATA'
_s@ label byte
_DATA ends
_TEXT segment byte public 'CODE'
extrn DGROUP@:word
extrn _setvect:near
public _newisr
public _main
extrn _getvect:near
_TEXT ends
end