I221154 F A2 Coal Merged
I221154 F A2 Coal Merged
                                                      Page 1 of 2
                           COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
    Explanation:
    It takes an integer, extracts its rightmost digit, and then shifts it one time to the right. After that, it uses a to
    execute an OR of the extracted rightmost bit's seven left shifts, saving the result in a. After completing this five
    times, it initializes b using eax.
                                                         Page 2 of 2
                           COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
                                     ASSIGNMENT#2 (FALL 2023)
                                                                         Assigned WORD
         Short for Assigned WORD                                               W
          WORD in DECIMAL(W)                                                  7823
       Convert WORD to HEX (WH)
                                                     Page 1 of 15
                         COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
                                   ASSIGNMENT#2 (FALL 2023)
1. Write equivalent Assembly instructions for the C++ code given below and also explain C++ code in
   given space?
   NOTE: AND performs a Boolean(bitwise) AND operation between each pair of matching bits in two
   operands and place result in the destination. AND instruction always clear overflow and carry flags. It
   modifies Sign, Zero and Parity flags.
                                                                                            Sign                          1
                                                                                            Zero                          0
                                                                                            Carry                         0
               mov al,0AEH                                                            Flags
               and al,246                                                                   Overflow                      0
                                                                                            Parity                        1
                                                                                            Auxiliary                     0
                                                          CODE
 .data
         ary db 26 dup(?)
         arysize= $-ary
         ary_copy db arysize dup(0)
         endmem db 1
 .code
                                                                 Page 2 of 15
                      COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
                                ASSIGNMENT#2 (FALL 2023)
 main PROC
      mov esi,OFFSET ary
      mov edi,OFFSET ary_copy
      mov ax,000FFh
      mov ecx,arysize
      and al,061h
      mov bl,al
      and bl,0CFH       ;masking
      L1:
            mov [esi],al
            mov [edi],bl
            inc esi
            inc edi
            inc al
            inc bl
      LOOP L1
             INVOKE ExitProcess,0
     main ENDP
     END main
                                           MEMORY
            0    1    2     3    4    5     6    7    8     9    A    B     C    D    E    F
   4000     61 62     63   64    65   66   67   68    69   6A   6B    6C    6D   6E   6F   70
   4010     71   72 73     74    75   76   77   78    79   7A    41   42    43   44   45   46
   4020     47   48   49   4A   4B    4C   4D   4E    4F   50   51    52    53   54   55   56
   4030     57 58     59   5A   1
                                                CODE
 .data
         ary db 26 dup(?)
                                                 Page 3 of 15
                       COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
                                 ASSIGNMENT#2 (FALL 2023)
         arysize= $-ary
         ary_copy db arysize dup(0)
         endmem db 1
 .code
         mov esi,OFFSET ary
         mov edi,OFFSET ary_copy
         mov ax,0041h
         mov ecx,arysize
         mov bl,al
         OR bl,00100000b
         L1:
              mov [esi],al
              mov [edi],bl
              inc esi
              inc edi
              inc al
              inc bl
         LOOP L1
MEMORY
             0    1    2    3       4    5      6    7     8        9   A         B    C    D         E    F
   4000      41   42   43   44     45    46     47   48   49    4A      4B        4C   4D   4E    4F       50
   4010      51   52   53   54     55    56     57   58   59    5A      61        62   63   64        65   66
   4020      67   68   69   6A     6B    6C     6D   6E   6F    70      71        72   73   74        75   76
   4030      77   78   79   7A     01
6. Update register after each line of code and update Flags after executing the following code
       mov   ax,0A593H                                                       AX        A5        93
       XOR   ax,-1                       Sign                                AX        5A        6C
       XOR   ax,0                        Zero                                AX        5A        6C
       XOR   ax,-1                                                           AX        A5        93
       XOR   ax,ax                       Carry                               AX        00        00
                                 Flags
                                         Overflow
       mov ax, 05A37H
       XOR al,0                          Parity                              AX        5A        37
                                                                             Al        5A        37
       XOR ah,1                          Auxiliary
       XOR al,ah                                                             AH        5B        37
                                                                             AL        5B        6C
                                                     Page 4 of 15
                      COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
                                ASSIGNMENT#2 (FALL 2023)
