Microprocessor Programming (Code :- 314321)

 ---------------×------------------××--------------------×---------------

MICROPROCESSOR PROGRAMMING (314321)

---------------×------------------××--------------------×---------------

Microprocessor Programming (Code :- 314321)
Microprocessor Programming (Code :- 314321) 

---------------×------------------××--------------------×---------------

Unit 1 :- 8086 16-bit Microprocessor

Unit 2 :- The Art of assembly Language Programming 

Unit 3 :- Instruction Set of 8086 Microprocessor

Unit 4 :- 8086 Assembly Language Programming

Unit 5 :- Procedure and Macro in Assembly Language Program 

---------------×------------------××--------------------×---------------

Some Notes on 8086 Microprocessor 

BHE :- Bus High Enable it is available at pin 34. It is used to indicate transfer of data bus D8 to D15. This signal is low active during first clock cycle and thereafter it becomes active.

ALE :- ALE stands for address latch enable as address and data bus both are multiplexed, ALE is used to lock either address or data.

The fetching of next instruction while current instruction is being executed is known as Pipelining. Pipelining as become possible due to because of queue. BIU (Bus interface unit ) starts filling the queue until the entire queue is full. BIU restarts the filling queue when at least last two places are vacant.

Ready is used as acknowledgement signal from slower I/O device. When device is ready to transfer data then Ready is Active High signal. It is available at pin 22.

The Single Stepping or Tracing is done using Trap Flag Register. Trap Flag Register is also known as Control Flag Register. When TF=1 then Processor perform Single step i.e. it execute single line. Single Step mode is known as Executing a one line at a time. 

Debugger is program is extension of single step mode under the user control.

8086 supports memory segmentation. 8086 supports pipelining method. So it will increase the speed of execution of program. 

Ready : It is used as acknowledgement from slower I/O device or memory. It is Active high signal, when high; it indicates that the peripheral device is ready to transfer data. 

INTR :- This is a level triggered interrupt request input, checked during last clock cycle of each instruction to determine the availability of request. If any interrupt request is occurred, the processor enters the interrupt acknowledge cycle.


Flag register of 8086 

• Carry Flag :-  It is set when the carry / borrow is generated out of MSB of result (i.e. D7 for 8-bit 
operation and D15 for 16-bit operation ). Carry flag shows status of carry. When CF =0 then No 
carry generated and when CF =1 then carry is generated of MSB. Carry flag (CF) is at D0 . 

• Parity Flag :- It is set to 1 if the lower byte of result contains even number of 1’s otherwise it is 
set to reset i.e. 0. Parity Flag (PF) is at D2 . When PF=0 then Odd Parity and when PF=1 then Even 
Parity. 

• Auxiliary Flag :- It is set to 1 if the carry generated from lower nibble to higher nibble otherwise 
it is reset i.e. 0. Auxiliary Flag (AF) is at D4 . It is applicable at 8-bit instructions. 

• Zero Flag :- It is set to 1 if the result after performing ALU operations is zero otherwise it is reset. 
Zero Flag (ZF) is available at D6 .  

• Sign Flag :- It is set to 1 if the MSB of the result is 1 otherwise it is reset. Sign Flag is available at 
D7 . If SF=1 then it indicates that number is negative and SF=0 then it indicates that number is 
positive. It is applicable for signed operations.  

Practical Programs :- 

Write a program to perform addition of two 8 bit numbers 

include 'emu8086.inc'

.model small

.data

    num db 12h

.code

    mov ax,@data

    mov ds,ax

    mov al,num

    mov ah,13h

    add ah,al 

    mov ah,4CH

    INT 21h  

ENDS


Write an ALP to perform addition of two 16 bit numbers.

include 'emu8086.inc'

.model small

.data

    num1 dw 6753h

    num2 dw 2020h

    sum dw ?

.code

    mov ax,@data

    mov ds,ax

    mov ax,num1

    mov bx,num2

    add ax,bx

    mov sum,ax

    mov ah,4ch

    int 21h

 ends



Write an ALP to perform subtraction of two 8 bit numbers.

include 'emu8086.inc'

.model small

.data

    a db 52h

    b db 12h

    c db ?

.code

    mov ax,@data

    mov ds,ax

    mov al,a

    mov bl,b

    sub al,bl

    mov c,al

    mov ah,4ch

    int 21h

ends



Write an ALP to perform subtraction of two 16 bit numbers.

include 'emu8086.inc'

.model small

