Page 167 - PowerPoint Presentation
P. 167

CAVITE STATE UNIVERSITY
                               T3 CAMPUS
                               Department of Information Technology          COSC 65 – Programming Languages

                     ADD – add second operand to first.
                     SUB – Subtract second operand to first.
                     CMP – Subtract second operand form first for flags only.
                     AND – Logical AND between all bits of two operand. These rules apply:
                                     1 AND 1 = 1
                                     1 AND 0 = 0        As you see, we get 1 only
                                     0 AND 1 = 0        when both bits are 1.
                                     0 AND 0 = 0
                       .
                     TEST – The same as AND but for flags only.
                     OR – Logical OR between all bits of two operand. These rules apply:
                                     1 OR 1 = 1
                                     1 OR 0 = 1       As you see, we get 1 every time when
                                     0 OR 1 = 1       at least one of the bits is 1.
                                     0 OR 0 = 0
                 XOR – Logical XOR (exclusive OR) between all bits of two operands. These rules apply:
                                     1 XOR 1 = 0
                                     1 XOR 0 = 1      As you see, we get 1 every time when
                                     1 XOR 1 = 1      bits are different from each other.
                                     0 XOR 0 = 0

                           ; Sample code for addition/subtraction Instructions
                           .model small
                           .data
                           .code
                           main proc
                                  mov cl, 5     ; set 5 as value of cl
                                  add cl, 2     ; add 2 to cl. Can be change to sub for subtraction
                           endp
                           end main

                 ; Sample code for cmp or compare Instruction         CMP Results     ZF     CF
                 .model small                                   Destination < Source   0     1
                 .data
                 .code                                          Destination > Source   0     0
                                                                Destination < Source   1     0
                 main proc
                        mov ax, 500    ; set value of ax as 500
                        mov bx, 200    ; set value of bx as 200

                        cmp ax, bx     ; cmp (ax – Destination) (bx – Source)
                  endp

                  end main    To check what’s happening in this code:
                              1. Compile the load the emulator
                              2. click single step and check what’s happening per
                              line of code.
                              3. Repeat single step process 3 times.
                              4. Then click the flag button to see the CMP Results.
                              5. CF and ZF must be 0.
                              6. Try to change the value of ax and bx. Then repeat
                              the same process and check what will be the result.






                                                                                                 Page | 26
   162   163   164   165   166   167   168   169   170   171   172