7. Write a program that finds parity of number given below? HINT: Use XOR and LOOP to find parity
                    .data
                            parity DQ 0A1B2C3D4E5F67890H
Answer:
.data
parity DQ 0A1B2C3D4E5F67890H
w dw 4 dup(0)
.code
main PROC
    mov edi, offset w
    mov ax, word ptr parity
    mov [edi], ax
    inc edi
    inc edi
    mov ax, word ptr parity + 2
    mov [edi], ax
    inc edi
    inc edi
    mov ax, word ptr parity + 4
    mov [edi], ax
    inc edi
    inc edi
    mov ax, word ptr parity + 6
    mov [edi], ax
Loop_strt:
    inc edi
    inc edi
    mov dx, [esi]
    mov bx, [edi]
    xor [esi], bx
    mov dx, [esi]
    Loop Loop_strt
main ENDP
END main
 INSTRUCTIONS: (Question 8-11) Perform each of the following operations on word size 2’s complement
numbers and update the answer and value of flags after performing the arithmetic. Perform all the steps in the
“calculation” box, only filling the answer will not get any credit.
8. Update flags after arithmetic instruction? Also state which of the following jumps will taken or not
    taken
                                                  Page 5 of 15
                      COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
                                ASSIGNMENT#2 (FALL 2023)
          Sign             1                                       Calculation
          Zero             0                                   1111 1111 1111 1110
                                                             + 1111 1100 0111 0000
    Flags Carry            1
                                                               1111 1010 0110 1110
          Overflow         0
          Parity           0
9. Update flags after arithmetic instruction? Also state which of the following jumps will taken or not
   taken
10. Update flags after arithmetic instruction? Also state which of the following jumps will taken or not taken
                                                 Page 6 of 15
                       COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
                                 ASSIGNMENT#2 (FALL 2023)
11. Update flags after arithmetic instruction? Also state which of the following jumps will taken or not taken
              mov bx,0FABDh
              add bx,0684Ah
                                                                             TAKEN                       NOT TAKEN
              jc l1                                     Jc            ----------------
          L1: jz L2                                     Jz                                           ----------------
          L2: jno L3
          L3: jns L4
                                                        Jno           ----------------
          L4: jp L5                                     Jns           ----------------
          L5: mov ah,04ch                               jp                                           ----------------
           Sign             0                                              Calculation
           Zero             0                                           1111 1010 1011 1101
                                                                      + 0110 1000 0100 1010
           Carry            1
                                                                        0110 0011 0000 0111
     Flags                  0
           Overflow
           Parity           0
           Auxiliary        1
12. Update value of ax and cx registers after every iteration. Update any changes to the done to flag
                                                     1            2          3        4          5       6
                                               CX   5         4          3        2          1       0
                                                 Page 7 of 15
                     COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
                               ASSIGNMENT#2 (FALL 2023)
               mov ecx,5                              AX      1      2    3   4     5   6
              mov ax,1
        L1:
             inc ax
             dec ecx
        jcxz end_loop
        jmp L1
        end_loop:
                        Sign                 0                            Calculation
                        Zero                 1                                 -
                        Carry                0
                  Flags                      0
                        Overflow
                        Parity               1
                        Auxiliary            0
                                            NOT
                                     TAKEN TAKEN
                           JNG                      -------
                           JNGE                    -------
                                                           Page 8 of 15
                     COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
                               ASSIGNMENT#2 (FALL 2023)
                         JGE      -------
                                                               Sign        0             Calculation
                                                               Zero        0          0000000000100000
                                                                                     - 1111111111011101
                                                               Carry       1
                                                                                       -------------------------
                                                         Flags             0          0000000001000011
                                                               Overflow
                                                               Parity      0
                                                               Auxiliary   1
