Exercise 5            Name       _____________________    Points ___/15

Translate the following from C++ fragments to corresponding structured Assembler. Assume that i and j are defined as dwords. Use WriteDec and ReadDec for input and output.
1. (5)   if (i < eAx) {
            eAx++;
            cout << eAx;
          }
          else {
            eAx--;
            cout << eAx;
          }
.IF   i < eAx
       inc     eAx
       call    WriteDec
.ELSE
       dec    eAx
       call    WriteDec
.ENDIF
2. (5)    for (i=0; i<10; i++)
            for (j=10; j>5; j--) {
                eAx = i*j;
                cout << eAx;
            }
       mov   i, 0
@for:
       cmp   i, 10
       jl       @do
       jmp   @endfor
  @do:
      mov    j, 10
    @@for:
                cmp     j, 5
                jg        @@do
                jmp     @@endfor
        @@do:
                mov     eAx, i
                mul      j
                call      WriteDec
                dec      j
                jmp     @@for
       @@endfor:
        inc    i
        jmp  @@for
@@endfor:
3. (5)   int A[] = {15, 14, 9, 3, -1};
         i = 0;
          while (A[i] > 0){
            A[i] = A[i]/3;
            i++;

          }
.data
         A   dword   15, 14, 9, 3, -1
.code
              mov     eBx, 0
.WHILE   A[eBx*4] > 0
              mov      eAx, A[eBx*4]
              mov      eDx, 0
              div        dword 3
              mov      A[eBx*4], eAx
              inc         eBx
.ENDW