Sunteți pe pagina 1din 95

Geethanjali College of Engineering and Technology

Cheeryal (v), Keesara (M), Ranga Reddy District.

MICROPROCESSORS AND INTERFACING LAB


I. Microprocessor 8086 :1. Introduction to TASM. 2. Arithmetic operation Multi byte Addition and Subtraction, Multiplication and Division Signed and unsigned Arithmetic operation, ASCII arithmetic operation. 3. Logic operations Shift and rotate Converting packed BCD to unpacked BCD, BCD to ASCII conversion. 4. By using string operation and Instruction prefix: Move Block, Reverse string, Sorting, Inserting, Deleting, Length of the string, String comparison. 5. DOS/BIOS programming: Reading keyboard (Buffered with and without echo) Display characters, Strings.

II. Interfacing :1. 8259 Interrupt Controller : Generate an interrupt using 8259 timer. 2. 8279 Keyboard Display : Write a small program to display a string of characters. 3. 8255 PPI : Write ALP to generate sinusoidal wave using PPI. 4. 8251 USART : Write a program in ALP to establish Communication between two processors.

III. Microcontroller 8051:1. Reading and Writing on a parallel port. 2. Timer in different modes. 3. Serial communication implementation. Equipment required for Laboratories:1. 8086 P Kits 2. 8051 Micro Controller kits 3. Interfaces/peripheral subsystems i) 8259 PIC ii) 8279-KB/Display iii) 8255 PPI iv) 8251 USART 4. ADC Interface 5. DAC Interface 6. Traffic Controller Interface 7. Elevator Interface

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

INTRODUCTION TO TASM EDITOR:


An editor is a program, which allows you to create a file containing the assembly language statements for your program. As you type in your program, the editor stores the ASCII codes for the letters and numbers in successive RAM locations. When you have typed in all of your programs, you then save the file on a floppy of hard disk. This file is called source file. The next step is to process the source file with an assembler. In the TASM assembler, you should give your source file name the extension, .ASM

ASSEMBLER:
An assembler program is used to translate the assembly language mnemonics for instructions to the corresponding binary codes. When you run the assembler, it reads the source file of your program the disk, where you saved it after editing on the first pass through the source program the assembler determines the displacement of named data items, the offset of labels and pails this information in a symbol table. On the second pass through the source program, the assembler produces the binary code for each instruction and inserts the offset etc that is calculated during the first pass. The assembler generates two files on floppy or hard disk. The first file called the object file is given the extension. OBJ. The object file contains the binary codes for the instructions and information about the addresses of the instructions. The second file generated by the assembler is called assembler list file. The list file contains your assembly language statements, the binary codes for each instructions and the offset for each instruction. In TASM assembler, TASM source file name ASM is used to assemble the file. Edit source file name LST is used to view the list file, which is generated, when you assemble the file.

LINKER:
A linker is a program used to join several object files into one large object file and convert to an exe file. The linker produces a link file, which contains the binary codes for all the combined modules. The linker however doesnt assign absolute addresses to the program, it assigns is said to be relocatable because it can be put anywhere in memory to be run. In TASM, TLINK source filename is used to link the file.

DEBUGGER:
A debugger is a program which allows you to load your object code program into system memory, execute the program and troubleshoot are debug it the debugger allows you to look at the contents of registers and memory locations after your program runs. It allows you to change the contents of register and memory locations and return the program. A debugger also allows you to set a break point at any point in the program. If you inset a breakpoint the debugger will run the program upto the instruction where the breakpoint is set and stop execution. You can then examine register and memory contents to see whether the results are correct at that point. In TASM, td

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

filename is issued to debug the file.

DEBUGGER FUNCTIONS:
1. 2. 3. 4. Debugger allows to look at the contents of registers and memory locations. We can extend 8-bit register to 16-bit register which the help of extended register option. Debugger allows to set breakpoints at any point with the program. The debugger will run the program upto the instruction where the breakpoint is set and then stop execution of program. At this point, we can examine registry and memory contents at that point. 5. With the help of dump we can view register contents. 6. we can trace the program step by step with the help of F7. 7. We can execute the program completely at a time using F8.

DEBUGGER COMMANDS:
ASSEMBLE: To write assembly language program from the given address A starting address <cr> Eg: a 100 <cr> Starts program at an offset of 100. DUMP: To see the specified memory contents D memory location first address last address (While displays the set of values stored in the specified range, which is given above) Eg: d 0100 0105 <cr> Display the contents of memory locations from 100 to 105(including). ENTER: To enter data into the specified memory locations(s). E memory location data data data data data <cr> Eg: e 1200 10 20 30 40 . Enters the above values starting from memory locations 1200 to 1203, by loading 10 into 1200,20 into 1201 and soon. GO: To execute the program G: one instruction executes (address specified by IP) G address <cr>: executes from current IP to the address specified G first address last addresses <cr>: executes a set of instructions specified between the given addresses MOVE: Moves a set of data from source location to destination location M first address last address destination address Eg: m100 104 200 Transfers block of data (from 100 to 104) to destination address 200.

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

