Control Structures
These are examples of control structures. You may also be interested in:

 Conditional structures
 Exceptions
 Flow-control structures
 Loops

Task

List the conditional structures offered by a programming language. See Wikipedia: conditionals for descriptions.

Common conditional structures include if-then-else and switch.

Less common are arithmetic if, ternary operator and Hash-based conditionals.

Arithmetic if allows tight control over computed gotos, which optimizers have a hard time to figure out.



 
/* ARM assembly AARCH64 Raspberry PI 3B */
/*  program condstr64.s   */
 
/*******************************************/
/* Constantes file                         */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
/*******************************************/
/* Initialized data                        */
/*******************************************/
.data
szMessTest1:   .asciz "The test 1 is equal.\n"
szMessTest1N:  .asciz "The test 1 is not equal.\n"
szMessTest1A:  .asciz "The test 1A is equal.\n"
szMessTest1AN: .asciz "The test 1A is not equal.\n"
szMessTest2:   .asciz "The test 2 is equal.\n"
szMessTest2N:  .asciz "The test 2 is not equal.\n"
szMessTest3:   .asciz "The test 3 is <.\n"
szMessTest3N:  .asciz "The test 3 is >.\n"
szMessTest4:   .asciz "The test 4 is <=.\n"
szMessTest4N:  .asciz "The test 4 is >.\n"
szMessTest5:   .asciz "The test 5 is negative.\n"
szMessTest5N:  .asciz "The test 5 is positive ou equal 0.\n"
szMessTest6:   .asciz "Test 6 : carry is off.\n"
szMessTest6N:  .asciz "Test 6 : carry is set.\n"
szMessTest7:   .asciz "Test 7 : no overflow.\n"
szMessTest7N:  .asciz "Test 7 : overflow.\n"
szMessTest8:   .asciz "Test 8 : then.\n"
szMessTest8N:  .asciz "Test 8 : else.\n"
szMessResult:  .asciz "Test result = @ \n" 
/*******************************************/
/* UnInitialized data                      */
/*******************************************/
.bss 
sZoneConv:               .skip 30
/*******************************************/
/*  code section                           */
/*******************************************/
.text
.global main 
main:                           // entry of program
 
                                // classic test equal zero, not equal zero 
  //mov x1,0                    // comments
    mov x1,1                    //  or uncomments
    cmp x1,0                    // structure if else
    bne 1f
    ldr x0,qAdrszMessTest1      // if equal
    b 2f
1:
    ldr x0,qAdrszMessTest1N     // else
2:
    bl affichageMess
 
    mov x1,0                    //  comments
    //mov x1,1                  //  or uncomments
    cbnz x1,3f                  // other test and branch if not zero
    ldr x0,qAdrszMessTest1A
    b 4f
3:
    ldr x0,qAdrszMessTest1AN
4:
    bl affichageMess
                                // test equal 5, not equal 5 
    //mov x1,#5
    mov x1,10
    cmp x1,5
    bne 5f
    ldr x0,qAdrszMessTest2
    b 6f
5:
    ldr x0,qAdrszMessTest2N
6:
    bl affichageMess
 
                                // test < 5,  > 5  SIGNED
    mov x1,#-10
    //mov x1,#10
    cmp x1,#5
    bgt 7f
    ldr x0,qAdrszMessTest3
    b 8f
7:
    ldr x0,qAdrszMessTest3N
8:
    bl affichageMess
 
                                // test < 5,  > 5  UNSIGNED
    //mov x1,#-10
    mov x1,#2
    cmp x1,#5
    bhi 9f
    ldr x0,qAdrszMessTest4
    b 10f
9:
    ldr x0,qAdrszMessTest4N
10:
    bl affichageMess
 
                               // test < 0,  > 0 
    mov x1,2
    subs x1,x1,5               // s --> flags
    bpl 11f
    ldr x0,qAdrszMessTest5
    b 12f
11:
    ldr x0,qAdrszMessTest5N
