Software Development for Engineers: C/C++, Pascal, Assembly, Visual Basic, HTML, Java Script, Java DOS, Windows NT, UNIX
5/5
()
About this ebook
Related to Software Development for Engineers
Related ebooks
Computer Programming and Computer Systems Rating: 0 out of 5 stars0 ratingsARM System Developer's Guide: Designing and Optimizing System Software Rating: 4 out of 5 stars4/5Software Development with C++: Maximizing Reuse with Object Technology Rating: 0 out of 5 stars0 ratingsAdvanced Turbo C Programming Rating: 5 out of 5 stars5/5Real-Time Embedded Systems Rating: 0 out of 5 stars0 ratingsShared Memory Application Programming: Concepts and Strategies in Multicore Application Programming Rating: 0 out of 5 stars0 ratingsProgramming Microcontrollers in C Rating: 5 out of 5 stars5/5WPF in Action with Visual Studio 2008: Covers Visual Studio 2008 Service Pack 1 and .NET 3.5 Service Pack 1! Rating: 0 out of 5 stars0 ratingsModern C for Absolute Beginners: A Friendly Introduction to the C Programming Language Rating: 0 out of 5 stars0 ratingsEmbedded Microcontroller Interfacing for M-COR ® Systems Rating: 0 out of 5 stars0 ratingsPractical Parallel Computing Rating: 0 out of 5 stars0 ratingsGPU Computing Gems Jade Edition Rating: 5 out of 5 stars5/5Multicore DSP: From Algorithms to Real-time Implementation on the TMS320C66x SoC Rating: 0 out of 5 stars0 ratingsExploring the Python Library Ecosystem: A Comprehensive Guide Rating: 0 out of 5 stars0 ratingsOpen Client/Server Computing and Middleware Rating: 0 out of 5 stars0 ratingsEmbedded Microprocessor Systems: Real World Design Rating: 0 out of 5 stars0 ratingsStructured Parallel Programming: Patterns for Efficient Computation Rating: 1 out of 5 stars1/5Computer Programming and Architecture: The Vax Rating: 0 out of 5 stars0 ratingsIntroduction to Parallel Programming Rating: 0 out of 5 stars0 ratingsTheoretical Studies in Computer Science Rating: 0 out of 5 stars0 ratingsAdvanced Programming with Microsoft QuickC Rating: 0 out of 5 stars0 ratingsBeginning Data Structures Using C Rating: 4 out of 5 stars4/5Computer Programming: A Mixed Language Approach Rating: 0 out of 5 stars0 ratingsComputer Fundamentals and C Programming Rating: 0 out of 5 stars0 ratingsConceptive C Rating: 0 out of 5 stars0 ratingsHistory of Programming Languages Rating: 3 out of 5 stars3/5BeagleBone By Example Rating: 0 out of 5 stars0 ratingsPHP Programming Solutions Rating: 0 out of 5 stars0 ratingsThe Art of Programming Embedded Systems Rating: 3 out of 5 stars3/5
Software Development & Engineering For You
Managing Humans: Biting and Humorous Tales of a Software Engineering Manager Rating: 4 out of 5 stars4/5Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5Hand Lettering on the iPad with Procreate: Ideas and Lessons for Modern and Vintage Lettering Rating: 4 out of 5 stars4/5Learn to Code. Get a Job. The Ultimate Guide to Learning and Getting Hired as a Developer. Rating: 5 out of 5 stars5/5JavaScript Beginners Learn Java Script Programming Language, Basics Concept & Practice by Example Rating: 4 out of 5 stars4/5How to Write Effective Emails at Work Rating: 4 out of 5 stars4/5The Essential Persona Lifecycle: Your Guide to Building and Using Personas Rating: 4 out of 5 stars4/5Python For Dummies Rating: 4 out of 5 stars4/5Beginning Programming For Dummies Rating: 4 out of 5 stars4/5OneNote: The Ultimate Guide on How to Use Microsoft OneNote for Getting Things Done Rating: 1 out of 5 stars1/5Level Up! The Guide to Great Video Game Design Rating: 4 out of 5 stars4/5Flow: A Handbook for Change-Makers, Mavericks, Innovators and Leaders Rating: 0 out of 5 stars0 ratingsModern C++ for Absolute Beginners: A Friendly Introduction to C++ Programming Language and C++11 to C++20 Standards Rating: 0 out of 5 stars0 ratingsChaos Monkeys: Obscene Fortune and Random Failure in Silicon Valley Rating: 4 out of 5 stars4/5PYTHON: Practical Python Programming For Beginners & Experts With Hands-on Project Rating: 5 out of 5 stars5/5Tiny Python Projects: Learn coding and testing with puzzles and games Rating: 5 out of 5 stars5/5SQL For Dummies Rating: 0 out of 5 stars0 ratingsHow Do I Do That In InDesign? Rating: 5 out of 5 stars5/5How Do I Do That in Photoshop?: The Quickest Ways to Do the Things You Want to Do, Right Now! Rating: 4 out of 5 stars4/5iPhone Application Development For Dummies Rating: 4 out of 5 stars4/5Android App Development For Dummies Rating: 0 out of 5 stars0 ratingsEngineering Management for the Rest of Us Rating: 5 out of 5 stars5/5Good Code, Bad Code: Think like a software engineer Rating: 5 out of 5 stars5/5Debugging: The 9 Indispensable Rules for Finding Even the Most Elusive Software and Hardware Problems Rating: 4 out of 5 stars4/5Photoshop For Beginners: Learn Adobe Photoshop cs5 Basics With Tutorials Rating: 0 out of 5 stars0 ratingsAdobe Illustrator CC For Dummies Rating: 5 out of 5 stars5/5Git Essentials Rating: 4 out of 5 stars4/5Ry's Git Tutorial Rating: 0 out of 5 stars0 ratings
Reviews for Software Development for Engineers
1 rating0 reviews
Book preview
Software Development for Engineers - William Buchanan
1
Introduction
1.1 Introduction
Software development has grown over the years from simple BASIC programs written on small hobby computers to large software systems that control factories. Many applications that at one time used dedicated hardware are now implemented using software and programmable hardware. This shift in emphasis has meant that, as a percentage, an increasing amount of time is spent on software and less on hardware development.
Electrical, electronic and software engineers require a great deal of flexibility in their approach to system development. They must have an understanding of all levels of abstraction of the system, whether it be hardware, software or firmware. The system itself could range from a small 4-bit central heating controller to a large industrial control system. In the development of any system the engineer must understand the system specification from its interface requirements, its timing requirements, its electrical characteristics, and so on.
The software that runs on a system must be flexible in its structure as the developer could require to interrogate memory addresses for their contents or to model a part of the system as an algorithm. For this purpose the programming languages C and Pascal are excellent in that they allow a high-level of abstraction (such as algorithm specification) and allow low-level operations (such as operations on binary digits). They have a wide range of applications, from commerce and business to industry and research, which is a distinct advantage as many software languages have facilities that make them useful only in a particular environment. For example, in the past, business and commercial applications used COBOL extensively, whereas engineering and science used FORTRAN.
1.2 Hardware, software and firmware
A system consists of hardware, software and firmware, all of which interconnect. Hardware is ‘the bits that can be touched’, that is, the components, the screws and nuts, the case, the electrical wires, and so on. Software is the programs that run on programmable hardware and change their operation depending on the inputs to the system. These inputs could be taken from a keyboard, interface hardware or from an external device. The program itself cannot exist without some form of programmable hardware such as a microprocessor or controller. Firmware is a hardware device that is programmed using software. Typical firmware devices are EEPROMs (Electrically Erasable Read Only Memories), and interface devices that are programmed using registers.
In most applications, dedicated hardware is faster than hardware that is running software, although systems running software programs tend to be easier to modify and require less development time.
1.3 Basic computer architecture
The main elements of a basic computer system are a central processing unit (or microprocessor), memory, and input/output (I/O) interfacing circuitry. These are interconnected by three main buses: the address bus; the control bus; and the data bus, as illustrated in Figure 1.1. External devices such as a keyboard, display, disk drives, and so on, can connect directly onto the data, address and control buses, or connect through I/O interfacing circuitry.
Figure 1.1 Block diagram of a simple computer system
Memory normally consists of RAM (random access memory) and ROM (read only memory). ROM stores permanent binary information, whereas RAM is a non-permanent memory and loses its contents when the power is taken away. RAM memory is used to run application programs and to store information temporarily.
The microprocessor is the main controller of the computer. It fetches binary instructions (known as machine code) from memory, it then decodes these into a series of simple actions and carries out the actions in a sequence of steps. These steps are synchronized by a system clock.
The microprocessor accesses a memory location by putting its address on the address bus. The contents at this address are placed on the data bus and the microprocessor reads the data from the data bus. To store data in memory the microprocessor places the data on the data bus. The address of the location in memory is then put on the address bus and the data is then read from the data bus into the required memory address location.
1.4 Compiling, linking and producing an executable program
A microprocessor only understands binary information and operates on a series of binary commands known as machine code. It is extremely difficult to write large programs in machine code, so that high-level languages are used instead. A low-level language is one which is similar to machine code and normally involves the usage of keyword macros to replace machine code instructions. A high-level language has a syntax that is almost like written English and thus makes a program easy to read and to modify. In most programs the actual operation of the hardware is invisible to the programmer.
A compiler changes the high-level language into machine code. High-level languages include C, BASIC, COBOL, FORTRAN and Pascal; an example of a low-level language is 80386 Assembly Language.
Figure 1.2 shows the sequence of events that occur to generate an executable program from a C or Pascal source code file (the filenames used in this example relate to a PC-based system). An editor creates and modifies the source code file; a compiler then converts this source code into a form which the microprocessor can understand, that is, machine code. The file produced by the compiler is named an object code file code (note that Turbo Pascal does not produce an object code file). This file cannot be executed as it does not have all the required information to run the program. The final stage of the process is linking, which involves adding extra machine code into the program so that it can use devices such as a keyboard, a monitor, and so on. A linker links the object code file with other object code files and with libraries to produce an executable program. These libraries contain other object code modules that are compiled source code.
Figure 1.2 Edit, compile and link processes
If compilation or linking steps generate errors or warnings then the source code must be modified to eliminate them and the process of compilation/linking begins again. Warnings in the compile/link process do not stop the compiler or linker from producing an output, but errors will. All errors in the compilation or linking stage must be eliminated, whereas it is only advisable to eliminate warnings.
1.5 C compilation
Borland C++ Version 3.0 is an integrated development package available for PC-based systems. It contains an editor, compiler, linker and debugger (used to test programs). The editor creates and modifies source code files and is initiated by running BC.EXE. Figure 1.3 shows a main screen with a source code file PROG1_1.C.
Figure 1.3 Borland C++ Version 3.0 main screen
Figure 1.4 shows the compile menu options within this package. A source code file is compiled by selecting Compile to OBJ. If there are no errors an object code file is produced (in this case PROG_1.OBJ). This is linked using Link EXE file (producing the file PROG_1.EXE). A compile and link process can also be initiated using the Make EXE file option. Programs are run from the Run menu option.
Figure 1.4 Borland C++ Version 3.0 compile menu options
1.6 Pascal compilation
Turbo Pascal Version 5.0 is an integrated development package available for PC-based systems. It contains an editor, compiler, linker and debugger (used to test programs). The editor creates and modifies source code files and is initiated by running TURBO. EXE. Figure 1.5 shows a main screen with a source code file PROG1_1.PAS.
Figure 1.5 Turbo Pascal Version 5.0 main screen
Figure 1.6 shows the compile menu options within this package. A source code file is compiled by selecting Compile. If there are no errors then an executable program is produced. If the destination is given as Memory then it does not save the executable file to the disk but runs it from memory. If the destination is to the Disk then an executable file will be produced (producing the file PROG_1.EXE). The destination can be toggled by pressing the ENTER key while the line cursor is on the Destination option. A program is run from the Run menu option.
Figure 1.6 Turbo Pascal Version 5.0 compile menu options
1.7 Introduction to C
This section gives a brief introduction to ANSI-C.
1.7.1 Pre-processor
The pre-processor acts on programs before the compiler. It uses commands that have a number-sign symbol (‘#’) as the first non-blank character on a line. Figure 1.7 shows its main uses, which are: including special files (header files) and defining various macros (or symbolic tokens). The #include directive includes a header file and #define defines macros. By placing these directives near the top of a source code file then all parts of the program have access to the information contained in them.
Figure 1.7 Operations on the program to produce an executable file
For example, the pre-processor directive:
includes the header file main.h. The inverted commas inform the preprocessor that this file will be found in the current working directory, while the directive
includes the file stdio.h found in the default include directory. This directory is normally set-up automatically by the system. For example, Turbo C Version 2.0 stores its header files, by default, in the directory \TC\INCLUDE and Borland C uses \BORLANDC\INCLUDE. Typically, header files on a Unix system are stored in the /usr/include directory.
To summarize, inverted commas (
) inform the pre-processor to search for the specified header file in the current directory (or the directory specified in the pathname). The chevron characters (< >) inform the preprocessor to search in the default include directory. It is not advisable to include any other file apart from header files. These have a ‘.h’ file extension (although this is not obligatory). Standard header files are used in conjunction with functions contained in libraries. They do not contain program code, but have information relating to functions. A given set of functions, such as maths or I/O, has a header file associated with it. Table 1.1 gives typical header files and their functionality.
Table 1.1
Typical header files
A macro replaces every occurrence of a certain token with another specified token. The following examples show substitutions using the #define directive.
Typically, as a matter of programming style, the definitions of constants, such as π, are given in uppercase characters.
1.7.2 Structure
Normally programs are split into a number of sub-tasks named functions. These are clearly distinctive pieces of code that perform particular operations. The main function (main ()) is the basic routine for controlling the flow of the program and calls other sub-functions.
C Program 1.1 is a simple program which uses the puts() function to display the text Essence of Software
. The puts() function is a standard function used to output text to the display; the header file associated with it is stdio.h. This header file is included using the #include directive.
The statement terminator (;) is used to end a line of code (or statement) and braces ({}) show the beginning ({) and end (}) of a block of code. Comments are inserted in the program between a start comment identifier (/*) and an end identifier (*/).
All C programs have a main() function which defines the entry point into the program and, by means of calling functions, controls general program flow. It can be located anywhere in the source code program, but is normally placed near the top of the file it is located in (making it easier to find). The int keyword preceding main() defines that the program returns a value to the operating system (or calling program). In this case, the return value is 0 (return (0)). Normally, a non-zero return value is used when the program has exited due to an error; the actual value of this gives an indication of why the program has exited. The void within the parenthesis of main() defines that there is no communication between the program and the operating system (that is, no values are passed into the program). Figure 1.8 shows the basic structure of a C program.
Figure 1.8 C program structure
1.7.3 Data types
Variables within a program can be stored as either numbers or characters. For example, the resistance of a copper wire would be stored as a number (a real value) and the name of a component (such as, R1
) would be stored as characters. Table 1.2 gives the four basic data types which define the format of variables.
Table 1.2
Basic data types
There are three basic extensions for the four types; these are:
An integer is any value without a decimal point; its range depends on the number of bytes used to store it. A floating point value is any number and can include a decimal point; this value is always in a signed format. Again, the range depends on the number of bytes used.
Integers normally take up 2 or 4 bytes in memory, depending on the compiler implementation. This gives ranges of –32768 to 32767 (a 2-byte int) and –2 147483 648 to 2 147483 647 (a 4-byte int), respectively.
1.7.4 Declaration of variables
A program uses variables to store data. Before the program can use a variable, its name and its data type must first be declared. A comma groups variables of the same data type. For example, if a program requires integer variables num_steps and bit_mask, floating point variables resistor1 and resistor2, and two character variables char1 and char2, then the following declarations can be made:
C Program 1.2 is a simple program that determines the equivalent resistance of two resistors of 1000 Ω and 500 Ω connected in parallel. It contains three floating point declarations for the variables resistor1, resistor2 and equ_resistance.
It is also possible to assign an initial value to a variable at the point in the program at which it is declared; this is known as variable initialization. C Program 1.3 gives an example of this with the declared variables resistor1 and resistor2 initialized to 1000.0 and 500.0, respectively.
1.7.5 Keywords
ANSI-C has very few reserved keywords (only 32); these cannot be used as program identifiers. C is case-sensitive and thus they must be used in lowercase. From these simple building blocks large programs can be built. The following gives a list of the keywords.
Functions are sections of code that perform a specified operation. They receive some input and produce an output in a way dictated by their functionality. These can be standardized functions which are inserted into libraries or are written by the programmer. ANSI-C defines some standard functions which provide basic input/output to/from the keyboard and display, mathematical functions, character handling, and so on. They are grouped together into library files and are not an intrinsic part of the language. These libraries link into a program to produce an executable program.
1.8 Introduction to Pascal
This section gives a brief introduction to Turbo Pascal.
1.8.1 Constant declarations
Pascal uses the const keyword to defined constant numeric values. The following examples show constant declarations for π and the speed of light (which is 3×10⁸).
In Pascal the case of the characters is ignored but, as a matter of programming style, the definition of constants, such as π, is given in uppercase characters.
1.8.2 Structure
Normally programs are split into a number of sub-tasks named procedures or functions. These are clearly distinctive pieces of code that perform particular operations. The main program is the basic routine to control the flow of a program and calls other sub-functions.
Pascal Program 1.1 is a simple program which uses the writeln procedure to display the text ‘Essence of Software’. The writeln procedure is a standard procedure which is used to output text to the display.
The statement terminator (;) is used to end a line of code (or statement) and the keywords begin and end define the beginning and end of a block of code. Comments are inserted into the program between a start comment identifier (/*) and an end identifier (*/).
All Pascal programs have a main program which defines the entry point into the program and, by means of calling functions and procedures, controls general program flow. In most cases it is be located at the end of the source code file.
Figure 1.9 shows the basic structure of a Pascal program. Each program has a program header which is defined with the program keyword. After this the program variables are declared. In this case the variables declared are var1, var2 (which are integers) and var3, var4 (which are real values). The main program is defined after the variable declaration and can be identified between the begin and end keywords. The final end keyword has a full-stop after it.
Figure 1.9 Pascal program structure
1.8.3 Data types
Variables within a program can be stored as either numbers or characters. For example, the resistance of a copper wire would be stored as a number (a real value) and the name of a component (such as, ‘R1’) would be stored as characters. Table 1.3 gives the four basic data types which define the format of variables.
Table 1.3
Basic Pascal data types
Other data types used in Turbo Pascal include:
An integer is any value without a decimal point; its range depends on the number of bytes used to store it. A floating point value is any number and can include a decimal point; this value is always in a signed format. Again, the range depends on the number of bytes