QUIT: To exit from the debugger. Q <cr> REGISTER: Shows the contents of Registers R register name Eg: r ax Shows the contents of register. TRACE: To trace the program instruction by instruction. T = 0100 <cr>: traces only the current instruction. (Instruction specified by IP) T = 0100 02 <cr>: Traces instructions from 100 to 101, here the second argument specifies the number of instructions to be traced. UNASSEMBLE: To unassembled the program. Shows the opcodes along with the assembly language program. U 100 <cr>: unassembled 32 instructions starting from 100th location U 0100 0109 <cr>: unassebles the lines from 100 to 104

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

PROGRAM FOR MULTI BYTE ADDITION AIM: To write an assembly language program to perform multi byte addition of two numbers. REGISTERS USED: AX, DS, AL FLAGS AFFECTED: PROGRAM: ASSUME CS:CODE,DS:DATA CODE SEGMENT MOV AX,DATA MOV DS,AX LEA SI,ARR1 LEA DI,ARR2 LEA BX,ARR3 MOV CX,COUNT MOV AX,0000H SAHF BACK: MOV AL,[DI] ADC AL,[SI] MOV [BX],AL INC SI INC DI INC BX LOOP BACK HLT CODE ENDS DATA SEGMENT ARR1 DB 12H,06H,45H ARR2 DB 12H,07H,09H ARR3 DB ? COUNT EQU 03H DATA ENDS END

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

FLOW CHART:

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

RESULT: INPUT:OPR1= 12h,06h,45h OPR2=12h,07h,09h OUTPUT: RES=24,0D,4E

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

PROGRAM FOR MULTI BYTE SUBTRACTION AIM: To write an assembly language program to perform multi byte subtraction of two numbers. REGISTERS USED: AX, DS, AL FLAGS AFFECTED: PROGRAM: ASSUME CS:CODE,DS:DATA CODE SEGMENT MOV AX,DATA MOV DS,AX LEA SI,ARR1 LEA DI,ARR2 LEA BX,ARR3 MOV CX,COUNT MOV AX,0000H SAHF BACK: MOV AL,[DI] SBB AL,[SI] MOV [BX],AL INC SI INC DI INC BX LOOP BACK HLT CODE ENDS DATA SEGMENT ARR1 DB 12H ARR2 DB 13H ARR3 DB ? COUNT EQU 01H DATA ENDS END

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

FLOW CHART:

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

RESULT:

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

PROGRAM FOR ADDITION OF TWO 8 BIT NUMBERS AIM: To write an assembly language program to perform addition of two 8-bit signed and unsigned numbers. REGISTERS USED: AX, DS, AL FLAGS AFFECTED: AF, CF, OF, PF, SF, ZF PROGRAM: ASSUME CS:CODE,DS:DATA CODE SEGMENT MOV AX,DATA MOV DS,AX MOV AL,OPR1 ADD AL,OPR2 MOV RES,AL HLT CODE ENDS DATA SEGMENT OPR1 DB 69H OPR2 DB 10H RES DB ? DATA ENDS END

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

FLOW CHART:

START

INITIALIZATION OF DATA SEGMENT

ALOPR1

ALAL+OPR2 RESAL

STOP

RESULT: UNSIGNED NUMBERS INPUT: OPR1 = 69H OPR2 = 10H OUTPUT: RES = 79H

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

SIGNED NUMBERS INPUT: OPR1 = 97H OPR2 = A9H OUTPUT: RES = 40H, CF = 1

ADDITION OF TWO 16-BIT NUMBERS AIM: To write an assembly language program to perform addition of two 16-bit signed and unsigned numbers. REGISTERS USED: AX, DS FLAGS AFFECTED: AF, CF, OF, PF, SF, ZF PROGRAM: ASSUME CS:CODE,DS:DATA CODE SEGMENT MOV AX,DATA MOV DS,AX MOV AX,OPR1 ADD AX,OPR2 MOV RES,AX HLT CODE ENDS DATA SEGMENT OPR1 DW 4269H OPR2 DW 1000H RES DW ? DATA ENDS END

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

FLOW CHART:

START

INITIALIZATION OF DATA SEGMENT

AXOPR1

AXAX+OPR2 RESAX

STOP

RESULT: UNSIGNED NUMBERS INPUT: OPR1 = 4269H

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

OPR2 = 1000H OUTPUT: RES = 5269H SIGNED NUMBERS INPUT: OPR1 = 9763H OPR2 = A973H OUTPUT: RES = 40D6H , CF = 1

SUBTRACTION OF TWO 8-BIT NUMBERS AIM: To write an assembly language program to perform subtraction of two 16-bit signed and unsigned numbers. REGISTERS USED: AX, DS, AL FLAGS AFFECTED: AF, CF, OF, PF, SF, ZF PROGRAM: ASSUME CS:CODE,DS:DATA CODE SEGMENT MOV AX,DATA MOV DS,AX MOV AL,OPR1 SUB AL,OPR2 MOV RES,AL HLT CODE ENDS DATA SEGMENT OPR1 DB 69H OPR2 DB 10H RES DB ? DATA ENDS END

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

FLOW CHART:

START

INITIALIZATION OF DATA SEGMENT

ALOPR1

ALAL-OPR2 RESAL

STOP

RESULT: UNSIGNED NUMBERS

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