14. Dry run program gives below update table for each iteration count total number of iterations took by
    the program
                                            CODE
 .data
           data dw   66h,01h,045h,01h,040h,05h,-025h,04h,-010h,011h
           swap db   0
 .code
     main PROC
         start:
          mov swap,0                          ;Reset swap flag to no swap
           mov ebx,0                           ;initialize array index to zero
 loop1:
         mov ax,[ebx+data]                   ;load number to ax
         cmp ax,[ebx+data+2]                 ;compare with next number
         jge noswap                         ;no swap if already inorder
                                                  Page 9 of 15
           COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
                     ASSIGNMENT#2 (FALL 2023)
        INVOKE ExitProcess,0
main ENDP
END main
                                  Page 10 of 15
                COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
                          ASSIGNMENT#2 (FALL 2023)
                                                                                     COUNT   SWAP
 66   1        45        1       40       5           -25          4    -10     11   0       0
66 1 45 1 40 5 -25 4 -10 11 1 0
66 45 1 1 40 5 -25 4 -10 11 2 1
66 45 1 1 40 5 -25 4 -10 11 3 0
66 45 1 40 1 5 -25 4 -10 11 4 1
66 45 1 40 5 1 -25 4 -10 11 5 1
66 45 1 40 5 1 -25 4 -10 11 6 0
66 45 1 40 5 1 4 -25 -10 11 7 0
66 45 1 40 5 1 4 -10 -25 11 8 1
66 45 1 40 5 1 4 -10 11 -25 9 1
66 45 1 40 5 1 4 -10 11 -25 10 0
66 45 1 40 5 1 4 -10 11 -25 11 0
66 45 40 1 5 1 4 -10 11 -25 12 1
66 45 40 5 1 1 4 -10 11 -25 13 1
66 45 40 5 1 1 4 -10 11 -25 14 0
66 45 40 5 1 4 1 -10 11 -25 15 1
66 45 40 5 1 4 1 -10 11 -25 16 0
66 45 40 5 1 4 1 11 -10 -25 17 1
66 45 40 5 1 4 1 11 -10 -25 18 0
66 45 40 5 1 4 1 11 -10 -25 19 0
66 45 40 5 1 4 1 11 -10 -25 20 0
66 45 40 5 1 4 1 11 -10 -25 21 0
66 45 40 5 1 4 1 11 -10 -25 22 0
66 45 40 5 4 1 1 11 -10 -25 23 1
                                              Page 11 of 15
                 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
                           ASSIGNMENT#2 (FALL 2023)
66 45 40 5 4 1 1 11 -10 -25 24 0
66 45 40 5 4 1 11 1 -10 -25 25 1
66 45 40 5 4 1 11 1 -10 -25 26 0
66 45 40 5 4 1 11 1 -10 -25 27 0
66 45 40 5 4 1 11 1 -10 -25 28 0
66 45 40 5 4 1 11 1 -10 -25 29 0
66 45 40 5 4 1 11 1 -10 -25 30 0
66 45 40 5 4 1 11 1 -10 -25 31 0
66 45 40 5 4 1 11 1 -10 -25 32 0
66 45 40 5 4 11 1 1 -10 -25 33 0
66 45 40 5 4 11 1 1 -10 -25 34 0
66 45 40 5 4 11 1 1 -10 -25 35 0
66 45 40 5 4 11 1 1 -10 -25 36 0
66 45 40 5 4 11 1 1 -10 -25 37 0
66 45 40 5 4 11 1 1 -10 -25 38 0
66 45 40 5 4 11 1 1 -10 -25 39 0
66    45    40      5       4        11           1           1        -10    -25    40   0
66    45    40      5       11       4            1           1        -10    -25    41   1
66 45 40 5 11 4 1 1 -10 -25 42 0
66 45 40 5 11 4 1 1 -10 -25 43 0
66 45 40 5 11 4 1 1 -10 -25 44 0
66 45 40 5 11 4 1 1 -10 -25 45 0
66 45 40 5 11 4 1 1 -10 -25 46 0
66 45 40 5 11 4 1 1 -10 -25 47 0
66 45 40 5 11 4 1 1 -10 -25 48 0
                                              Page 12 of 15
                       COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
                                 ASSIGNMENT#2 (FALL 2023)
 66      45       40      11         5         4        1           1       -10      -25          49          1
 66      45       40      11         5         4        1           1       -10      -25          50          0
 66      45       40      11         5         4        1           1       -10      -25          51          0
 66      45       40      11         5         4        1           1       -10      -25          52          0
 66      45       40      11         5         4        1           1       -10      -25          53          0
 66      45       40      11         5         4        1           1       -10      -25          54          0
 66      45       40      11         5         4        1           1       -10      -25          55          0
 66      45       40      11         5         4        1           1       -10      -25          56          0
 66      45       40      11         5         4        1           1       -10      -25          57          0
 66      45       40      11         5         4        1           1       -10      -25          58          0
 66      45       40      11         5         4        1           1       -10      -25          59          0
 66      45       40      11         5         4        1           1       -10      -25          60          0
 66      45       40      11         5         4        1           1       -10      -25          61          0
 66      45       40      11         5         4        1           1       -10      -25          62          0
 66      45       40      11         5         4        1           1       -10      -25          63          0