12:
    bl affichageMess
 
    // carry off carry on
    //mov x1,#-10             // for carry set
    //mov x1,#10              // for carry off
    mov x1,(2<<62) - 1        // for carry off
    adds x1,x1,20             // s --> flags
    bcs 13f
    ldr x0,qAdrszMessTest6    // carry clear
    b 14f
13:
    ldr x0,qAdrszMessTest6N   // carry set
14:
    bl affichageMess
 
                              // overflow off overflow on
    //mov x1,#-10             // for not overflow 
    //mov x1,#10              // for not overflow
    mov x1,(2<<62) - 1        // for overflow 
    adds x1,x1,20             // s --> flags
    bvs 15f
    ldr x0,qAdrszMessTest7    // overflow off
    b 16f
15:
    ldr x0,qAdrszMessTest7N   // overflow on
16:
    bl affichageMess
 
    // other conditionnel test csel
    mov x2,-20
    mov x3,25
    mov x1,10                   // for equal
    //mov x1,#20                // for else
    cmp x1,10   
    csel x0,x2,x3,eq            // if x1=10 x0 = x2 else x0 = x3
    ldr x1,qAdrsZoneConv
    bl conversion10S
    ldr x0,qAdrszMessResult
    ldr x1,qAdrsZoneConv
    bl strInsertAtCharInc       // insert result at @ character
    bl affichageMess
 
                                // other conditionnel test cset
    //mov x1,10                 // for equal
    mov x1,20                   // for else
    cmp x1,10   
    cset x0,eq                  // if x1=10 x0 = 1 else x0 = 0
    ldr x1,qAdrsZoneConv
    bl conversion10S
    ldr x0,qAdrszMessResult
    ldr x1,qAdrsZoneConv
    bl strInsertAtCharInc       // insert result at @ character
    bl affichageMess
 
                                // other conditionnel test cinc
    mov x0,3
    mov x1,10                   // for equal
    //mov x1,20                 // for else
    cmp x1,10   
    cinc x0,x0,eq               // if x1=10 x0 = x0+1 else x0 = x0
    ldr x1,qAdrsZoneConv
    bl conversion10S
    ldr x0,qAdrszMessResult
    ldr x1,qAdrsZoneConv
    bl strInsertAtCharInc      // insert result at @ character
    bl affichageMess
 
                               // other conditionnel test csinc
    mov x0,3
    mov x2,6
    mov x3,11
    mov x1,10                  // for equal
    //mov x1,20                // for else
    cmp x1,10   
    csinc x0,x2,x3,ne          // if x1<>10 x0 = x2  else x0 = x3 + 1
    ldr x1,qAdrsZoneConv
    bl conversion10S
    ldr x0,qAdrszMessResult
    ldr x1,qAdrsZoneConv
    bl strInsertAtCharInc      // insert result at @ character
    bl affichageMess
100:                           // standard end of the program
    mov x0,0                   // return code
    mov x8,EXIT                // request to exit program
    svc 0                      // perform the system call
qAdrszMessTest1:         .quad szMessTest1
qAdrszMessTest1N:        .quad szMessTest1N
qAdrszMessTest1A:        .quad szMessTest1A
qAdrszMessTest1AN:       .quad szMessTest1AN
qAdrszMessTest2:         .quad szMessTest2
qAdrszMessTest2N:        .quad szMessTest2N
qAdrszMessTest3:         .quad szMessTest3
qAdrszMessTest3N:        .quad szMessTest3N
qAdrszMessTest4:         .quad szMessTest4
qAdrszMessTest4N:        .quad szMessTest4N
qAdrszMessTest5:         .quad szMessTest5
qAdrszMessTest5N:        .quad szMessTest5N
qAdrszMessTest6:         .quad szMessTest6
qAdrszMessTest6N:        .quad szMessTest6N
qAdrszMessTest7:         .quad szMessTest7
qAdrszMessTest7N:        .quad szMessTest7N
qAdrszMessTest8:         .quad szMessTest8
qAdrszMessTest8N:        .quad szMessTest8N
qAdrszMessResult:        .quad szMessResult
qAdrsZoneConv:           .quad sZoneConv
/********************************************************/
/*        File Include fonctions                        */
/********************************************************/
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
 
 