INPUT:

OPR1 = 69H OPR2 = 10H OUTPUT: RES = 59H SIGNED NUMBERS INPUT: OPR1 = 97H OPR2 = 89H OUTPUT: RES = 0DH

SUBTRACTION OF TWO 16-BIT NUMBERS AIM: To write an assembly language program to perform subtraction of two 16-bit signed and unsigned numbers. REGISTERS USED: AX, DS FLAGS AFFECTED: AF, CF, OF, PF, SF, ZF PROGRAM: ASSUME CS:CODE,DS:DATA CODE SEGMENT MOV AX,DATA MOV DS,AX MOV AX,OPR1 SUB AX,OPR2 MOV RES,AX HLT CODE ENDS DATA SEGMENT OPR1 DW 4269H OPR2 DW 1000H RES DW ? DATA ENDS END

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

FLOW CHART:

START

INITIALIZATION OF DATA SEGMENT

AXOPR1 AXAX-OPR2 RESAX

STOP

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

RESULT: UNSIGNED NUMBERS INPUT: OPR1 = 4269H OPR2 = 1000H OUTPUT: RES = 3269H SIGNED NUMBERS INPUT: OPR1 = 9763H OPR2 = 8973H OUTPUT: RES = 0DF0H

MULTIPLICATION OF TWO 16-BIT UNSIGNED NUMBERS AIM: To write an assembly language program to perform multiplication of two 16-bit unsigned numbers. REGISTERS USED: AX,DS FLAGS AFFECTED: OF,CF PROGRAM: ASSUME CS:CODE,DS:DATA CODE SEGMENT MOV AX,DATA MOV DS,AX MOV AX,OPR1 MUL OPR2 MOV RESLW,AX MOV RESHW,DX HLT CODE ENDS DATA SEGMENT OPR1 DW 2000H OPR2 DW 4000H RESLW DW ? RESHW DW ? DATA ENDS END

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

FLOW CHART:

START

INITIALIZATION OF DATA SEGMENT

AXOPR1 AXAX*OPR2 RESLWAX RESHWDX STOP

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

RESULT: INPUT: OPR1 = 2000H OPR2 = 4000H OUTPUT: RESLW = 0000H (AX) RESHW = 0800H (DX)

MULTIPLICATION OF TWO 16-BIT SIGNED NUMBERS AIM: To write an assembly language program to perform multiplication of two 16-bit signed numbers. REGISTERS USED: AX,DS FLAGS AFFECTED: OF,CF PROGRAM: ASSUME CS:CODE,DS:DATA CODE SEGMENT MOV AX,DATA MOV DS,AX MOV AX,OPR1 IMUL OPR2 MOV RESLW,AX MOV RESHW,DX HLT CODE ENDS DATA SEGMENT OPR1 DW 7593H OPR2 DW 6845H RESLW DW ? RESHW DW ? DATA ENDS

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

END

FLOW CHART:

START

INITIALIZATION OF DATA SEGMENT

AXOPR1

AXAX*OPR2 RESLWAX RESHWDX

STOP

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

RESULT: CASE I: Two positive numbers INPUT: OPR1 = 7593H OPR2 = 6845H OUTPUT: RESLW = 689FH (AX) RESHW = 2FE3H (DX) CASE II: one positive number & one negative number INPUT: OPR1 = 8A6DH 2s Complement of (-7593H) OPR2 = 6845H OUTPUT: RESLW = 9761H (AX) 2s Complement RESHW = D01CH (DX) of (- 2FE3689FH) CASE III: two negative numbers INPUT: OPR1 = 8A6DH 2s Complement of (-7593H) OPR2 = 97BBH 2s Complement of (-6845H) OUTPUT: RESLW = 689FH (AX) RESHW = 2FE3H (DX)

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

DIVISION OF UNSIGNED NUMBERS AIM: To write an assembly language program to perform division of 16-bit unsigned number by 8-bit unsigned number. REGISTERS USED: AX, DS FLAGS AFFECTED: IF PROGRAM: ASSUME CS:CODE,DS:DATA CODE SEGMENT MOV AX,DATA MOV DS,AX MOV AX,OPR1 DIV OPR2 MOV RESQ,AL MOV RESR,AH HLT CODE ENDS DATA SEGMENT OPR1 DW 2C58H OPR2 DB 56H

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

RESQ DB ? RESR DB ? DATA ENDS END

START
FLOW CHART:

INITIALIZATION OF DATA SEGMENT

AXOPR1

AXAX/OPR2 RESQAL RESRAH

STOP

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

RESULT: INPUT: OPR1 = 2C58H (DIVIDEND) OPR2 = 56H (DIVISOR) OUTPUT: RESQ = 84H (AL) RESR = 00H (AH)

DIVISION OF SIGNED NUMBERS AIM: To write an assembly language program to perform division of 16-bit signed number by 8-bit signed number. REGISTERS USED: AX, DS FLAGS AFFECTED: IF PROGRAM: ASSUME CS:CODE,DS:DATA CODE SEGMENT MOV AX,DATA MOV DS,AX MOV AX,OPR1 IDIV OPR2 MOV RESQ,AL MOV RESR,AH HLT CODE ENDS DATA SEGMENT

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

