Difference between revisions of "W1151 Conditional and Flow Chart"

From Coder Merlin
Line 10: Line 10:
As a quick review of a real-world example, let's examine the Hello, World! program in assembly language:
As a quick review of a real-world example, let's examine the Hello, World! program in assembly language:


<syntaxhighlight lang="assembly">
<syntaxhighlight lang="swift">
         .global _start
         .global _start



Revision as of 16:18, 4 January 2020

Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder
Confluence

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.

In the example above, the program execution begins at address 0x8020 and completes at address 0x8026. All instructions are executed sequentially.

As a quick review of a real-world example, let's examine the Hello, World! program in assembly language:

        .global _start

        .text
_start:
        # write(1, message, 13)
        mov     $1, %rax                # system call 1 is write
        mov     $1, %rdi                # file handle 1 is stdout
        mov     $message, %rsi          # address of string to output
        mov     $12, %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
message:
        .ascii  "Hello, World!"

Topic Headers[edit]

Key Concepts[edit]

Exercises[edit]

References[edit]