15. You are working on the development of an encryption process for a secure communication protocol for a
    highly sensitive application. As part of the encryption process, the system needs to perform a series of
    bitwise operations on the provided data. Your task is to design and implement an assembly program that
    can do these series of transformations on a 32-bit integer number mDATA.
Suppose an 16-bit number mFLAGS, you have to transform the data by applying the series of following 4-
bitwise operations on mDATA according to the specific bit value in mFLAGS as defined in the operation
description provided below:
Note: Not allowed to use any predefined rotate instruction like (ROL,ROR etc.)
Note: Not allowed to use any predefined rotate instruction like (ROL,ROR etc.)
                                                    Page 13 of 15
                    COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
                              ASSIGNMENT#2 (FALL 2023)
                           In key mixing operation, you must update the mDATA by performing XOR
                           operation with the a key value. A 32-bit key value must be generated by using
                           mFLAGS in such a way that mFLAGS is concatenated with mFLAGS.
                           i.e., if mFLAG is 1010110110101101 the key must be
                           10101101101011011010110110101101.
You must provide your permutation table in a char array in the data section.
                           For Example:
                           the above permutation table can be represented in char array as “160709 … 15”,
                           where the bit positions are in ascending order,
                           i.e., 16 is the new position for bit 0,
                           and 07 is the new position for bit 1,
                           and so on.
Note: You have to generate 16-bit number mFLAGS using your Roll Number excluding the character and the
first digit. For example if the number is 22i-9986 the mFLAGS must be 29986.
Answer:
                                              Page 14 of 15
                    COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
                              ASSIGNMENT#2 (FALL 2023)
16. Dry run program gives below update table for each iteration count total number of iterations took by
    the program
                                           CODE
 .data
     Multiplicand db 78                    ;   Consider    Assigned Number Digit
                                           ;   A0 which    is 4 bit
          Multiplier db 23                 ;   Consider    Assigned Number Digit A3
                                           ;   A0 which    is 4 bit
 Result db 0
.code
            mov ax,0
           mov cl,4
         mov al,multiplicand
         mov bl,multiplier
     checkbit:
         shr bl,1
         jnc skip
         add result,al
     skip:
         shl al,1
         loop checkbit
                             al                            bl
     Cf                 multiplicand                 Multiplier          CF                result
0 0 0 0 1 0 0 0 1 1 0 0 0 1
0 0 0 1 0 0 0 0 0 0 0 0 0 1
1 0 1 0 0 0 0 0 0 0 0 0 0 1
0 1 0 0 0 0 0 0 0 0 0 0 0 1
Page 15 of 15