OPR1 DW 26F8H OPR2 DB 0AAH RESQ DW ? RESR DW ? DATA ENDS END

START

FLOW CHART:

INITIALIZATION OF DATA SEGMENT

AXOPR1

AXAX/OPR2 RESQAL RESRAH

STOP

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

RESULT: CASE I: two positive numbers INPUT: OPR1 = 26F8H (DIVIDEND) OPR2 = 56H (DIVISOR) OUTPUT: RESQ = 74H (AL) RESR = 00H (AH) CASE II: one positive number & one negative number INPUT: OPR1 = D908H 2s Complement of (-26F8H) OPR2 = 56H OUTPUT: RESQ = 8CH (AL) 2s Complement of (- 74H) RESR = 00H (AH) CASE III: one positive number & one negative number INPUT: OPR1 = 26F8H OPR2 = AAH 2s Complement of (-56H) OUTPUT: RESQ = 8CH (AL) 2s Complement of (- 74H) RESR = 00H (AH)

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

ASCII ADDITION AIM: To write an ALP to perform the addition of two ASCII bytes. REGISTERS USED: AX,DS FLAGS AFFECTED: AF,CF PROGRAM: ASSUME CS:CODE,DS:DATA CODE SEGMENT MOV AX,DATA MOV DS,AX MOV AH,00H MOV AL,CHAR ADD AL,CHAR1 AAA MOV RES,AX

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

HLT CODE ENDS DATA SEGMENT CHAR DB '8' CHAR1 DB '6' RES DW ? DATA ENDS END

START

FLOW CHART:

INITIALIZATION OF DATA SEGMENT

AH00 AlCHAR ALAL+CHAR1


ASCII adjust for addition

RESAX

STOP

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

RESULT: INPUT: CHAR = 8 CHAR1 = 6 OUTPUT: RES = 0104 (AX) unpacked BCD of 14

ASCII SUBTRACTION AIM: To write an ALP to perform the subtraction of two ASCII bytes. REGISTERS USED: AX, DS FLAGS AFFECTED: AF, CF PROGRAM: ASSUME CS:CODE,DS:DATA CODE SEGMENT MOV AX,DATA MOV DS,AX MOV AH,00H MOV AL,CHAR SUB AL,CHAR1 AAS

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

MOV RES,AX HLT CODE ENDS DATA SEGMENT CHAR DB 9 CHAR1 DB 5 RES DW ? DATA ENDS END

START

INITIALIZATION OF DATA SEGMENT


FLOW CHART:

AH00 ALCHAR ALAL-CHAR1


ASCII adjust for subtraction

RESAX

STOP

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

RESULT: CASE I: INPUT: CHAR = 9 CHAR1 = 5 OUTPUT: RES = 0004 (AX) CASE II: INPUT: CHAR = 5 CHAR1 = 9 OUTPUT: RES = 00FC (AX) 2s Complement of (-4)

ASCII MULTIPLICATION AIM: To write an ALP to perform the multiplication of two ASCII bytes. REGISTERS USED: AX, DS FLAGS AFFECTED: PF, SF, ZF PROGRAM: ASSUME CS:CODE,DS:DATA CODE SEGMENT MOV AX,DATA MOV DS,AX MOV AH,00 MOV AL,NUM1

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

MUL NUM2 AAM MOV RES,AX HLT CODE ENDS DATA SEGMENT NUM1 DB 09 NUM2 DB 05 RES DW ? DATA ENDS END

START

INITIALIZATION OF DATA SEGMENT


FLOW CHART:

AH00 ALNUM1 ALAL*NUM2


ASCII adjust for multiplication

RESAX

STOP

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

RESULT: INPUT: NUM1 = 09 NUM2 = 05 OUTPUT: RES = 0405 (AX) unpacked BCD of 45

ASCII DIVISION AIM: To write an ALP to perform the multiplication of two ASCII numbers. REGISTERS USED: AX, DS FLAGS AFFECTED: PF, SF, ZF PROGRAM: ASSUME CS:CODE,DS:DATA CODE SEGMENT MOV AX,DATA MOV DS,AX

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

MOV AX,DIVIDEND AAD MOV CH,DIVISOR DIV CH MOV RESQ,AL MOV RESR,AH HLT CODE ENDS DATA SEGMENT DIVIDEND DW 0607H DIVISOR DB 09H RESQ DB ? RESR DB ? DATA ENDS END

START

INITIALIZATION OF DATA SEGMENT

AXDIVIDEND
FLOW CHART: ASCII Adjust for Division

CHDIVISOR AXAX/CH RESQAL, RESRAH

STOP

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

RESULT: INPUT: DIVIDEND = 0607H unpacked BCD of 67 DIVISOR = 09H OUTPUT: RESQ = 07 (AL) RESR = 04 (AH)

ASCENDING ORDER AIM: To write an assembly language program to arrange the given numbers in ascending order. REGISTERS USED: AX,DS,ES,SI,DI FLAGS AFFECTED: AX,DS,SI,CX,DX PROGRAM: ASSUME CS:CODE,DS:DATA

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

