music |
OSdata.com |
branching
summary
This subchapter looks at branching.
free computer programming text book projecttable of contents
|
music |
OSdata.com |
This subchapter looks at branching.
free computer programming text book projecttable of contents
|
This subchapter looks at branching. Dont do anything you see in this subchapter!
Direct branching was a huge nightmare in early programming. This nightmare was often called spaghetti programming, because attempting to follow the logic of a program was often like trying to follow strands of spaghetti in a bowl.
This problem led directly to the introduction of structured programming and the loop control structures you have just learned.
So, why am I telling you about this?
You might use an older programming language, such as APL, which requires that you use direct branching to create the looping structures. You might program at machine or assembly level, where again you have to use unconditional or conditional branching to create your own control structures. Or you might encounter old software where you have actually trace through the spaghetti code for yourself.
The most common version of this command is the classic GOTO. In some languages you have the option as to whether you write it as GOTO or GO TO.
APL →B APL monadic function of the form is →B that transfers control to the statement numbered B.
BASIC GOTO label BASIC command that transfers control to the labelled statement. Labels in BASIC are numbers.
C goto label C statement that transfers control to the labelled statement. The goto must transfer control to a label that is in the current function.
FORTRAN GOTO label FORTRAN command that transfers control to the labelled statement. Labels in FORTRAN are numbers.
Pascal goto label Pascal command that transfers control to the labelled statement. Labels in Pascal are numbers from 0 to 9999 inclusive, which must be declared.
PL/I GO TO label PL/I command that transfers control to the labelled statement. May be abbreviated GOTO.
Control registers control some aspect of processor operation. The most universal control register is the program counter.
Almost every digital computer ever made uses a program counter. The program counter points to the memory location that stores the next executable instruction. Branching is implemented by making changes to the program counter. Some processor designs allow software to directly change the program counter, but usually software only indirectly changes the program counter (for example, a JUMP instruction will insert the operand into the program counter). An assembler has a location counter, which is an internal pointer to the address (first byte) of the next location in storage (for instructions, data areas, constants, etc.) while the source code is being converted into object code.
The VAX uses the 16th of 16 general purpose registers as the program counter (PC). Almost the entire instruction set can directly manipulate the program counter, allowing a very rich set of possible kinds of branching.
The program counter in System/360 and 370 machines is contained in bits 40-63 of the program status word (PSW), which is directly accessible by some instructions.
Processor flags store information about specific processor functions. The processor flags are usually kept in a flag register or a general status register. This can include result flags that record the results of certain kinds of testing, information about data that is moved, certain kinds of information about the results of compations or transformations, and information about some processor states. Closely related and often stored in the same processor word or status register (although often in a privileged portion) are control flags that control processor actions or processor states or the actions of certain instructions.
A few typical result flags (with processors that include them):
Some conditions are determined by combining multiple flags. For example, if a processor has a negative flag and a zero flag, the equivalent of a positive flag is the case of both the negative and zero flags both simultaneously being cleared.
A few typical control flags (with processors that include them):
See also Registers
Program control instructions change or modify the flow of a program.
The most basic kind of program control is the unconditional branch or unconditional jump. Branch is usually an indication of a short change relative to the current program counter. Jump is usually an indication of a change in program counter that is not directly related to the current program counter (such as a jump to an absolute memory location or a jump using a dynamic or static table), and is often free of distance limits from the current program counter.
The pentultimate kind of program control is the conditional branch or conditional jump. This gives computers their ability to make decisions and implement both loops and algorithms beyond simple formulas.
See also Program Control Instructions in Assembly Language
Coding example: I am making heavily documented and explained open source code for a method to play music for free almost any song, no subscription fees, no download costs, no advertisements, all completely legal. This is done by building a front-end to YouTube (which checks the copyright permissions for you).
View music player in action: www.musicinpublic.com/.
Create your own copy from the original source code/ (presented for learning programming).
return to table of contents
free downloadable college text book
Because I no longer have the computer and software to make PDFs, the book is available as an HTML file, which you can convert into a PDF.
previous page | next page |
Tweets by @osdata |
free computer programming text book projectBuilding a free downloadable text book on computer programming for university, college, community college, and high school classes in computer programming. If you like the idea of this project, Supporting the entire project: If you have a business or organization that can support the entire cost of this project, please contact Pr Ntr Kmt (my church) free downloadable college text book on computer programming. |
This web site handcrafted on Macintosh computers using Tom Benders Tex-Edit Plus and served using FreeBSD .
UNIX used as a generic term unless specifically used as a trademark (such as in the phrase UNIX certified). UNIX is a registered trademark in the United States and other countries, licensed exclusively through X/Open Company Ltd.
Names and logos of various OSs are trademarks of their respective owners.
Copyright © 2010 Milo
Created: December 19, 2010
Last Updated: December 20, 2010
return to table of contents
free downloadable college text book
previous page | next page |