W1151 Conditional and Flow Chart
Prerequisites[edit]
Background[edit]
Introduction[edit]
Until now, the programs which we have observed and written exhibited sequential flow. That is, they had a single entry point and a single exit point. Instruction execution began at the entry point, instructions were executed sequentially, and then the program execution completed. While this type of flow is useful in some simple cases in the general case the flow will be more complex.
Sequential Execution[edit]
In the example above, the program execution begins at address 0x8020 and completes at address 0x8026. All instructions are executed sequentially.
Let's examine a Hello, World! program in assembly language:
.global _start
.text
_start:
# write(1, messageA, 6)
mov $1, %rax # system call 1 is write
mov $1, %rdi # file handle 1 is stdout
mov $messageA, %rsi # address of string to output
mov $6, %rdx # number of bytes
syscall # invoke operating system to do the write
# write(1, messageB, 6)
mov $1, %rax # system call 1 is write
mov $1, %rdi # file handle 1 is stdout
mov $messageB, %rsi # address of string to output
mov $6, %rdx # number of bytes
syscall # invoke operating system to do the write
# exit(0)
mov $60, %rax # system call 60 is exit
xor %rdi, %rdi # we want return code 0
syscall # invoke operating system to exit
messageA:
.ascii "Hello "
messageB:
.ascii "World!"
Flowcharts[edit]
A flowchart is a type of diagram that enables us to visualize the flow of execution through a program. As such, flowcharts representing an entire program generally have a single entry point, a single exit point, and one or more processes. (In this case the word process is not the same as an operating system process, but represents the general usage of the word, i.e. "do something".) Throughout this experience, we'll introduce several symbols that are typically used in flowcharts.
Symbol | Meaning |
---|---|
Describes the direction of flow through the diagram, particularly when the flow is not in the traditional top-to-bottom order. | |
Indicates the beginning or end of a program or function. | |
Indicates an ordered series of logically grouped operations. |