.data

    a dw 0081h

    b dw 0011h

    c dw ?

.code

    mov ax,@data

    mov ds,ax

    mov ax,a

    mov bx,b

    sub ax,bx

    mov c,ax

    mov ah,4ch

    int 21h

ends



Write an ALP to perform multiplication of two 8 bit numbers.

include 'emu8086.inc'

.model small

.data

    a db 02h

    b db 03h

    c dw ?

.code

    mov ax,@data

    mov ds,ax

    mov al,a

    mov bl,b

    mul bl

    mov c,ax

    mov ah,4ch

    int 21h

ends



1.     1. ALP to perform addition and subtraction of two given numbers.

include 'emu8086.inc'

.model small

.data

    a db 01h

    b db 02h

    c db 03h

    d db 04h 

    e db ?

    f db ?

.code

    mov ax,@data

    mov ds,ax

    mov al,a

    mov bl,b

    add al,bl

    mov e,al

    mov al,d

    mov bl,c

    sub al,bl

    mov f,al

    mov ah,4ch

    int 21h

ends

 

2.     2. ALP to find largest and smallest number from array of numbers.

include 'emu8086'

.model small

.stack 100h

.data

    ARRAY DB 15H,45H,08H,56H,78H

    LARGEST DB 00H

    small db 00h

.code

    MOV DX,DATA

    MOV DS,DX

    MOV CX,04H

    MOV SI,OFFSET ARRAY

    MOV AL,[SI]

   

    smallest:

    UP1: INC SI

    CMP AL,[SI]

    JC NEXT1

    MOV AL,[SI]

    NEXT1: DEC CX

          JNZ UP1

          MOV SMALL,AL

               

    MOV CX,04H

    MOV DI,OFFSET ARRAY

    MOV AL,[DI]

   

    Large:   

    UP: INC DI

    CMP AL,[DI]

    JNC NEXT

    MOV AL,[DI]

    NEXT: DEC CX

    JNZ UP

    MOV LARGEST,AL

    INT 21H

ENDS

3.     

        3. ALP to find the length of string and concatenate two strings.

include 'emu8086.inc'

.model small

.data

    msg db 'computer$'

    count db ? 

    str1 db 'hello$'

    str2 db 'world$'

   

.code

    mov ax,@data

    mov ds,ax 

   

    length:

    mov si,offset msg

    next1:

        mov al,[si]

        cmp al,'$'

        je exit2

            inc count

            inc si

            jmp next1

    exit2:

        mov dh,count 

       

    concat:

        mov si,offset str1

        next:

            mov al,[si]

            cmp al,'$'

            je exit:

            inc si

            jmp next

        exit:

            mov di,offset str2

        up:

            mov al,[di]

            cmp al,'$'

            je exit1

            mov [si],al

            inc si

            inc di

            jmp up

        exit1:

            mov al,'$'

            mov [si],al

   

        mov ah,4ch

        int 21h

ends

 

4.     4. ALP to check a given number is odd or even

; Program to find number is odd or even

include 'emu8086.inc'

.MODEL SMALL

.STACK 100H

.DATA

    MSG1 DB "ODD$"

    MSG2 DB "EVEN$"

    NUM DB ?

 

.CODE

   MOV AX , @DATA 

   MOV DS , AX

 

   MOV AH , 1h     

   INT 21H

   MOV NUM , AL   

 

   ROR AL , 1     

   JC EL          

    LEA DX , MSG2 

    JMP EXIT      

 EL:

    LEA DX , MSG1 

 

EXIT:

   MOV AH , 09H   

   INT 21H

 

   MOV AH , 4CH   

   INT 21H

ENDS

 

5.    5. ALP for multiplication of two signed and unsigned numbers.

include 'emu8086.inc'

.model small

.data

    a db 02h

    b db 04h

    c db -03h

    d db -05h

    sign dw ?

    unsign dw ?

.code

    mov ax,@data

    mov ds,ax

    mov al,a

    mov bl,b

    mul bl

    mov unsign,ax

    mov al,d

    mov bl,c

    imul bl

    mov sign,ax

    mov ah,4ch

    int 21h

end

ends

 

 

6.     6. ALP to perform division of two unsigned and signed numbers.

include 'emu8086.inc'

.model small

.data

    unsign db ?

    sign db ?

.code

    mov ax,@data

    mov ds,ax

   

    mov ax,203

    mov bl,4

    div bl

    mov unsign,al

            

    mov ax,-203

    mov bl,4

    idiv bl

    mov sign,al

   

    mov ah,4ch

    int 21h

