26
M M SASIKANTH 2013A7PS101H GROUP NO:4 WEDNESDAY 2 PM - 4 PM Experiment - 1 ASM 1.1 Store two 8 bit numbers in CL and DL. Add them and save the result in CL ASM Program MOV CL,23H; MOV DL,46H; ADD CL,DL; INT 03H; Results CX = 0069 DX = 0046 Conclusion As we know format of MOV instruction is MOV destination , source and format of ADD instruction is ADD destination , source and the result of addition is stored in destination address or register. So in the above ASM we first stored 23H and 46H in CL and DL respectively using MOV instruction and after ADD instruction the result is stored in CX or CL depending on the numbers given to add in our case CL is sucient to store result that is 0069H. 1

Microp Lab 2

Embed Size (px)

DESCRIPTION

8086 processor

Citation preview

  • M M SASIKANTH 2013A7PS101H GROUP NO:4 WEDNESDAY 2 PM - 4 PM

    Experiment - 1 ASM 1.1 Store two 8 bit numbers in CL and DL. Add them and save the result in CL

    ASM Program

    MOV CL,23H;

    MOV DL,46H;

    ADD CL,DL;

    INT 03H;

    Results CX = 0069

    DX = 0046

    Conclusion As we know format of MOV instruction is MOV destination , source and format of ADD instruction is ADD destination , source and the result of addition is stored in destination address or register. So in the above ASM we first stored 23H and 46H in CL and DL respectively using MOV instruction and after ADD instruction the result is stored in CX or CL depending on the numbers given to add in our case CL is sucient to store result that is 0069H.

    1

  • ASM - 1.2 Store two 16 bit numbers in AX and BX. Add them and save result in AX

    ASM Program

    MOV AX,2345H

    MOV BX,4000H

    ADD AX,BX

    INT 03H

    Results AX = 6345

    BX = 4000

    Conclusion

    This is similar to first ASM the only dierences are here we are storing 16 bit numbers instead of 8 bit numbers in AX , BX the result is stored in AX , as the instruction is ADD AX , BX according to the values given that is 6345H

    2

  • ASM - 1.3 Store two 8 bit numbers in CL and DL. Subtract DL from CL and save result in CL

    ASM Program MOV CL,46H

    MOV DL,22H

    SUB CL,DL

    INT 03H

    Results CX = 0024

    DX = 0022

    Conclusion The format of SUB instruction is SUB destination , source , the source value is subtracted from destination and the result value is stored in destination , In our case as DL should be subtracted from CL and the result should be stored in CL we give instruction as SUB CL , DL as per given values after subtraction the result is stored in destination that is CX = 0024H

    3

  • ASM - 1.4 Store two 16 bit numbers in BX and CX. Subtract CX from BX and save result in AX

    ASM Program MOV BX,2345H

    MOV CX,0AAAAH

    SUB BX,CX

    MOV AX,BX

    INT 03H

    Results AX = 789B

    BX = 789B

    CX = AAAA

    Conclusion This is similar to 8 bit subtraction here the numbers are 16 bits and stored in BX , CX after subtraction results should be stored in AX . As we subtract CX from BX the result is stored in BX but we need the result to be in AX so we use MOV instruction to transfer the value in BX to AX. So according to given values the result is 789B stored in BX and after MOV instruction AX value also becomes 789B

    4

  • ASM - 1.5 Store two 8 bit numbers in AL and BL. Multiply AL and BL and save result in AX.

    ASM Program MOV AL,22H

    MOV BL,09H

    MUL BL

    INT 03H

    Results AX = 0132

    Conclusion Here we need to multiply two 8 bit numbers. The format of MUL instruction is MUL multiplier, the multiplier is multiplied by AL or AX or EAX depending on the multiplier. Here multiplier is BL so it is multiplied with the value in AL as we are multiplying two 8 bit numbers we can get maximum 16 bits result it is stored in AX that is 0132H in our case.

    5

  • ASM - 1.6 Store two 16 bit numbers in AX and BX. Multiply AX and BX and save result in CX and DX.

    ASM Program MOV BX,1234H

    MOV AX,4321H

    MUL BX

    MOV CX,AX

    INT 03H

    Results AX = F4B4

    BX = 1234

    CX = F4B4

    DX = 04C5

    Conclusion Here we are multiplying two 16 bit numbers in AX , BX. When we multiply two 16 bit numbers we can get maximum 32 bit number. The lower 16 bits are stored in AX and higher 16 bits are stored in DX. According to the question we need lower 16 bits in CX so we use MOV instruction to transfer higher 16 bit value in AX to CX. Therefore the final value in our case is CX = F4B4H the lower 16 bits and DX = 0465H the higher 16 bits.

    6

  • ASM - 1.7 Store two 8 bit numbers in AL and BL. Divide AL by BL and save results in registers of your choice.

    ASM Program

    MOV AL,24H

    MOV BL,06H

    DIV BL

    INT 03H

    Results AX = 0006H

    BX = 0006H

    Remainder = 00H

    Quotient = 06H

    Conclusion The format of DIV instruction is DIV source this divides Axor DX-AX by the source where source can be register or memory location. In this case we divide a word by a byte that is DIV BL that divides AX by the byte in BL quotient is stored in AL and remainder is stored in AH.

    7

  • ASM - 1.8 Store two 16 bit numbers in AX and BX. Divide AX by BX and save result in registers of your choice

    ASM Program MOV AX,0210H

    MOV BX,0020H

    MOV DX,0000H

    DIV BX

    INT 03H

    Results AX = 0010H

    BX = 0020H

    DX = 0010H

    Remainder = 0010H

    Quotient = 0010H

    Conclusion This is similar to 8 bit division but here we use DIV BX that is divides the double word in DX-AX by the word in BX. The quotient is stored in AX and remainder is stored in DX.

    8

  • Experiment - 2 ASM 2 An array of N words is stored in a data segment as an array. The count of words N is also stored as a byte. Compute the average of the N numbers and store the result in memory at location Average

    Process: Compute average of N numbers.Input: N=number of words. Ary: list of numbers

    Output: Average

    ASM Program MOV AX,0000H

    MOV SI,3000H

    MOV CX,[5000H]

    MOV BX,CX

    CLC

    X1: ADC AX,[SI]

    INC SI

    INC SI

    DEC CX

    JNZ X1

    DIV BX

    INT 03H

    Results Number of words = 4;

    Words = 0010H, 0020H, 0030H, 0040H

    Average = 0028H

    9

  • Conclusion Here we need to take array of words and find their average so first we start array at address 3000H we take all the words whose average should be found and also the count of number of words in CX at address 5000H. We write a loop to repeat CX times in that we add the value in the address [SI] to AX and SI is increased to point next word, CX is decreased when CX is equal to ZERO the loop stops and the value in AX is divided by BX which is the count of number of words. The result quotient is stored in AX and remainder is stored in DX

    ASM 3 We have to find the approximate Fahrenheit temperature for a given Celsius value. The Fahrenheit temperature is store in fixed point format in two bytes. The input Centigrade temp is 0 to 100 degrees. Using a lookup table method to convert the Celsius to Fahrenheit .

    Process: Convert Celsius value to Fahrenheit

    Input: Celsius value as byteOutput: Fahrenheit as two bytes.(Ex: C=120C F=53.610 Byte 1= (35h) Byte 2=(99h))

    10

  • ASM Program MOV AX,0000H

    MOV AL,[5000H]

    MOV BX,4000H

    XLATB

    INT 03H

    Results LooK up Table

    4000 - 0020H

    4005 - 0029H

    4010 - 0032H

    4015 - 003BH

    4020 - 0044H

    Conclusion Here we use XLATB and a lookup table first we enter the fahrenheit value corresponding to the oset value considered as celsius value now in our program we use XLATB which goes to this lookup table and sees the

    11

  • corresponding oset value address to find fahrenheit value and sets AL to this value.

    Experiment - 3 ASM 4 Sort an array of 16 bit signed binary numbers so that they are arranged in ascending order.

    Process: Sort the signed numbers in the ary.

    Input: N=count.

    Ary: list of numbers

    Output: ordered numbers in ary

    ASM Program MOV DX, 0005H

    X3: MOV SI, 4000H

    MOV CX, DX

    DEC DX

    JZ X4

    X1: MOV AX, [SI]

    MOV BX, [SI+2]

    CMP AX,BX

    JL X2

    XCHG AX, [SI+2]

    XCHG AX, [SI]

    X2: INC SI

    INC SI

    DEC CX

    JNZ X1

    JZ X3

    X4: INT 03H

    Results Array is 0009H, 0001H, 0006H, 0004H, 0002H at address starting from 4000H

    12

  • Sorted array is 0001H, 0002H, 0004H, 0006H, 0009H

    Conclusion Here we use the Bubble sort technique to sort the array of binary numbers in ascending order we compare every element with the numbers in the array next to it if the number is smaller than the number with which we are

    13

  • comparing we exchange the numbers pointers. Like this in every loop execution the largest value is in the last of Array. So looping the array by the number of elements in array all the elements will be sorted.

    ASM 5 A company makes several parts. Each part is coded as below. The code is 16 bit width with 4 bits for model umber and 4 bits for part number and 8 bits for serial number. Find the total number of items with part number = 5.

    Process: Count the items with part no=5Input: N=item count; list: list of item codes in an array

    Output: CX=count of items with part no=5

    ASM Program MOV DX, 0005H

    MOV CX, 0000H

    MOV BX, [5000H]

    MOV SI,4000H

    X1: MOV AX, [SI]

    AND AH, 0FH

    CMP AH,DL

    JE X2

    X3: INC SI

    INC SI

    DEC BX

    JNZ X1

    INT 03H

    X2: INC CX

    JNZ X3

    14

  • Results Item Count = 5

    Item Codes = 45ABH, 32CDH, 55E5H, A5B2H, BFFFH at address 4000H

    Number of items with Part number = 5 equal to CX = 0003H

    Conclusion Here we iterate through every element and first copy the value into AX now we mash AH with 0FH by doing an AND operation with AH and 0FH so by doing AND with 0FH we get the part number in AH now we increment CX if the part value AH is equal to 5. By performing this loop for every element we get the count of number of Codes with part number equal to 5.

    Experiment - 4 ASM 6 Write a program to reverse the given string and store at the same location. No additional memory is to be used.

    Process: Reverse the string stored at str1

    Input: str1= stringOutput: Reversed string at location str1

    15

  • ASM Program MOV SI,4000H

    MOV CX,[5000H]

    DEC CX

    MOV DI,SI

    ADD DI,CX

    X1: MOV AL,[SI]

    MOV BL,[DI]

    MOV [SI],BL

    MOV [DI],AL

    INC SI

    DEC DI

    CMP SI,DI

    JL X1

    INT 03H

    Results Given String at address 4000H is 45AB 32CD 55E5 A5B2 BFFF

    Reversed String FF BF B2 A5 E5 55 CD 32 AB 45

    Conclusion Here we swap first and last word and then second and last but one word and so on.. by doing this the half times the number of words in string we reverse the string

    16

  • ASM 7 Write a program using the LOOP instruction with indirect addressing that copies a string from source to target, reversing the character order in the process.

    Use the following variables:

    source BYTE "This is the source string"

    target BYTE SIZEOF source DUP('#')

    ASM Program MOV SI,4000H

    MOV DI,5000H

    MOV CX,[6000H]

    DEC CX

    ADD DI,CX

    INC CX

    X1 :CLD

    LODSB

    STD

    STOSB

    LOOP X1

    INT 03H

    Results Input string at address 4000H is FF BF B2 A5 E5 55 CD 32 AB 45

    Output string at address 5000H is 45 AB 32 CD 55 E5 A5 B2 BF FF

    17

  • Conclusion Here first we go to the end of the source string and start copying from there to the destination string address by executing this loop the number of times of length of string the loop will be reversed and stored in destination address.

    Experiment - 5 INT-1 Press the KB INT key on your kit for some time and release. The kit has to display on the LCD panel the number of seconds you kept the key pressed. Use the interrupt provided with this key and develop the program.

    ASM Program

    Interrupt program

    MOV BX, 0000H

    MOV SI, 0008H

    MOV AX, 3000H

    MOV [SI],AX

    MOV SI, 000AH

    MOV AX, 0000H

    MOV [SI],AX

    MOV CX, 0000H

    MOV SI, 0000H

    HERE:

    CMP CX, 0000H

    JE HERE

    CALL DEBOUNCE

    MOV CX, 0000H

    MOV AX, 0000H

    MOV ES, AX

    MOV AX, 4000H

    CALL 0FE00H:0013H

    JMP COUNT

    DEBOUNCE:

    18

  • LOOP DEBOUNCE

    RET

    COUNT:

    CMP CX, 0000H

    JNE DOWN

    INC BX

    CMP BX, 0FFFFH

    JNE DOWN1

    INC SI

    MOV BX,0000H

    DOWN1:

    JMP COUNT

    DOWN:

    MOV AX, 0000H

    MOV ES, AX

    MOV AX,5000H

    CALL 0FE00H:0013H

    INT 03H

    ISR program

    MOV CX,0FFFH

    IRET

    Conclusion Here we use interrupts and interrupt service routines to record the time we kept the key pressed we store it in BX there are two cases when the time limit exceeds the maximum value in BX it again goes to 0000H and starts to increase again for every second

    Results

    Case(1) SI: 0004H

    BX:0086H (Normal time)

    Case(2) SI: 0000H

    BX:1AB7H (less time)

    Case(3) SI:0013H

    BX:82EDH(more time than limit of BX)

    19

  • Experiment - 6 The speed of a stepper motor has to be controlled by KBINT key. The motor starts when KBINT is pressed and speed increases gradually to maximum when key is pressed. When the key is released speed comes down to zero gradually. Set the speed, maximum limits as per your choice.

    20

  • ASMProgram

    ORG 2000HMOV SI, 0008HMOV AX, 3000HMOV [SI], AXMOV SI, 000AHMOV AX, 0000HMOV [SI], AXMOV AX, 0000HMOV ES, AXMOV DX, 0FFE6HMOV AL, 80HOUT DX, ALMOV CX, 0HMOV BX, 0000HMOV DI, 0810HMOV AL, 11HMOV DX, 0FFE0HR1: OUT DX, AL CALL DELAY ROL AL, 1H JMP R1DELAY: CMP BL, 01H

    JNE DOWN1 MOV BL, 00H CALL DEBOUNCE CMP DI, 0400H JL INCR CMP DI, 0D00H JG DECR JMP COMP

    INCR: MOV BH, 00H JMP COMP

    21

  • DECR: MOV BH, 01HCOMP: CMP BH, 00H JE AD SUB DI, 0100H JMP DOWN1AD: ADD DI, 0100HDOWN1: MOV CX, DIHERE: LOOP HERE RETDEBOUNCE: MOV CX, 0FFFHDEBOUNCE1: LOOP DEBOUNCE1 RET

    ISR program

    MOV BL, 01H

    IRET

    Result Here we observe that when we press KBINT the stepper motor speed increases.

    Conclusion Here we use interrupts and interrupt service routine to control the speed of Stepper motor.

    22

  • Experiment - 7 Design a system to control trac lights. The trac light should be controlled in such a way that

    It will allow the trac from west to east and east to west transition for

    some fixed delay.

    It will allow the trac from north to south and south to north for some

    fixed delay.

    Repeat the process.

    ASMProgram

    ORG 2000H

    START: MOV AL, 80H

    MOV DX,0FFE6H

    OUT DX,AL

    AGAIN: MOV BX,3000H

    NEXTST: MOV AL,[BX]

    MOV DX,0FFE0H

    OUT DX,AL

    INC BX

    ADD DX,2

    MOV AL,[BX]

    OUT DX,AL

    INC BX

    ADD DX,2

    MOV AL,[BX]

    OUT DX,AL

    INC BX

    CALL DELAY

    MOV AL,[BX]

    CMP AL,00H

    JNZ NEXTST

    JMP AGAIN

    DELAY: MOV CX,0FFFH

    DLY5: PUSH CX

    23

  • MOV CX,03FFH

    DLY10: NOP

    LOOP DLY10

    POP CX

    LOOP DLY5

    RET

    Results At address 3000H 18H, 18H, 0A5H at stage 1

    and 81H, 81H, 5BH, 00H at stage 2

    Conclusion First we initialize 8255 to Mode - 0 and make all ports to output and set the values of ports to the signals according to which we needed in the address 3000H as per our program we also write a subroutine for using delay between changing the color of lights of trac controller.Here we see a real life scenario i.e trac lights controlling

    Experiment - 8 Seven segment display.

    ASMProgram

    MOV DX, 0FFE6H

    MOV AL,80H

    OUT DX,AL

    MOV SI,3000H

    MOV CL,04H

    LOOP2: MOV BL,08H

    MOV AL,[SI]

    INC SI

    LOOP1: ROL AL,1

    MOV DX,0FFE2H

    OUT DX,AL

    24

  • MOV AH,AL

    MOV AL,01H

    MOV DX,0FFE4H

    OUT DX,AL

    DEC AL

    OUT DX,AL

    MOV AL,AH

    DEC BL

    JNZ LOOP1

    DEC CL

    JNZ LOOP2

    INT 03H

    Results S 3000 - 83

    S 3001 - 8C

    S 3002 - 8B

    S 3003 - C6

    Displays BPHC

    S 3000 - 82

    S 3001 - C0

    S 3002 - 88

    S 3003 - 87

    Displays GOAT

    S 3000 - 82

    S 3001 - C0

    S 3002 - A1

    S 3003 - 92

    Displays GODS

    Conclusion Here first we initialize 8255 and give the values we want to display to a, b, c, d, e ,f ,g in active low mode so we need to give 0 to display LED This helps us to interface 8255 with Seven segment display

    25

  • 26