Tuesday 27 December 2016

Smallest of two 8-bit numbers

Here is an example of Assembly Language code for 8086. This example illustrates how the smallest of two 8-bit number using Direct Addressing Mode is done.


CODE  SEGMENT                                            // start of the logical code segment
          ASSUME CS:CODE                               // this instruction will inform
                                                                           the assembler the assumed name of CS.              START: MOV  AL, 09H                       // this instruction will move                                                                                                the operand 09H to the accumulator.
              MOV BL, 03H                                    // this instruction will move
                                                                              the operand 03H to the Register B.
              CMP  AL, BL                                             // this instruction will compare the
                                                                              content of the Register B with the
                                                                              content of the accumulator, by the
                                                                              means of subtraction.
              JC NEXT                                            // this instruction will cause a jump
                                                                                to the next label if a carry is
                                                                                generated.
              MOV [2035H], BL                               // if carry is not generated the result
                                                                               from Register B would be moved
                                                                               to the memory location 2035H.
 NEXT: MOV [2035H], AL                               // if carry is generated the result
                                                                               from accumulator would be moved
                                                                               to the memory location 2035H.
CODE  ENDS                                                    // end of the logical code segment
     END START                                                // end of the program




NOTE:
While actually implementing this code the keyword next should be replaced with the address of the instruction.

No comments:

Post a Comment