CODE SEGMENT MOV AX,DATA MOV DS,AX MOV DX,COUNT-1 START BACK:MOV CX,DX MOV SI,OFFSET LIST AGAIN:MOV AX,[SI] INITIALIZATION OF CMP AX,[SI+2] SEGMENT DATA JC GO XCHG AX,[SI+2] DXCOUNT-1 XCHG AX,[SI] GO:INC SI INC SI BACK : CXDX LOOP AGAIN DEC DX SIOFFSET JNZ BACK ADDRESS OF LIST HLT CODE ENDS DATA SEGMENT AX[SI] AGAIN: LIST DW 05H,04H,01H,03H,02H COUNT EQU 05H DATA ENDS IF TRUE END AX < [SI+2] FALSE EXCHANGE [SI] &[SI+2] INCREMENT SI BY 2 FALSE IF CX= 0 FLOW CHART: FALSE

TRUE

DECREMENT DX IF DX= 0 TRUE STOP

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

RESULT: INPUT: LIST (DS: 0000H) = 05H,04H,01H,03H,02H OUTPUT: LIST (DS: 0000H) = 01H,02H,03H,04H,05H

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

DESCENDING ORDER AIM: To write an assembly language program to arrange the given numbers in descending order. REGISTERS USED: AX,DS,SI,CX,DX FLAGS AFFECTED: CF,AF,

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

PROGRAM: ASSUME CS:CODE,DS:DATA CODE SEGMENT MOV AX,DATA START MOV DS,AX MOV DX,COUNT-1 BACK:MOV CX,DX INITIALIZATION OF MOV SI,OFFSET LIST DATA SEGMENT AGAIN:MOV AX,[SI] CMP AX,[SI+2] DXCOUNT-1 JNC GO XCHG AX,[SI+2] XCHG AX,[SI] : CXDX BACK GO:INC SI INC SI LOOP AGAIN SIOFFSET DEC DX ADDRESS OF LIST JNZ BACK HLT AGAIN: AX[SI] CODE ENDS DATA SEGMENT LIST DW 03H,04H,01H,05H,02H IF COUNT EQU 05H AX > DATA ENDS [SI+2] END FALSE EXCHANGE [SI] &[SI+2] INCREMENT SI BY 2 FALSE IF CX= 0

TRUE

TRUE

DECREMENT DX FLOW CHART: FALSE IF DX= 0 TRUE STOP

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

RESULT: INPUT: LIST (DS: 0000H) = 03H,04H,01H,05H,02H OUTPUT: LIST (DS: 0000H) = 05H,04H,03H,02H,01H

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

LOGICAL AND OPERATION AIM: To write an Assembly language program to perform the Logical AND operation. REGISTERS USED: AX, DS

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

FLAGS AFFECTED: PF, SF, ZF PROGRAM: ASSUME CS:CODE,DS:DATA CODE SEGMENT MOV AX,DATA MOV DS,AX MOV AX,OPR1 AND AX,OPR2 MOV RES,AX HLT CODE ENDS DATA SEGMENT OPR1 DW 6493H OPR2 DW 1936H RES DW ? DATA ENDS END

START

INITIALIZATION OF DATA SEGMENT

AXOPR1

FLOW CHART:

AXAX AND OPR2 RESAX

STOP

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

RESULT: INPUT: OPR1 = 6493H OPR2 = 1936H OUTPUT: RES = 0012H

LOGICAL OR OPERATION AIM: To write an Assembly language program to perform the Logical OR operation.

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

REGISTERS USED: AX, DS FLAGS AFFECTED: PF, SF, ZF PROGRAM: ASSUME CS:CODE,DS:DATA CODE SEGMENT MOV AX,DATA MOV DS,AX MOV AX,OPR1 OR AX,OPR2 MOV RES,AX HLT CODE ENDS DATA SEGMENT OPR1 DW 6493H OPR2 DW 1936H RES DW ? DATA ENDS END

START

INITIALIZATION OF DATA SEGMENT

AXOPR1

AXAX OR OPR2 RESAX


FLOW CHART:

STOP

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

RESULT: INPUT: OPR1 = 6493H OPR2 = 1936H OUTPUT: RES = 7DB7H

LOGICAL XOR OPERATION

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

AIM: To write an Assembly language program to perform the Logical XOR operation. REGISTERS USED: AX, DS FLAGS AFFECTED: PF, SF, ZF PROGRAM: ASSUME CS:CODE,DS:DATA CODE SEGMENT MOV AX,DATA MOV DS,AX MOV AX,OPR1 XOR AX,OPR2 MOV RES,AX HLT CODE ENDS DATA SEGMENT OPR1 DW 6493H OPR2 DW 1936H RES DW ? DATA ENDS END

START

INITIALIZATION OF DATA SEGMENT

AXOPR1

AXAX XOR OPR2 RESAX

FLOW CHART:

STOP

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

RESULT: INPUT: OPR1 = 6493H OPR2 = 1936H OUTPUT: RES = 7DA5H

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

LOGICAL NOT OPERATION AIM: To write an Assembly language program to perform the Logical Invert operation. REGISTERS USED: AX,DS FLAGS AFFECTED: No flags are affected. PROGRAM: ASSUME CS:CODE,DS:DATA CODE SEGMENT MOV AX,DATA MOV DS,AX MOV AX,OPR1 NOT AX MOV RES,AX HLT CODE ENDS DATA SEGMENT OPR1 DW 6493H RES DW ? DATA ENDS END

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

