SlideShare una empresa de Scribd logo
1 de 37
Descargar para leer sin conexión
INTERMEDIATE 8086 ASSEMBLY
 LANGUAGE PROGRAMMING

Cutajar & Cutajar
© 2012
Machine Code
2



       There are occasions when the programmer must program at the machine’s own
        level.
       Machine Code programs are tedious to write and highly error prone.
                                                 0000111100001111
        In situations where a high-level
                                                 0010010101010100
        language is inappropriate we
                                                 1010101010100101
        avoid working in machine code
        most of the time by making the computer do more of the work. Thus we write
        in assembly language and then the computer converts this assembly language
        program into machine code.
Assembly Language
3



       In assembly language, a mneumonic (i.e. memory aid) is used as a short notation
        for the instruction to be used.
        Assembly                  Machine Code
        Language
        SUB AX,BX                 001010111000011
        MOV CX,AX                 100010111001000
        MOV DX,0                  10111010000000000000000
    Assembly language is an intermediate step between high level languages and machine
    code. Most features present in HLL are not present in Assembly Language as type
    checking etc.
Compilers / Assemblers
4



       High-level Languages such as           Pascal Program
        Pascal programs are sometimes
                                                        Compiler
        converted firstly to assembly
        language by a computer program   Assembler language Program
        called compiler and then into
        machine code by another                         Assembler
        program called assembler           Machine Code Program

                                                  This version is
                                                actually loaded and
                                                     executed
General Purpose Registers
5

                                  AH        AL
        There are 4 general
         purpose registers in          AX
         the 8086.
                                  BH        BL
        They are all 16-bit
         registers
        Each byte can be              BX
         addressed individually   CH        CL
         by specifying the High
         order or the Low order
         byte of the register.         CX
                                  DH        DL

                                       DX
Some Simple Commands
6




       MOV AX,3    ; Put 3 into register AX
       ADD AX,2    ; Add 2 to the contents of AX
       MOV BX,AX   ; Copy the contents of AX in BX
       INC CX      ; Add 1 to the contents of CX
       DEC DX      ; Subtract 1 from the contents of DX
       SUB AX,4    ; Subtract 4 from the contents of AX
       MUL BX      ; Multiply the contents of AX with BX leaving
                    ; the answer in DX-AX
       DIV BX      ; Divide the contents of DX-AX by BX leaving
                    ; the quotient in AX and remainder in DX.
Number Formats
7
                                                                AX
                                                  AH                         AL
     MOV AH,01010101B                   0 1 0      1 0    1 0 1
     MOV AL,00100111B                   0 1 0      1 0    1 0 1 0 0 1 0 0 1 1 1
     MOV AX,3                           0 0 0      0 0    0 0 0 0 0 0 0 0 0 1 1
     MOV AH,AL                          0 0 0      0 0    0 1 1 0 0 0 0 0 0 1 1
     MOV AL,10D                         0 0 0      0 0    0 1 1 0 0 0 0 1 0 1 0
     MOV AL,10H                         0 0 0      0 0    0 1 1 0 0 0 1 0 0 0 0

    In case a number is moved (copied) into the register the base of a is specified by a
    letter B for Binary, D for Decimal and H for Hex.
AMBIGUITY
8



       Consider the instruction MOV DL, AH
         Does it mean ‘copy the contents of register AH to DL or

         Does it mean ‘copy A in hexadecimal into register DL

       To avoid this ambiguity all hexadecimal numbers must start with a number. This can
        always be done by preceding a number starting with A,B,C,D,E and F with a
        preceding zero to remove ambiguity.
         Thus MOV DL, AH means copy AH to DL whilst

         MOV DL, 0AH means sore hexadecimal A to DL
The Flags Register
9



       Some of the instructions (but not all) affect the flag register.
       The flag register signals the status of the CPU after the last operation performed.
       For example if SUB AX,2 results in zero the ZF get 1 (lights on) indicating that
        the result of the last operation was zero.
