04. Code addressing: conditionals, loops and arrays

(unfinished before)

(reprise) Addressing:

Labels

⇒ Assembly lables: TODO example of data labels using in syscalls and loads/stores.

Multiplication and division

Multiplication implementation

Fixtime multiplication:

Conditionals

Full table in documentation

A bit of theory: canonical loop flow:

  1. Initialization

  2. condition Check

    1. (assembler language) jump outside (4)
  3. Body

  4. conditional variables Update

    1. (assembler language) jump to (2)

Why two jumps (alternative: final check and jump into)?

An example:

   1         li      $t0 10          # initialization
   2 loop:   blez    $t0 final       # condition check
   3         move    $a0 $t0
   4         li      $v0 1           # body: number output
   5         syscall
   6         li      $v0 11
   7         li      $a0 0x0a        # body: LF output
   8         syscall
   9         addiu   $t0 $t0 -1      # update
  10         j       loop            # try "b loop" here!
  11 final:  li      $v0 10          # stop
  12         syscall

See compiled code:

Nested loops

TODO: multimplication tablecolumn

Arrays

H/W

  1. EJudge: DigitSum 'Sum of digits'

    Input an integer (can be negative), and output sum of its' digits.

    Input:

    -12345
    Output:

    15
  2. EJudge: PlusMinus 'Plus and Minus'

    Input a cardinal N, then input N integers ai; output the result of a0-a1+a2-…±aN-1 .

    Input:

    4
    22
    13
    14
    15
    Output:

    8
  3. EJudge: EvenBack 'Even backwards'

    Input a cardinal N, then N integers. Output line by line only even ones, in reversed order.

    Input:

    6
    12
    -11
    3
    88
    0
    1
    Output:

    0
    88
    12
  4. EJudge: NoDups 'No dups'

    Input a cardinal N, then N integers. Output all the integers, skipping duplicated ones.

    Input:

    8
    12
    34
    -12
    23
    12
    -12
    56
    9
    Output:

    12
    34
    -12
    23
    56
    9

HSE/ArchitectureASM/04_ConditionalsArrays (последним исправлял пользователь FrBrGeorge 2019-11-27 10:53:03)