FLOW CHART:

START

INITIALIZATION OF DATA SEGMENT

AXOPR1

AXNOT AX RESAX

STOP

RESULT: INPUT: OPR1 = 6493H OUTPUT: RES = 9B6CH

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

SHIFT ARITHMETIC / LOGICAL LEFT OPERATION AIM: To write an Assembly language program to perform the Shift arithmetic / Logical operation. REGISTERS USED: AX, DS FLAGS AFFECTED: SF, ZF, PF PROGRAM: ASSUME CS:CODE,DS:DATA CODE SEGMENT MOV AX,DATA MOV DS,AX MOV AX,OPR1 SAL AX,01H (or) SHL AX,01H MOV RES,AX HLT CODE ENDS DATA SEGMENT OPR1 DW 1639H RES DW ? DATA ENDS END

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

FLOW CHART:

START

INITIALIZATION OF DATA SEGMENT

AXOPR1

Shift AX by 01to left RESAX

STOP

RESULT: INPUT: OPR1 = 1639H OUTPUT: RES = 2C72H

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

LOGICAL RIGHT OPERATION AIM: To write an Assembly language program to perform the Shift Logical Right operation. REGISTERS USED: AX,DS FLAGS AFFECTED: SF,ZF,PF PROGRAM: ASSUME CS:CODE,DS:DATA CODE SEGMENT MOV AX,DATA MOV DS,AX MOV AX,OPR1 SHR AX,01H MOV RES,AX HLT CODE ENDS DATA SEGMENT OPR1 DW 8639H RES DW ? DATA ENDS END

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

FLOW CHART:

START

INITIALIZATION OF DATA SEGMENT

AXOPR1

Shift AX by 01to right RESAX

STOP

RESULT: INPUT: OPR1 = 8639H OUTPUT: RES = 431CH

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

SHIFT ARITHMETIC RIGHT OPERATION AIM: To write an Assembly language program to perform the Shift Arithmetic Right operation. REGISTERS USED: AX,DS FLAGS AFFECTED: SF,ZF,PF PROGRAM: ASSUME CS:CODE,DS:DATA CODE SEGMENT MOV AX,DATA MOV DS,AX MOV AX,OPR1 SAR AX,01H MOV RES,AX HLT CODE ENDS DATA SEGMENT OPR1 DW 8639H RES DW ? DATA ENDS END

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

FLOW CHART:

START

INITIALIZATION OF DATA SEGMENT

AXOPR1

Shift AX by 01to right, Retain MSB RESAX

STOP

RESULT: INPUT: OPR1 = 8639H OUTPUT: RES = C31CH

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

ROTATE RIGHT WITHOUT CARRY AIM: To write an Assembly language program to perform the Rotate Right without carry operation. REGISTERS USED: AX,DS FLAGS AFFECTED: CF,OF PROGRAM: ASSUME CS:CODE,DS:DATA CODE SEGMENT MOV AX,DATA MOV DS,AX MOV AX,OPR1 ROR AX,01H MOV RES,AX HLT CODE ENDS DATA SEGMENT OPR1 DW 1639H RES DW ? DATA ENDS END

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

FLOW CHART:

START

INITIALIZATION OF DATA SEGMENT

AXOPR1

Rotate AX by 01to right RESAX

STOP

RESULT: INPUT: OPR1 = 1639H

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

OUTPUT: RES = 8B1CH

ROTATE RIGHT WITH CARRY AIM: To write an Assembly language program to perform the Rotate Right with carry operation. REGISTERS USED: AX,DS FLAGS AFFECTED: CF,OF PROGRAM: ASSUME CS:CODE,DS:DATA CODE SEGMENT MOV AX,DATA MOV DS,AX MOV AX,OPR1 RCR AX,01H MOV RES,AX HLT CODE ENDS DATA SEGMENT OPR1 DW 1639H RES DW ? DATA ENDS END

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

FLOW CHART:

START

INITIALIZATION OF DATA SEGMENT

AXOPR1

Rotate with carry AX by 01 to right

RESAX

STOP

RESULT: INPUT: OPR1 = 1639H

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

OUTPUT: RES = 0B1CH

ROTATE LEFT WITHOUT CARRY AIM: To write an Assembly language program to perform the Rotate Left without carry operation. REGISTERS USED: AX,DS FLAGS AFFECTED: CF,OF PROGRAM: ASSUME CS:CODE,DS:DATA CODE SEGMENT MOV AX,DATA MOV DS,AX MOV AX,OPR1 ROL AX,01H MOV RES,AX HLT CODE ENDS DATA SEGMENT OPR1 DW 8097H RES DW ? DATA ENDS END

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

FLOW CHART:

START

INITIALIZATION OF DATA SEGMENT

AXOPR1

Rotate AX by 01to left RESAX

STOP

RESULT:

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

INPUT:

OPR1 = 8097H

OUTPUT: RES = 012FH