JUMPS
10



         Jump instructions allow the 8086 to take decisions according to information provided by
          the flag register.
         For example, if AX and BX contain the ASCII code for the same letter then do one
          thing, if not then do another.
         `
               …
               CMP AX,BX             ; Compares the contents of BX with that of AX
               JE SAME               ; Jump if they are equal to the point
                                     ; in the code labeled SAME
               …                     ; Obey these instructions if the contents of AX
               …                     ; is not equal to that of BX
     SAME:     MOV CX,AX             ; Program continues from here if AX = BX.
               …
Labels
11



        We saw that the jump instruction has a general format JE <label> where <label> is a
         facility offered by the assembler.
        These labels are converted by the assembler to exact address where the program is to
         continue.
           Labels must start with a letter and can contain thereafter letters, numbers and
             underscores (_).
           Spaces and punctuation marks are not permitted
           Avoid using keywords in labels
           Once_again, Next, Name34, this_37 are permitted as labels
           3rdday, tues+wed and semi;colons are not permitted as labels.
JUMP Conditions
12

     JA/JNBE      (CF and ZF) = 0          Above / Not Below or Equal
     JAE/JNB      CF = 0                   Above or Equal / Not Below
     JB/JNAE/JC   CF = 1                   Below / Not Above or Equal / Carry
     JBE/JNA      (CF or ZF) = 1           Below or Equal / Not Above
     JE/JZ        ZF = 1                   Equal / Zero
     JMP          none                     Unconditionally
     JNC          CF = 0                   No Carry
     JNE/JNZ      ZF = 0                   Not Equal / Not Zero
     JNO          OF = 0                   No Overflow
     JNP/JPO      PF = 0                   No Parity / Parity Odd
     JNS          SF = 0                   No Sign / Positive
     JO           OF = 1                   Overflow
     JP/JPE       PF = 1                   Parity / Parity Even
     JS           SF = 1                   Sign
     JG/JNLE      ZF = 0 and SF = OF       Greater / Not Less nor Equal
     JGE/JNL      SF = OF                  Grater or Equal / Not Less
     JL / JNGE    SF <> OF                 Less / Not Greater nor Equal
     JLE/JNG      (ZF = 1) or (SF <> OF)   Less or equal / not greater
     JCXZ         Register CX = 0          CX is equal to zero
Example using Jumps
13




              MOV CX, AX           ; Keep a copy of AX before modification
              SUB AX,BX            ; AX := AX – BX
              JZ MAKE1             ; This is instruction will cause execution
                                   ; to continue from MAKE1 if AX was
                                   ; equal to BX (subtraction resulted in Zero)
              MOV DX, 0            ; Otherwise store 0 in DX
              JMP RESET ; Jump to RESTORE where AX is restored
                                   ; thus avoiding the next instruction
     MAKE1:   MOV DX, 1            ; If AX = BX then we set DX to 1
     RESET:   MOV AX, CX           ; Restore the old value of AX

          Note that in the Code a colon ends a
                      label position
The Logical Family
14



     AND                                 NOT (Invert: One’s Complement)
     Contents of AX = 0000101011100011   Contents of AX = 0000101011100011
     Contents of BX = 1001100000100001   Contents of AX = 1111010100011100
     Contents of AX = 0000100000100001   after NOT AX is executed
     after AND AX,BX is executed

     OR                                  TEST
     Contents   of AX = 0000101011100011 Contents of AX =            0000101011100011
     Contents   of BX = 1001100000100001 Contents of BX =            1001100000100001
     Contents   of AX = 1001101011100011 Contents of AX =            0000101011100011
     after OR   AX,BX is executed        after TEST AX,BX            is executed

     XOR                                   Similar to AND but the result is not stored in AX
     Contents of AX = 0000101011100011               but only the Z-flag is changed
     Contents of BX = 1001100000100001    NEG (Two’s Complement)
     Contents of AX = 1001001011000010    Contents of AX = 0000101011100011
     after XOR AX,BX is executed          Contents of AX = 1111010100011101
                                          after NEG AX is executed
Use of Logical Family
15




     Symbol   ASCII (Dec)   ASCII (Hex)   By Making an AND between an ASCII value and 0FH
     0        48            30            we can obtain the required number.
     1        49            31            Say we AND 33H = 00110011B
     2        50            32                  with 0FH = 00001111B
     3        51            33
                                               We obtain = 00000011B                   (3)
     4        52            34
     5        53            35            By Making an OR between a number value and 30H we
     6        54            36            can obtain its ASCII code.
     7        55            37            Say we OR 05H         = 00000101B
     8        56            38                 with 30H         = 00110101B
                                              We obtain         = 00110101B
     9        57            39
                                                 (ASCII         value for ‘5’)
Masking
16



      By the use of masking we can set or test individual bits of a register

     Suppose we want to set the 3rd.
     bit of AX to 1 leaving the
     others unchanged.
                                                           Suppose we want to test the if the
            AX = 0101010100011001
                                                           6th. bit of AX is 1 or 0:
           04H = 0000000000000100
                                                                    AX = 0101010100011001
     OR AX,04H = 0101010100011101                                  20H = 0000000000100000
                                                           AND AX,20H = 0000000000000000
     Suppose we want to set the 5th.                       So if the result is 0 then that
     bit of AX to 0 leaving the                            particular bit was 0, 1 otherwise
     others unchanged.
                AX = 0101010100011001
            0FFEFH = 1111111111101111
     AND AX,0FFEFH = 0101010100001101
Instructions which affect Memory
17




         Computer memory is best thought of numbered pigeon holes (called locations),
          each capable of storing 8 binary digits (a byte)
      Data can be retrieved from memory, one or
                                                     [0000]
      two bytes at a time:                           [0001]
                                                     [0002]
     MOV AL, [20H] will transfer the                 [0003]
     Contents of location 20H to AL.                 [0004]
                                                     [0005]
     MOV BX, [20H] will transfer the contents of     [0006]
                                                     [0007]
     locations 20H and 21H to BX.                    [0008]
     MOV [20H], AL will transfer the contents of     [0009]
                                                     [000A]
     AL to memory location 20H                       [000B]
                                  Location ADDRESS   [000C]
                                                                    Location CONTENTS
Changing addresses
18



        Varying an address whilst a program is running involves specifying the locations
         concerned in a register.
        From all the general purpose registers BX is the only capable of storing such
         addresses.
           Thus MOV AX, [CX] is illegal

           Whilst MOV CL, [BX] copies the contents of memory location whose address is
            specified by BX into the register CL.
           And MOV [BX], AL copies the contents of AL in the memory location whose
            address is specified in BX
Examples Affecting Memory
19




        Consider the checkerboard memory test where a section of memory is filled with
         alternate 01010101 and 10101010.
        The following program does the checkerboard test on locations 200H-300H
         inclusive.

                  MOV BX,200H
                  MOV AX,1010101001010101B
         NEXT:    MOV [BX],AX
                  INC BX
                  CMP BX,300H
                  JLE NEXT
The Instruction Pointer (IP)
20



        The computer keeps track of the next line to
         be executed by keeping its address in a special   START
                                                              .           This is the
         register called the Instruction Pointer (IP) or                line which is
         Program Counter.                                     .
                                                              .           executing
        This register is relative to CS as segment
         register and points to the next instruction to    MOV AX,BX
         be executed.                                      MOV CX,05H
        The contents of this register is updated with     MOV DX,AX         IP
         every instruction executed.
                                                               .
        Thus a program is executed sequentially line
                                                               .
         by line
                                                               .
The Stack
21




        The Stack is a portion of memory
         which, like a stack of plates in a
         canteen, is organized on a Last-
         In-First-Out basis.
        Thus the item which was put last
         on the stack is the first to be
         withdrawn
The Stack Pointer
22



                                                        [0000]
                                                        [0002]
        The Stack pointer keeps track of the           [0004]
         position of the last item placed on the        [0006]
                                                        [0008]
         stack (i.e. the Top Of Stack)                  [000A]
                                                        [000C]
                                                   SP   [000E]
                                                        [0010]
                                                        [0012]
                                                        [0014]
        The Stack is organized in words, (i.e. two     [0016]
         bytes at a time). Thus the stack pointer is    [0018]
         incremented or decremented by 2.                 Note that on placing items on the
        The Stack Pointer points to the last                stack the address decreases
         occupied locations on the stack
PUSH & POP
23


                                                   PUSH AX       AX
        The two set of instructions which              [0000]
                                                        [0002]
                                                        [0004]
         explicitly modify the stack are the            [0006]
                                                        [0008]   NEW SP
         PUSH (which places items on the       OLD SP   [000A]
                                                        [000C]
         stack) and the POP (which                      [000E]
                                                        [0010]
         retrieves items from the stack). In            [0012]
                                                        [0014]
         both cases, the stack pointer is               [0016]
                                                        [0018]
         adjusted accordingly to point
                                                   POP AX
         always to the top of stack.                    [0000]
                                                                 AX
                                                        [0002]
        Thus PUSH AX means SP=SP-2                     [0004]
                                                        [0006]
         and AX -> [SP]                                 [0008]
                                                        [000A]
                                               OLD SP            NEW SP
                                                        [000C]
        POP AX means [SP] -> AX and                    [000E]
                                                        [0010]
         SP=SP+2.                                       [0012]
                                                        [0014]
                                                        [0016]
                                                        [0018]
Subroutines
24




        In high-level languages, procedures        START       SUB1 PROC
                                                                 .
         make it possible to break a large             .         .
         program down into smaller pieces so           .         .
                                                       .        RET
         that each piece can be shown to work
         independently. In this way the final       CALL SUB1
         program is built up of a number of
                                                       .
         trusty bricks and is easier to debug          .
         because the error is either localized to      .
         one subprogram or its interlinking.
         This has also the advantage of re-
         usability of bricks.
The CALL Mechanism
25



        Although at first sight the CALL        START       SUB1 PROC
         and RET mechanism can be                             .
                                                    .         .
         implemented by using two JMP’s.            .         .
         In fact this cannot be done since          .        RET
         the CALL mechanism remembers            CALL SUB1
         the place where it was called from                   1
                                                    .
         and returns to the line following it.      .
         Thus this is not a fixed address.          .
                                                 CALL SUB1
                                                   .
                                                              2
                                                   .
                                                   .
The Return Mechanism
26



        When a CALL is encountered the current value of the instruction pointer is pushed
         on the stack and the it is filled with the address stated by the call.
        Since the fetch cycle goes to search for the instruction pointed at by the instruction
         pointer, the program continues it’s execution from the first statement in the
         subroutine.
        On encountering the RET instruction the contents of the IP is popped from the stack
         thus continuing the execution where it was suspended.
        Thus care must be taken to leave the return address intact before leaving a
         subroutine. (i.e. a symmetrical number of pushes and pops within the subroutine)
Software Interrupts
27



        Software interrupts are like hardware interrupts which are generated by the program
         itself. From the interrupt number, the CPU derives the address of the Interrupt service
         routine which must be executed.
        Software interrupts in assembly language can be treated as calls to subroutines of
         other programs which are currently running on the computer.
        One of the most famous software interrupt is Interrupt No. 21H, which branches in
         the operating system, and permits the use of PC-DOS functions defined there.
           The function required to be performed by DOS is specified in AH prior to the the
             interrupt.
           The functions return and accept values in various registers.
           AN interrupt is called using the instruction INT followed by the interrupt number
             . For example: INT 21H
Some INT 21H functions
28



     Function   Description   Explanation
     Number
     1          Keyboard      Waits until a character is typed at the keyboard and then puts the ASCII
                Input         code for that character in register AL and echoed to screen
                (echoed)
     2          Display       Prints the character whose ASCII code is in DL
                Output

     8          Keyboard      Waits until a character is typed at the keyboard and then puts the ASCII
                Input         code for that character in register AL and NOT echoed to screen
                (No echo)
     9          Display       Prints a series of characters stored in memory starting with the one in the
                String        address given in DX (relative to DS).Stop when the ASCII code for $ is
                              encountered
INT 21H Example
29



     Prompt   DB    ‘Please enter 1 or 2: ‘,13D,10D,’$’
     Song1    DB    ‘So you think you can tell heaven from hell’
     Song2    DB    ‘Blue Sky is in pain’,13D,10D,’$’


     ASK:     MOV   DX, OFFSET Prompt
              MOV   AH,09H
                                                               This is only a
              INT   21H
                                                          program fragment to
                                                           illustrate the use of
     GET:     MOV   AH,01H
                                                           interrupt 21H – For
              INT   21H
                                                         full details consult the
                                                               MASM notes
              CMP   AL,01H
              JE    NEXT
              MOV   DX, OFFSET Song1
              MOV   AH,09H
              INT   21H
Addition and Subtraction with carry or
30
         borrow
        In assembly language there are two versions
         of addition and two versions of subtraction.           CF     CF
           ADD - Simple addition of two numbers
                                                          0
           ADC - Adds two numbers together with
             the carry flag                               0

           SUB – Simple subtraction of two
             numbers
           SBB – Subtracts the second number and       Last           0   1   1
             the carry flag (borrow)                    addition in   00 01 98 41 +
        This provides a means of adding numbers        case of an    00 02 71 64
                                                        outgoing      00 04 70 05
         greater than 32-bits.
                                                        carry
        CLC clears the carry for the first digit
         addition
The Compare Instruction
31



        The compare instruction does not change the contents of the registers involved but only
         sets the flag register accordingly.
        The actual operation performed by the compare is a subtraction, leaving the source and
         destination registers intact
        Consider CMP AX,BX : Flags are set according to the result of subtracting BX from AX:
           If AX = BX then the ZF is set to 1
           If AX > BX then the ZF is set to 0 and CF is set to 0 too
           If AX < BX then we need an external borrow, which is reflected in CF = 1
           These flags are tested in the ABOVE or BELOW jumps which test unsigned numbers
           The GREATER and LESS jumps are for signed numbers and work on the SF, OF
              and the ZF instead
Addressing Modes
32



        The addressing modes deal with the source and destination of the data required by
         the instruction. This can be either a register or a location in memory, or even a port.
        Various addressing modes exist:
           Register Addressing
           Immediate and Direct Addressing
           Indirect Addressing
           Indexed Addressing
           Based Addressing
           Based-Indexed Addressing




                                                 Computer Logic II
Register Addressing
33



        This addressing mode           General Purpose    Segment Registers
         involves the contents of      AX    AH      AL    CS
         the register directly as
                                       BX    BH      BL    DS
         for example:
                                       CX    CH      CL    SS
           MOV AX, BX
                                       DX    DH      DL    ES
           MOV CL, DL
        Note that the IP and          SI                  FLAGS
         Flags register cannot be      DI
                                                             IP
         accessed directly by the      SP
         programmer                    BP

                                                      AX           BX
                                    Ex. MOV AX,BX
Immediate and Direct Addressing
34



        In Immediate addressing – for example           Ex. MOV CL,61H
         MOV CL,61H – the immediate operand              CL
                                                                             61H
         61H is stored as part of the instruction.
         Thus the number 61H is loaded directly in
         CL.
        Direct addressing is similar except that in     Ex. MOV AL,[210H]
         this case the effective address of one of the   AL
         operands is taken directly from the
         instruction. Thus in MOV AL, [210H] the
         contents of location 210H relative to DS is
         put in AL                                         (DS:210H)         75H
Default Segment Register
35

                            Note that the default segment register can be changed
                            using the segment override, i.e. stating the whole
     General Purpose
                            address in the form DS: Offset
     AX   AH      AL
     BX   BH      BL   Relative to DS by default
     CX   CH      CL
     DX   DH      DL         NORMALLY                            FOR STRINGS

     SI                Relative to DS by default                         DS
     DI                Relative to DS by default                         ES
     SP                Relative to SS by default

     BP                Relative to SS by default

     IP                Relative to CS by default
Some other useful Instructions
36




        CLC: Clear Carry Flag (CF = 0)
        STC: Set Carry Flag (CF = 1)
        CMC : Complement Carry Flag (CF = CF)
        CBW: Convert Byte to Word
        CWD: Convert Word to Double-Word
        NEG: Negate (2’s Complement)
        NOT: Compliment (1’s Complement)
Reference Books
37




        Programming the 8086/86 for the IBM PC and Compatibles . Michael Thorne
        Microprocessors and Interfacing – Programming and Hardware – Douglas V.Hall
        Microsoft Macro Assembler – for the MS-DOS Operating Systems – Reference
         Manual

Más contenido relacionado

La actualidad más candente

Relationship Among Token, Lexeme & Pattern
Relationship Among Token, Lexeme & PatternRelationship Among Token, Lexeme & Pattern
Relationship Among Token, Lexeme & PatternBharat Rathore
 
Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086Shehrevar Davierwala
 
Error control coding bch, reed-solomon etc..
Error control coding   bch, reed-solomon etc..Error control coding   bch, reed-solomon etc..
Error control coding bch, reed-solomon etc..Madhumita Tamhane
 
Assembly language 8086
Assembly language 8086Assembly language 8086
Assembly language 8086John Cutajar
 
The 8051 microcontroller and embedded systems using assembly and c 2nd-ed
The 8051 microcontroller and embedded systems using assembly and c 2nd-edThe 8051 microcontroller and embedded systems using assembly and c 2nd-ed
The 8051 microcontroller and embedded systems using assembly and c 2nd-edĐinh Công Thiện Taydo University
 
Introduction to arm architecture
Introduction to arm architectureIntroduction to arm architecture
Introduction to arm architectureZakaria Gomaa
 
Logical instructions (and, or, xor, not, test)
Logical instructions (and, or, xor, not, test)Logical instructions (and, or, xor, not, test)
Logical instructions (and, or, xor, not, test)Irfan Anjum
 
7 convolutional codes
7 convolutional codes7 convolutional codes
7 convolutional codesVarun Raj
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...Bilal Amjad
 
Assembly language programming(unit 4)
Assembly language programming(unit 4)Assembly language programming(unit 4)
Assembly language programming(unit 4)Ashim Saha
 
8086 pin diagram description
8086 pin diagram description8086 pin diagram description
8086 pin diagram descriptionAkhil Singal
 
Half wavelength dipole antenna
Half wavelength dipole antennaHalf wavelength dipole antenna
Half wavelength dipole antennaAmit Kumar
 

La actualidad más candente (20)

Relationship Among Token, Lexeme & Pattern
Relationship Among Token, Lexeme & PatternRelationship Among Token, Lexeme & Pattern
Relationship Among Token, Lexeme & Pattern
 
Rs 232 interface
Rs 232 interfaceRs 232 interface
Rs 232 interface
 
Assemblers
AssemblersAssemblers
Assemblers
 
Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086Assembly language programming_fundamentals 8086
Assembly language programming_fundamentals 8086
 
Error control coding bch, reed-solomon etc..
Error control coding   bch, reed-solomon etc..Error control coding   bch, reed-solomon etc..
Error control coding bch, reed-solomon etc..
 
Assembly language 8086
Assembly language 8086Assembly language 8086
Assembly language 8086
 
The 8051 microcontroller and embedded systems using assembly and c 2nd-ed
The 8051 microcontroller and embedded systems using assembly and c 2nd-edThe 8051 microcontroller and embedded systems using assembly and c 2nd-ed
The 8051 microcontroller and embedded systems using assembly and c 2nd-ed
 
Introduction to arm architecture
Introduction to arm architectureIntroduction to arm architecture
Introduction to arm architecture
 
07 data linkcontrol
07 data linkcontrol07 data linkcontrol
07 data linkcontrol
 
Usp notes unit6-8
Usp notes unit6-8Usp notes unit6-8
Usp notes unit6-8
 
Microcontroller 8096
Microcontroller 8096Microcontroller 8096
Microcontroller 8096
 
Logical instructions (and, or, xor, not, test)
Logical instructions (and, or, xor, not, test)Logical instructions (and, or, xor, not, test)
Logical instructions (and, or, xor, not, test)
 
Program activation records
Program activation recordsProgram activation records
Program activation records
 
7 convolutional codes
7 convolutional codes7 convolutional codes
7 convolutional codes
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
 
Assembly language programming(unit 4)
Assembly language programming(unit 4)Assembly language programming(unit 4)
Assembly language programming(unit 4)
 
Chap 4
Chap 4Chap 4
Chap 4
 
8086 pin diagram description
8086 pin diagram description8086 pin diagram description
8086 pin diagram description
 
Half wavelength dipole antenna
Half wavelength dipole antennaHalf wavelength dipole antenna
Half wavelength dipole antenna
 
06. thumb instructions
06. thumb instructions06. thumb instructions
06. thumb instructions
 

Destacado

Chapter 3 INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMING
Chapter 3 INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMINGChapter 3 INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMING
Chapter 3 INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMINGFrankie Jones
 
Chp6 assembly language programming for pic copy
Chp6 assembly language programming for pic   copyChp6 assembly language programming for pic   copy
Chp6 assembly language programming for pic copymkazree
 
Microprocessor chapter 9 - assembly language programming
Microprocessor  chapter 9 - assembly language programmingMicroprocessor  chapter 9 - assembly language programming
Microprocessor chapter 9 - assembly language programmingWondeson Emeye
 
Assembly Language Lecture 5
Assembly Language Lecture 5Assembly Language Lecture 5
Assembly Language Lecture 5Motaz Saad
 
Computer instructions
Computer instructionsComputer instructions
Computer instructionsAnuj Modi
 
Assembly Language Programming Of 8085
Assembly Language Programming Of 8085Assembly Language Programming Of 8085
Assembly Language Programming Of 8085techbed
 
Bca 2nd sem-u-3.1-basic computer programming and micro programmed control
Bca 2nd sem-u-3.1-basic computer programming and micro programmed controlBca 2nd sem-u-3.1-basic computer programming and micro programmed control
Bca 2nd sem-u-3.1-basic computer programming and micro programmed controlRai University
 
How to resolve a Linear Programming Problem using Simplex Algorithm?
How to resolve a Linear Programming Problem using Simplex Algorithm?How to resolve a Linear Programming Problem using Simplex Algorithm?
How to resolve a Linear Programming Problem using Simplex Algorithm?Wilfried Mbouenda Mbogne
 
Coal 5 memory reading concepts in Assembly Programming
Coal 5 memory reading concepts in Assembly ProgrammingCoal 5 memory reading concepts in Assembly Programming
Coal 5 memory reading concepts in Assembly ProgrammingMuhammad Taqi Hassan Bukhari
 
Assembly language programming
Assembly language programming Assembly language programming
Assembly language programming Gaurav Takrani
 

Destacado (20)

Chapter 3 INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMING
Chapter 3 INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMINGChapter 3 INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMING
Chapter 3 INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMING
 
Assembly 8086
Assembly 8086Assembly 8086
Assembly 8086
 
8086 Architecture
8086 Architecture8086 Architecture
8086 Architecture
 
System design
System designSystem design
System design
 
Mpmc lab
Mpmc labMpmc lab
Mpmc lab
 
Chp6 assembly language programming for pic copy
Chp6 assembly language programming for pic   copyChp6 assembly language programming for pic   copy
Chp6 assembly language programming for pic copy
 
Microprocessor chapter 9 - assembly language programming
Microprocessor  chapter 9 - assembly language programmingMicroprocessor  chapter 9 - assembly language programming
Microprocessor chapter 9 - assembly language programming
 
Assembly Language Lecture 5
Assembly Language Lecture 5Assembly Language Lecture 5
Assembly Language Lecture 5
 
Computer instructions
Computer instructionsComputer instructions
Computer instructions
 
Assembly Language Programming Of 8085
Assembly Language Programming Of 8085Assembly Language Programming Of 8085
Assembly Language Programming Of 8085
 
Bca 2nd sem-u-3.1-basic computer programming and micro programmed control
Bca 2nd sem-u-3.1-basic computer programming and micro programmed controlBca 2nd sem-u-3.1-basic computer programming and micro programmed control
Bca 2nd sem-u-3.1-basic computer programming and micro programmed control
 
Algorithm & flow chart
Algorithm & flow chartAlgorithm & flow chart
Algorithm & flow chart
 
C++ Basics
C++ BasicsC++ Basics
C++ Basics
 
Microprocessor lecture 2
Microprocessor lecture   2Microprocessor lecture   2
Microprocessor lecture 2
 
Lecture5
Lecture5Lecture5
Lecture5
 
How to resolve a Linear Programming Problem using Simplex Algorithm?
How to resolve a Linear Programming Problem using Simplex Algorithm?How to resolve a Linear Programming Problem using Simplex Algorithm?
How to resolve a Linear Programming Problem using Simplex Algorithm?
 
Coal 5 memory reading concepts in Assembly Programming
Coal 5 memory reading concepts in Assembly ProgrammingCoal 5 memory reading concepts in Assembly Programming
Coal 5 memory reading concepts in Assembly Programming
 
Assembly language programming
Assembly language programming Assembly language programming
Assembly language programming
 
Microprocessor
MicroprocessorMicroprocessor
Microprocessor
 
Assembly
AssemblyAssembly
Assembly
 

Similar a Assembly language 8086 intermediate

instruction-set-of-8086-mr-binu-joy3.ppt
instruction-set-of-8086-mr-binu-joy3.pptinstruction-set-of-8086-mr-binu-joy3.ppt
instruction-set-of-8086-mr-binu-joy3.pptssuser2b759d
 
8086 instructions
8086 instructions8086 instructions
8086 instructionsRavi Anand
 
Chapter 6 Flow control Instructions
Chapter 6 Flow control InstructionsChapter 6 Flow control Instructions
Chapter 6 Flow control Instructionswarda aziz
 
Assembly language (Example with mapping from C++ to Assembly)
Assembly language (Example with mapping from C++ to Assembly)Assembly language (Example with mapping from C++ to Assembly)
Assembly language (Example with mapping from C++ to Assembly)Tish997
 
Microprocessor.pptx
Microprocessor.pptxMicroprocessor.pptx
Microprocessor.pptxNishatNishu5
 
Chap 3_2.ppt
Chap 3_2.pptChap 3_2.ppt
Chap 3_2.pptinian2
 
Loop instruction, controlling the flow of progam
Loop instruction, controlling the flow of progamLoop instruction, controlling the flow of progam
Loop instruction, controlling the flow of progamDr. Girish GS
 
Assembly Language Compiler Implementation
Assembly Language Compiler ImplementationAssembly Language Compiler Implementation
Assembly Language Compiler ImplementationRAVI TEJA KOMMA
 
8086 instruction set
8086 instruction set8086 instruction set
8086 instruction setmeenakshi_l
 

Similar a Assembly language 8086 intermediate (20)

instruction-set-of-8086-mr-binu-joy3.ppt
instruction-set-of-8086-mr-binu-joy3.pptinstruction-set-of-8086-mr-binu-joy3.ppt
instruction-set-of-8086-mr-binu-joy3.ppt
 
Assignment on alp
Assignment on alpAssignment on alp
Assignment on alp
 
Assignment on alp
Assignment on alpAssignment on alp
Assignment on alp
 
8086 instructions
8086 instructions8086 instructions
8086 instructions
 
Instruction set
Instruction setInstruction set
Instruction set
 
Arithmetic instrctions
Arithmetic instrctionsArithmetic instrctions
Arithmetic instrctions
 
Chapter 6 Flow control Instructions
Chapter 6 Flow control InstructionsChapter 6 Flow control Instructions
Chapter 6 Flow control Instructions
 
[ASM]Lab4
[ASM]Lab4[ASM]Lab4
[ASM]Lab4
 
Assembly language (Example with mapping from C++ to Assembly)
Assembly language (Example with mapping from C++ to Assembly)Assembly language (Example with mapping from C++ to Assembly)
Assembly language (Example with mapping from C++ to Assembly)
 
Microprocessor.pptx
Microprocessor.pptxMicroprocessor.pptx
Microprocessor.pptx
 
Chap 3_2.ppt
Chap 3_2.pptChap 3_2.ppt
Chap 3_2.ppt
 
Loop instruction, controlling the flow of progam
Loop instruction, controlling the flow of progamLoop instruction, controlling the flow of progam
Loop instruction, controlling the flow of progam
 
Assembly Language Compiler Implementation
Assembly Language Compiler ImplementationAssembly Language Compiler Implementation
Assembly Language Compiler Implementation
 
Chapter 3 programming concepts-ii
Chapter 3  programming concepts-iiChapter 3  programming concepts-ii
Chapter 3 programming concepts-ii
 
Instruction set of 8086 Microprocessor
Instruction set of 8086 Microprocessor Instruction set of 8086 Microprocessor
Instruction set of 8086 Microprocessor
 
Exp 03
Exp 03Exp 03
Exp 03
 
Alp 05
Alp 05Alp 05
Alp 05
 
Alp 05
Alp 05Alp 05
Alp 05
 
8086 instruction set
8086 instruction set8086 instruction set
8086 instruction set
 
8086 instruction set
8086 instruction set8086 instruction set
8086 instruction set
 

Más de John Cutajar

Más de John Cutajar (12)

Oop principles
Oop principlesOop principles
Oop principles
 
Module 5 2010
Module 5 2010Module 5 2010
Module 5 2010
 
System Design
System DesignSystem Design
System Design
 
Algorithms
AlgorithmsAlgorithms
Algorithms
 
SImple SQL
SImple SQLSImple SQL
SImple SQL
 
Relational Database Examples
Relational Database ExamplesRelational Database Examples
Relational Database Examples
 
Databases
DatabasesDatabases
Databases
 
Relational
RelationalRelational
Relational
 
Intermediate Operating Systems
Intermediate Operating SystemsIntermediate Operating Systems
Intermediate Operating Systems
 
The efficient postcode
The efficient postcodeThe efficient postcode
The efficient postcode
 
Intermediate machine architecture
Intermediate machine architectureIntermediate machine architecture
Intermediate machine architecture
 
Javanotes
JavanotesJavanotes
Javanotes
 

Último

Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 

Último (20)

Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 

Assembly language 8086 intermediate

  • 1. INTERMEDIATE 8086 ASSEMBLY LANGUAGE PROGRAMMING Cutajar & Cutajar © 2012
  • 2. Machine Code 2  There are occasions when the programmer must program at the machine’s own level.  Machine Code programs are tedious to write and highly error prone. 0000111100001111 In situations where a high-level 0010010101010100 language is inappropriate we 1010101010100101 avoid working in machine code most of the time by making the computer do more of the work. Thus we write in assembly language and then the computer converts this assembly language program into machine code.
  • 3. Assembly Language 3  In assembly language, a mneumonic (i.e. memory aid) is used as a short notation for the instruction to be used. Assembly Machine Code Language SUB AX,BX 001010111000011 MOV CX,AX 100010111001000 MOV DX,0 10111010000000000000000 Assembly language is an intermediate step between high level languages and machine code. Most features present in HLL are not present in Assembly Language as type checking etc.
  • 4. Compilers / Assemblers 4  High-level Languages such as Pascal Program Pascal programs are sometimes Compiler converted firstly to assembly language by a computer program Assembler language Program called compiler and then into machine code by another Assembler program called assembler Machine Code Program This version is actually loaded and executed
  • 5. General Purpose Registers 5 AH AL  There are 4 general purpose registers in AX the 8086. BH BL  They are all 16-bit registers  Each byte can be BX addressed individually CH CL by specifying the High order or the Low order byte of the register. CX DH DL DX
  • 6. Some Simple Commands 6  MOV AX,3 ; Put 3 into register AX  ADD AX,2 ; Add 2 to the contents of AX  MOV BX,AX ; Copy the contents of AX in BX  INC CX ; Add 1 to the contents of CX  DEC DX ; Subtract 1 from the contents of DX  SUB AX,4 ; Subtract 4 from the contents of AX  MUL BX ; Multiply the contents of AX with BX leaving ; the answer in DX-AX  DIV BX ; Divide the contents of DX-AX by BX leaving ; the quotient in AX and remainder in DX.
  • 7. Number Formats 7 AX AH AL MOV AH,01010101B 0 1 0 1 0 1 0 1 MOV AL,00100111B 0 1 0 1 0 1 0 1 0 0 1 0 0 1 1 1 MOV AX,3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 MOV AH,AL 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 1 MOV AL,10D 0 0 0 0 0 0 1 1 0 0 0 0 1 0 1 0 MOV AL,10H 0 0 0 0 0 0 1 1 0 0 0 1 0 0 0 0 In case a number is moved (copied) into the register the base of a is specified by a letter B for Binary, D for Decimal and H for Hex.
  • 8. AMBIGUITY 8  Consider the instruction MOV DL, AH  Does it mean ‘copy the contents of register AH to DL or  Does it mean ‘copy A in hexadecimal into register DL  To avoid this ambiguity all hexadecimal numbers must start with a number. This can always be done by preceding a number starting with A,B,C,D,E and F with a preceding zero to remove ambiguity.  Thus MOV DL, AH means copy AH to DL whilst  MOV DL, 0AH means sore hexadecimal A to DL
  • 9. The Flags Register 9  Some of the instructions (but not all) affect the flag register.  The flag register signals the status of the CPU after the last operation performed.  For example if SUB AX,2 results in zero the ZF get 1 (lights on) indicating that the result of the last operation was zero.
  • 10. JUMPS 10  Jump instructions allow the 8086 to take decisions according to information provided by the flag register.  For example, if AX and BX contain the ASCII code for the same letter then do one thing, if not then do another.  ` … CMP AX,BX ; Compares the contents of BX with that of AX JE SAME ; Jump if they are equal to the point ; in the code labeled SAME … ; Obey these instructions if the contents of AX … ; is not equal to that of BX SAME: MOV CX,AX ; Program continues from here if AX = BX. …
  • 11. Labels 11  We saw that the jump instruction has a general format JE <label> where <label> is a facility offered by the assembler.  These labels are converted by the assembler to exact address where the program is to continue.  Labels must start with a letter and can contain thereafter letters, numbers and underscores (_).  Spaces and punctuation marks are not permitted  Avoid using keywords in labels  Once_again, Next, Name34, this_37 are permitted as labels  3rdday, tues+wed and semi;colons are not permitted as labels.
  • 12. JUMP Conditions 12 JA/JNBE (CF and ZF) = 0 Above / Not Below or Equal JAE/JNB CF = 0 Above or Equal / Not Below JB/JNAE/JC CF = 1 Below / Not Above or Equal / Carry JBE/JNA (CF or ZF) = 1 Below or Equal / Not Above JE/JZ ZF = 1 Equal / Zero JMP none Unconditionally JNC CF = 0 No Carry JNE/JNZ ZF = 0 Not Equal / Not Zero JNO OF = 0 No Overflow JNP/JPO PF = 0 No Parity / Parity Odd JNS SF = 0 No Sign / Positive JO OF = 1 Overflow JP/JPE PF = 1 Parity / Parity Even JS SF = 1 Sign JG/JNLE ZF = 0 and SF = OF Greater / Not Less nor Equal JGE/JNL SF = OF Grater or Equal / Not Less JL / JNGE SF <> OF Less / Not Greater nor Equal JLE/JNG (ZF = 1) or (SF <> OF) Less or equal / not greater JCXZ Register CX = 0 CX is equal to zero
  • 13. Example using Jumps 13 MOV CX, AX ; Keep a copy of AX before modification SUB AX,BX ; AX := AX – BX JZ MAKE1 ; This is instruction will cause execution ; to continue from MAKE1 if AX was ; equal to BX (subtraction resulted in Zero) MOV DX, 0 ; Otherwise store 0 in DX JMP RESET ; Jump to RESTORE where AX is restored ; thus avoiding the next instruction MAKE1: MOV DX, 1 ; If AX = BX then we set DX to 1 RESET: MOV AX, CX ; Restore the old value of AX Note that in the Code a colon ends a label position
  • 14. The Logical Family 14 AND NOT (Invert: One’s Complement) Contents of AX = 0000101011100011 Contents of AX = 0000101011100011 Contents of BX = 1001100000100001 Contents of AX = 1111010100011100 Contents of AX = 0000100000100001 after NOT AX is executed after AND AX,BX is executed OR TEST Contents of AX = 0000101011100011 Contents of AX = 0000101011100011 Contents of BX = 1001100000100001 Contents of BX = 1001100000100001 Contents of AX = 1001101011100011 Contents of AX = 0000101011100011 after OR AX,BX is executed after TEST AX,BX is executed XOR Similar to AND but the result is not stored in AX Contents of AX = 0000101011100011 but only the Z-flag is changed Contents of BX = 1001100000100001 NEG (Two’s Complement) Contents of AX = 1001001011000010 Contents of AX = 0000101011100011 after XOR AX,BX is executed Contents of AX = 1111010100011101 after NEG AX is executed
  • 15. Use of Logical Family 15 Symbol ASCII (Dec) ASCII (Hex) By Making an AND between an ASCII value and 0FH 0 48 30 we can obtain the required number. 1 49 31 Say we AND 33H = 00110011B 2 50 32 with 0FH = 00001111B 3 51 33 We obtain = 00000011B (3) 4 52 34 5 53 35 By Making an OR between a number value and 30H we 6 54 36 can obtain its ASCII code. 7 55 37 Say we OR 05H = 00000101B 8 56 38 with 30H = 00110101B We obtain = 00110101B 9 57 39 (ASCII value for ‘5’)
  • 16. Masking 16 By the use of masking we can set or test individual bits of a register Suppose we want to set the 3rd. bit of AX to 1 leaving the others unchanged. Suppose we want to test the if the AX = 0101010100011001 6th. bit of AX is 1 or 0: 04H = 0000000000000100 AX = 0101010100011001 OR AX,04H = 0101010100011101 20H = 0000000000100000 AND AX,20H = 0000000000000000 Suppose we want to set the 5th. So if the result is 0 then that bit of AX to 0 leaving the particular bit was 0, 1 otherwise others unchanged. AX = 0101010100011001 0FFEFH = 1111111111101111 AND AX,0FFEFH = 0101010100001101
  • 17. Instructions which affect Memory 17  Computer memory is best thought of numbered pigeon holes (called locations), each capable of storing 8 binary digits (a byte) Data can be retrieved from memory, one or [0000] two bytes at a time: [0001] [0002] MOV AL, [20H] will transfer the [0003] Contents of location 20H to AL. [0004] [0005] MOV BX, [20H] will transfer the contents of [0006] [0007] locations 20H and 21H to BX. [0008] MOV [20H], AL will transfer the contents of [0009] [000A] AL to memory location 20H [000B] Location ADDRESS [000C] Location CONTENTS
  • 18. Changing addresses 18  Varying an address whilst a program is running involves specifying the locations concerned in a register.  From all the general purpose registers BX is the only capable of storing such addresses.  Thus MOV AX, [CX] is illegal  Whilst MOV CL, [BX] copies the contents of memory location whose address is specified by BX into the register CL.  And MOV [BX], AL copies the contents of AL in the memory location whose address is specified in BX
  • 19. Examples Affecting Memory 19  Consider the checkerboard memory test where a section of memory is filled with alternate 01010101 and 10101010.  The following program does the checkerboard test on locations 200H-300H inclusive. MOV BX,200H MOV AX,1010101001010101B NEXT: MOV [BX],AX INC BX CMP BX,300H JLE NEXT
  • 20. The Instruction Pointer (IP) 20  The computer keeps track of the next line to be executed by keeping its address in a special START . This is the register called the Instruction Pointer (IP) or line which is Program Counter. . . executing  This register is relative to CS as segment register and points to the next instruction to MOV AX,BX be executed. MOV CX,05H  The contents of this register is updated with MOV DX,AX IP every instruction executed. .  Thus a program is executed sequentially line . by line .
  • 21. The Stack 21  The Stack is a portion of memory which, like a stack of plates in a canteen, is organized on a Last- In-First-Out basis.  Thus the item which was put last on the stack is the first to be withdrawn
  • 22. The Stack Pointer 22 [0000] [0002]  The Stack pointer keeps track of the [0004] position of the last item placed on the [0006] [0008] stack (i.e. the Top Of Stack) [000A] [000C] SP [000E] [0010] [0012] [0014]  The Stack is organized in words, (i.e. two [0016] bytes at a time). Thus the stack pointer is [0018] incremented or decremented by 2. Note that on placing items on the  The Stack Pointer points to the last stack the address decreases occupied locations on the stack
  • 23. PUSH & POP 23 PUSH AX AX  The two set of instructions which [0000] [0002] [0004] explicitly modify the stack are the [0006] [0008] NEW SP PUSH (which places items on the OLD SP [000A] [000C] stack) and the POP (which [000E] [0010] retrieves items from the stack). In [0012] [0014] both cases, the stack pointer is [0016] [0018] adjusted accordingly to point POP AX always to the top of stack. [0000] AX [0002]  Thus PUSH AX means SP=SP-2 [0004] [0006] and AX -> [SP] [0008] [000A] OLD SP NEW SP [000C]  POP AX means [SP] -> AX and [000E] [0010] SP=SP+2. [0012] [0014] [0016] [0018]
  • 24. Subroutines 24  In high-level languages, procedures START SUB1 PROC . make it possible to break a large . . program down into smaller pieces so . . . RET that each piece can be shown to work independently. In this way the final CALL SUB1 program is built up of a number of . trusty bricks and is easier to debug . because the error is either localized to . one subprogram or its interlinking. This has also the advantage of re- usability of bricks.
  • 25. The CALL Mechanism 25  Although at first sight the CALL START SUB1 PROC and RET mechanism can be . . . implemented by using two JMP’s. . . In fact this cannot be done since . RET the CALL mechanism remembers CALL SUB1 the place where it was called from 1 . and returns to the line following it. . Thus this is not a fixed address. . CALL SUB1 . 2 . .
  • 26. The Return Mechanism 26  When a CALL is encountered the current value of the instruction pointer is pushed on the stack and the it is filled with the address stated by the call.  Since the fetch cycle goes to search for the instruction pointed at by the instruction pointer, the program continues it’s execution from the first statement in the subroutine.  On encountering the RET instruction the contents of the IP is popped from the stack thus continuing the execution where it was suspended.  Thus care must be taken to leave the return address intact before leaving a subroutine. (i.e. a symmetrical number of pushes and pops within the subroutine)
  • 27. Software Interrupts 27  Software interrupts are like hardware interrupts which are generated by the program itself. From the interrupt number, the CPU derives the address of the Interrupt service routine which must be executed.  Software interrupts in assembly language can be treated as calls to subroutines of other programs which are currently running on the computer.  One of the most famous software interrupt is Interrupt No. 21H, which branches in the operating system, and permits the use of PC-DOS functions defined there.  The function required to be performed by DOS is specified in AH prior to the the interrupt.  The functions return and accept values in various registers.  AN interrupt is called using the instruction INT followed by the interrupt number . For example: INT 21H
  • 28. Some INT 21H functions 28 Function Description Explanation Number 1 Keyboard Waits until a character is typed at the keyboard and then puts the ASCII Input code for that character in register AL and echoed to screen (echoed) 2 Display Prints the character whose ASCII code is in DL Output 8 Keyboard Waits until a character is typed at the keyboard and then puts the ASCII Input code for that character in register AL and NOT echoed to screen (No echo) 9 Display Prints a series of characters stored in memory starting with the one in the String address given in DX (relative to DS).Stop when the ASCII code for $ is encountered
  • 29. INT 21H Example 29 Prompt DB ‘Please enter 1 or 2: ‘,13D,10D,’$’ Song1 DB ‘So you think you can tell heaven from hell’ Song2 DB ‘Blue Sky is in pain’,13D,10D,’$’ ASK: MOV DX, OFFSET Prompt MOV AH,09H This is only a INT 21H program fragment to illustrate the use of GET: MOV AH,01H interrupt 21H – For INT 21H full details consult the MASM notes CMP AL,01H JE NEXT MOV DX, OFFSET Song1 MOV AH,09H INT 21H
  • 30. Addition and Subtraction with carry or 30 borrow  In assembly language there are two versions of addition and two versions of subtraction. CF CF  ADD - Simple addition of two numbers 0  ADC - Adds two numbers together with the carry flag 0  SUB – Simple subtraction of two numbers  SBB – Subtracts the second number and Last 0 1 1 the carry flag (borrow) addition in 00 01 98 41 +  This provides a means of adding numbers case of an 00 02 71 64 outgoing 00 04 70 05 greater than 32-bits. carry  CLC clears the carry for the first digit addition
  • 31. The Compare Instruction 31  The compare instruction does not change the contents of the registers involved but only sets the flag register accordingly.  The actual operation performed by the compare is a subtraction, leaving the source and destination registers intact  Consider CMP AX,BX : Flags are set according to the result of subtracting BX from AX:  If AX = BX then the ZF is set to 1  If AX > BX then the ZF is set to 0 and CF is set to 0 too  If AX < BX then we need an external borrow, which is reflected in CF = 1  These flags are tested in the ABOVE or BELOW jumps which test unsigned numbers  The GREATER and LESS jumps are for signed numbers and work on the SF, OF and the ZF instead
  • 32. Addressing Modes 32  The addressing modes deal with the source and destination of the data required by the instruction. This can be either a register or a location in memory, or even a port.  Various addressing modes exist:  Register Addressing  Immediate and Direct Addressing  Indirect Addressing  Indexed Addressing  Based Addressing  Based-Indexed Addressing Computer Logic II
  • 33. Register Addressing 33  This addressing mode General Purpose Segment Registers involves the contents of AX AH AL CS the register directly as BX BH BL DS for example: CX CH CL SS  MOV AX, BX DX DH DL ES  MOV CL, DL  Note that the IP and SI FLAGS Flags register cannot be DI IP accessed directly by the SP programmer BP AX BX Ex. MOV AX,BX
  • 34. Immediate and Direct Addressing 34  In Immediate addressing – for example Ex. MOV CL,61H MOV CL,61H – the immediate operand CL 61H 61H is stored as part of the instruction. Thus the number 61H is loaded directly in CL.  Direct addressing is similar except that in Ex. MOV AL,[210H] this case the effective address of one of the AL operands is taken directly from the instruction. Thus in MOV AL, [210H] the contents of location 210H relative to DS is put in AL (DS:210H) 75H
  • 35. Default Segment Register 35 Note that the default segment register can be changed using the segment override, i.e. stating the whole General Purpose address in the form DS: Offset AX AH AL BX BH BL Relative to DS by default CX CH CL DX DH DL NORMALLY FOR STRINGS SI Relative to DS by default DS DI Relative to DS by default ES SP Relative to SS by default BP Relative to SS by default IP Relative to CS by default
  • 36. Some other useful Instructions 36  CLC: Clear Carry Flag (CF = 0)  STC: Set Carry Flag (CF = 1)  CMC : Complement Carry Flag (CF = CF)  CBW: Convert Byte to Word  CWD: Convert Word to Double-Word  NEG: Negate (2’s Complement)  NOT: Compliment (1’s Complement)
  • 37. Reference Books 37  Programming the 8086/86 for the IBM PC and Compatibles . Michael Thorne  Microprocessors and Interfacing – Programming and Hardware – Douglas V.Hall  Microsoft Macro Assembler – for the MS-DOS Operating Systems – Reference Manual