Exercise 5            Name       _________________    Points __/23

Give the Assembler code that will implement the corresponding C++ function calls using register parameters.
Example:
    void putstrng(int length, char[] string);
    putstrng(ecx, edi);                              mov    ecx, 10
                                                     mov    edi, offset prompt
Example:                                             call   putstrng
    int abs(int x);
                                                     mov    ebx, y
    ebx = y;                                         call   abs
    z = abs(ebx);                                    mov    z, eax
1. (2 pt)

    void f1( int x );

    ebx = Hours;
    f1( ebx );
2. (2 pt)

    int f2( int x );
    ecx = Dollars;
    z = f2( ecx );
3. (3 pt)
    char f3( char x, char y );
    bl = 'B';
    al = '1';
    ch = f3( bl, al);
4. (5 pt)
    int f4( int x, int y );
    for (int ecx=0; ecx<5; ecx++) {
        ebx = ecx + 4;
        cout << f4(ecx, ebx);
    }
Give the Assembler that will implement the corresponding C++ functions using register parameters. Save and restore any registers modified by the function, excluding Ax which is used for returning results.
Example:
    int sum(int x, int y) {                                sum    Proc   Near
        return x + y;                                             PushFD
    }                                                             Mov    eAx, eBx
                                                                  Add    eAx, eCx
                                                                  PopFD
                                                                  Ret
      ebx = 5;                                             sum    Endp
      ecx = 4;
      cout << sum(ebx, ecx);                                      Mov    eBx, 5
                                                                  Mov    eCx, 4
                                                                  Call   sum
                                                                  Call   PutDec
 5.  (5 pt)

    int f5( int x, int y) {
        return x % y;
    }

    ebx = 421;
    edx = 13;
    ecx = f5(ebx, edx);
6. (6 pt)

    int f6( int x, int y) {
        if (x < y)
            return x;
        else
            return y;
    }

    ebx = 4;
    edx = 3;
    ecx = f6(ebx, edx);