ROTATE LEFT WITH CARRY AIM: To write an Assembly language program to perform the Rotate Left with carry operation. REGISTERS USED: AX,DS FLAGS AFFECTED: CF,OF PROGRAM: ASSUME CS:CODE,DS:DATA CODE SEGMENT MOV AX,DATA MOV DS,AX MOV AX,OPR1 RCL AX,01H MOV RES,AX HLT CODE ENDS DATA SEGMENT OPR1 DW 8097H RES DW ? DATA ENDS END

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

FLOW CHART:

START

INITIALIZATION OF DATA SEGMENT

AXOPR1

Rotate with carry AX by 01 to Left

RESAX

STOP

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

RESULT: INPUT: OPR1 = 8097H OUTPUT: RES = 012EH

PACKED BCD TO UNPACKED BCD AIM: To write an assembly language program to perform packed bcd into unpacked bcd conversion. REGISTERS USED: AX,DS,BL,CL FLAGS AFFECTED: PF PROGRAM: ASSUME CS:CODE,DS:DATA CODE SEGMENT MOV AX,DATA MOV DS,AX MOV AL,BCD MOV BL,AL AND AL,0FH MOV UBCD1,AL MOV AL,BL AND AL,0F0H MOV CL,COUNT ROR AL,CL MOV UBCD2,AL HLT CODE ENDS DATA SEGMENT BCD DB 49H COUNT DB 04H UBCD1 DB ? UBCD2 DB ? DATA ENDS END

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

START

INITIALIZATION OF DATA SEGMENT

FLOW CHART:

ALBCD BLAL

ALAL AND 0FH UBCD1AL ALBL ALAL AND 0FH

Rotate AL to right by count times

UBCD2AL

STOP

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

RESULT: INPUT: BCD = 49 OUTPUT: UBCD1 = 09 UBCD2 = 04

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

BCD TO ASCII CONVERSION AIM: To write an assembly language program to perform BCD to ASCII conversion. REGISTERS USED: AX,DS,BL,CL FLAGS AFFECTED: PF PROGRAM: ASSUME CS: CODE,DS:DATA CODE SEGMENT MOV AX,DATA MOV DS,AX MOV AL,BCD MOV BL,AL AND AL,0FH OR AL,30H MOV ASCII1,AL MOV AL,BL AND AL,0F0H MOV CL,COUNT ROR AL,CL OR AL,30H MOV ASCII2,AL HLT CODE ENDS DATA SEGMENT BCD DB 49H

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

COUNT DB 04H ASCII1 DB ? ASCII2 DB ? DATA ENDS END

START

INITIALIZATION OF DATA SEGMENT

FLOW CHART:

ALBCD BLAL ALAL AND 0F ALAL OR 30 ASCII1AL ALBL AL AL AND F0 CLCOUNT Rotate AL to right by count times

ALAL OR 30

ASCII2AL

STOP

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

RESULT: INPUT: BCD = 49 OUTPUT: UBCD1 = 39 UBCD2 = 34

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

AIM: To write an assembly language program to find the Twos compliment of the given numbers. REGISTERS USED: AX,DS,SI,DI FLAGS AFFECTED: PROGRAM: ASSUME CS:CODE,DS:DATA CODE SEGMENT MOV AX,DATA MOV DS,AX LEA SI,ARR1 LEA DI,ARR2 MOV CL,03H BACK: MOV AL,[SI] NEG AL MOV [DI],AL INC DI INC SI LOOP BACK HLT CODE ENDS DATA SEGMENT ARR1 DB 03H,04H,05H ARR2 DB ?

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

DATA ENDS END

FLOW CHART:

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

RESULT:

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

AIM: To write an assembly language program to convert the given number from Binary Code to Gray code. REGISTERS USED: AX,DS,SI,DI FLAGS AFFECTED: PROGRAM: ASSUME CS:CODE,DS:DATA CODE SEGMENT MOV AX,DATA MOV DS,AX MOV AL,NUM MOV BL,AL CLC RCR AL,01 XOR BL,AL MOV RES,BL HLT CODE ENDS DATA SEGMENT NUM EQU 33H RES DB ? DATA ENDS END

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

FLOW CHART:

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

RESULT:

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

MOVE BLOCK AIM: To write an assembly language program to move the block of data from a source location to the specified destination location. REGISTERS USED: AX,DS,ES,SI,DI FLAGS AFFECTED: No flags are affected PROGRAM: ASSUME CS:CODE,DS:DATA CODE SEGMENT MOV AX,DATA MOV DS,AX MOV AX,DATA MOV ES,AX MOV SI,OFFSET STR1 MOV DI,OFFSET STR2 MOV CL,COUNT CLD REP MOVSB

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

HLT CODE ENDS DATA SEGMENT STR1 DB 04H,0F9H,0BCH,98H,40H COUNT EQU 05H DATA ENDS EXTRA SEGMENT ORG 0010H STR2 DB 0020 ? EXTRA ENDS START END

INITIALIZATION OF DATA, EXTRA SEGMENT INTIALISATION OF SOURCE, DESTINATION POINTER MOVE LENGTH OF STRING TO CL REGISTER

FLOW CHART:

MOVE A BYTE FROM SOURCE TO DESTINATION

INCREMENT POINTER, DECREMENT CL REGISTER