end

ends

 

7.     7. ALP to find sum of series.

include 'emu8086.inc'

.model small

.data

    a db 1,2,3,4,5,6,7,8,9,10

    sum db ?

.code

   

        mov ax,data

        mov ds,ax

        mov cl,10

        lea bx,a

        mov ah,00

        mov al,00 

       

    l1:

        add al,byte ptr[bx]

        inc bx

        dec cl

        cmp cl,00

        jnz l1

        mov sum,al

        mov ah,4ch

        int 21h

end

ends

 

 

8.     8. ALP for string operations such as string reverse and string copy.

include 'emu8086.inc'

.model small

.data

    STRING DB "STUPID$"

    ARR DB 10 DUP('$')

    destination DB 20 DUP(0)

.code

    MOV DX,@DATA

    MOV DS,DX

   

   

copystring:

    LEA SI,STRING

    LEA DI,destination

    mov cx,7

    mov al,0

    copyloop:

        mov al,[si]

        mov [di],al

        inc si

        inc di

        dec cx

        cmp cx,0

        jnz copyloop

        mov ah,09h

        lea dx,destination

   

reversestring:

    MOV CL,00H

    LEA SI,STRING

    MOV BL,'$'

AGAIN: MOV AL,[SI]

       CMP AL,BL

       JZ REVERSE

       INC CL

       INC SI

       JMP AGAIN

REVERSE: LEA DI,ARR

         DEC SI

UP: MOV AL,[SI]

    MOV [DI],AL

    INC DI

    DEC SI

    LOOP UP

    MOV [DI],'$'

    LEA DX,ARR

    MOV AH,09H

    INT 21H

    MOV AH,4CH

    INT 21H

end

ends

 

 

9.     9. ALP to check a given number is odd or even

include 'emu8086.inc'

.MODEL SMALL

.STACK 100H

.DATA

    MSG1 DB "ODD$"

    MSG2 DB "EVEN$"

    NUM DB ?

 

.CODE

   MOV AX , @DATA 

   MOV DS , AX

 

   MOV AH , 1h     

   INT 21H

   MOV NUM , AL   

   ROR AL , 1     

   JC EL          

    LEA DX , MSG2 

    JMP EXIT      

 EL:

    LEA DX , MSG1 

 

EXIT:

   MOV AH , 09H   

   INT 21H

   MOV AH , 4CH   

   INT 21H

ENDS

 

10  10ALP to perform arithmetic operations on given numbers using procedure                     Z=(A+B)*(C+D)

include 'emu8086.inc'

.MODEL SMALL

.STACK 100H

.DATA

   A DB 2

   B DB 2

   C DB 4

   D DB 4

   Z DW ?

   RES DB ?

.CODE

  MOV AX , @DATA

  MOV DS , AX

 

  MOV AL , A

  MOV AH , B

 

  CALL ADD_BYTE

  MOV RES , AL   ; STORING RESULT OF A+B

 

  MOV AL , C

  MOV AH , D

 

  CALL ADD_BYTE

  MOV BL , RES

 

  MUL BL

  AAM          ; ASCII ADJUST AFTER MULTIPLICATION

 

  MOV Z , AX

 

  ; PRINTING RESULT

  MOV BH , AL

  MOV DL , AH   

  ADD DL , 48

  MOV AH , 02

  INT 21H

 

  MOV DH , 00

  MOV DL , BH

  ADD DL , 48

  MOV AH , 02

  INT 21H

 

 MOV AH , 4CH  ; Service Routine for exit

 INT 21H

 

  ; Creating Procedure

  ADD_BYTE PROC

     ADD AL , AH

     RET

  ENDP

END

 

11   11. ALP to perform arithmetic operations on given numbers using macro for equation    P=(X2+Y2)

.MODEL SMALL

PROG MACRO a,b

    MOV al,a

    MUL al

    MOV bl,al

    MOV al,b

    MUL al

    ADD al,bl

ENDM

.DATA

    x DB 02H

    y DB 03H

    p DB ?

.CODE  

    MOV ax,data

    MOV ds,ax

    PROG x, y

    MOV p,al

    MOV ah,4Ch

    int 21H

END

 


---------------×------------------××--------------------×---------------


---------------×------------------××--------------------×---------------

Post a Comment

2 Comments

Hi, Viewers Do not Enter Spam Messages in comments