0% found this document useful (0 votes)
5 views4 pages

ProgrammingStructures

Uploaded by

sanjanatambe19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

ProgrammingStructures

Uploaded by

sanjanatambe19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Computer Systems Fundamentals 600.

333/443

Programming (Control) Structures Guide


Jorge Vasconcelos

Programming Control Structures refer to the way computer instruction flow is managed. In principle, instructions are
executed one after another, in the same way they were stored in the computer memory (von Neumann’s model).
However, computing solutions hardly require strictly sequential programs, instead, some instructions have to be executed
conditionally and many others have to be repeated several times.

Historically, such kind of behavior was classified as (see http://en.wikipedia.org/wiki/Structured_program_theorem.)

1. Sequence,

2. Selection, and

3. Iteration.

Computer languages with statements that directly implement those structures are known as structured languages.

For example, in C or C++, a sequence of instructions is denoted by the symbols { and }, the selection of actions occurs
with the statement if, or if-else, and iteration is accomplished with the loops for, while, and do-while.

Assembly languages are not structured in the sense that they do not provide specific instructions to control instruction-
flow; however, that is easily implemented, and is an essential feature of any language compiler. At this point, the
flowcharts corresponding to each structure result quite useful for the compiler designer or assembly programmer..
Computer Systems Fundamentals 600.333/443

Programming (Control) Structures Guide


Jorge Vasconcelos

(Abridged section)

Sequence structure flowchart Assembly template C/C++

int main ()

Start: ; label for begining { // Start

nop ; replace by instruction 1 function1 ();

nop ; replace by instruction 2 function2 ();

nop ; replace by instruction 3 function3 ();


return 0;
End: ; end of the sequence } // End
Computer Systems Fundamentals 600.333/443

Selection structure flowchart I Assembly template C/C++

bne $t0, $0, next ; t0 is not 0, goto next if (t0==0)

nop ; replace by instruction 1 function1();

next: // next
nop ; replace by instruction 2 function2();

Selection structure flowchart II Assembly template C/C++

if (t0==0)

function1();

< Insert your code here > else

function2();

function3(); // next

Selection structure flowchart II Assembly template C/C++


Switch (n)
{

< Insert your


case 0: function1();
break;
< Insert your code here > case 2: function2();
chart here > break;
default: function3();
break;
}
Computer Systems Fundamentals 600.333/443

Iteration structure flowchart I Assembly template C/C++


loop: //loop

beq $t0, $0, next ; t0 is 0, goto exit while (t0 = 0)


{

nop ; replace by instruction 1 function1();

j loop }

exit: //exit
nop ; replace by instruction n

Iteration structure flowchart II Assembly template C/C++

< Insert your < Insert your


chart here > chart here >

Iteration structure flowchart III Assembly template C/C++

< Insert your < Insert your


chart here > chart here >

You might also like