CL= 0
TRUE

FALSE

STOP

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

RESULT: INPUT: STR1 (DS:0000H) = 04H,F9H,BCH,98H,40H OUTPUT: STR2 (DS:0010H) = 04H,F9H,BCH,98H,40H

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

REVERSE STRING AIM: To write an assembly language program to reverse the given string. REGISTERS USED: AX,DS,SI,DI,CL FLAGS AFFECTED: ZF,PF PROGRAM: ASSUME CS:CODE,DS:DATA CODE SEGMENT MOV AX,DATA MOV DS,AX MOV CL,COUNT MOV SI,OFFSET STR1 MOV DI,0003H BACK:MOV AL,[SI] XCHG [DI],AL

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

MOV [SI],AL INC SI DEC DI DEC CL JNZ BACK HLT CODE ENDS DATA SEGMENT STR1 DB 01H,02H,03H,04H START COUNT EQU 02H DATA ENDS END

INITIALIZATION OF DATA SEGMENT

CLCOUNT SIoffset address of STR1 DI0003

Move a byte from SI to DI

FLOW CHART:

INC SI DEC DI DEC CL

FALSE If CL=0 TRUE

STOP

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

RESULT: INPUT: STR1 (DS:0000H) = 01H,02H,03H,04H OUTPUT: STR1 (DS:0000H) = 04H,03H,02H,01H

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

LENGTH OF THE STRING AIM: To write an assembly language program to find the length of the given string. REGISTERS USED: AX,DS,SI,CL FLAGS AFFECTED: ZF,PF,SF,AF,CF PROGRAM: ASSUME CS:CODE,DS:DATA CODE SEGMENT MOV AX,DATA MOV DS,AX MOV AL,00H MOV CL,00H

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

START

MOV SI,OFFSET STR1 BACK:CMP AL,[SI] JNC GO INC CL INC SI INITIALIZATION OF JNZ BACK GO:MOV LENGTH,CL DATA SEGMENT HLT CODE ENDS DATA SEGMENT STR1 DB 01H,03H,08H,09H,05H,07H,02H AL00H CL00H LENGTH DB ? SI OFFSET ADDRESS OF DATA ENDS STR1 END

FALSE AL<[SI] TRUE

Increment CL Increment SI

FALSE If CL=0 FLOW CHART: TRUE

LENGTHCL

STOP

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

RESULT: INPUT: STR (DS:0000H) = 01H, 03H,08H,09H,05H,07H,02H OUTPUT: LENGTH = 07H (CL)

FALSE

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

LARGEST NUMBER IN AN ARRAY AIM: To write an assembly language program to find largest number in the given list. REGISTERS USED: FLAGS AFFECTED: ZF,PF PROGRAM: ASSUME CS:CODE,DS:DATA CODE SEGMENT MOV AX,DATA

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

MOV DS,AX MOV CL,COUNT MOV SI,OFFSET LIST AND AL,[SI] DEC CL BACK: INC SI MOV BL,[SI] CMP AL,BL JNC AHEAD MOV AL,BL AHEAD: DEC CL JNZ BACK MOV RES,AL HLT CODE ENDS DATA SEGMENT LIST DB 06H,15H,05H COUNT DB 03H RES DB ? DATA ENDS END

FLOW CHART:

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

RESULT:

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

SMALLEST NUMBER IN AN ARRAY AIM: To write an assembly language program to find smallest number in the given list. REGISTERS USED: FLAGS AFFECTED: ZF,PF PROGRAM:

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

ASSUME CS:CODE,DS:DATA CODE SEGMENT MOV AX,DATA MOV DS,AX MOV CL,COUNT MOV SI,OFFSET LIST AND AL,[SI] DEC CL BACK: INC SI MOV BL,[SI] CMP AL,BL JC AHEAD MOV AL,BL AHEAD: DEC CL JNZ BACK MOV RES,AL HLT CODE ENDS DATA SEGMENT LIST DB 06H,15H,05H COUNT DB 03 RES DB ? DATA ENDS END

FLOW CHART:

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

RESULT:

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

MATRIX ADDITION OF TWO 3X3 MATRICES AIM: To write an assembly language program matrix addition of two 3X3 matrices. REGISTERS USED:

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

FLAGS AFFECTED: ZF,PF PROGRAM: ASSUME CS:CODE,DS:DATA CODE SEGMENT MOV AX,DATA MOV DS,AX MOV CX,COUNT MOV SI,OFFSET MAT1 MOV DI,OFFSET MAT3 MOV BX,OFFSET MAT2 NEXT: XOR AX,AX MOV AL,[SI] ADD AL,[SI] ADC AH,00H MOV WORD PTR[BX],AX INC SI INC DI ADD BX,02H LOOP NEXT HLT CODE ENDS DATA SEGMENT COUNT EQU 09H MAT1 DB 01H,02H,03H,01H,02H,03H,01H,02H,03H MAT2 DB 01H,02H,03H,01H,02H,03H,01H,02H,03H MAT3 DW ? DATA ENDS END

FLOW CHART:

Geethanjali College of Engineering and Technology


Cheeryal (v), Keesara (M), Ranga Reddy District.

RESULT:

S-ar putea să vă placă și