Download as pdf or txt
Download as pdf or txt
You are on page 1of 144

Dept. of E.C.

Microprocessor & Microcontrollers Lab

PART-A 1. INTRODUCTION TO MASM /TASM


Procedure to create an .exe file

MASM: (Microsoft assembler) To Create Source File: An editor is a program which allows you to create a file containing the assembly language statements for your program. This file is called a source file. Command to create a source file C:\MASM\BIN> Edit filename.asm The next step is to process the source file with an assembler. When you run the Assembler, it reads the source file of your program. On the first pass through the source program, the assembler determines the displacement of named data items, the offset labels, etc. and puts 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 offsets, etc. that it calculated during first pass. C:\MASM\BIN > Masm filename.asm X, Y, Z With this command assembler generates three files. 1. The first file (X) 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. 2. The second file (Y) generated by the assembler is called the assembler list file and is given the extension .LST. The list file contains your assembly language statements, the binary codes for each instruction and the offset for each instruction. 3. The third file (Z) generated by this assembler is called the cross-reference file and is given the extension .CRF. The cross-reference file lists all labels and pertinent information required for cross referencing NOTE: The Assembler only finds syntax errors : It will not tell you whether program does what it is supposed to do. To determine whether your program works, you have to run the program and test it.

Next step is to process the object file with linker.


SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 1

Dept. of E.C.E C:\MASM\BIN>LINK filename.obj Run File [Filename1.exe] : filename1.exe List file [nul.map] Libraries [.lib] Definitions File [nul.def] Creation of Library : NUL : library_name :

Microprocessor & Microcontrollers Lab

: Refer Modular Programming Section

A Linker is a program used to join several object files into one layer object file NOTE: On IBM PC type Computers, You must run the LINK program on your .OBJ file even if it contains only one assembly module. The linker produces a link file with the .EXE extension (an execution file) Next Run C:\MASM\BIN> filename

TASM: (Turbo Assembler) To Create Source File: An editor is a program which allows you to create a file containing the assembly language statements for your program. This file is called a source file. Command to create a source file C:\TASM\BIN> Edit filename.Asm The next step is to process the source file with an assembler. When you run the assembler, it reads the source file of your program. On the first pass through the source program, the assembler determines the displacement of named data items, the offset labels, etc. and puts 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 offsets, etc. that it calculated during first pass. C:\TASM\BIN > TASM filename.asm X, Y, Z With this command assembler generates three files. 4. The first file (X) 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. 5. The second file (Y) generated by the assembler is called the assembler list file and is given the extension .LST. The list file contains your assembly language statements, the binary codes for each instruction and the offset for each instruction. 6. The third file (Z) generated by this assembler is called the cross-reference file and is given the extension .CRF. The cross-reference file lists all labels and pertinent information required for cross referencing

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 2

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

NOTE: The Assembler only finds syntax errors: It will not tell you whether program does what it is supposed to do. To determine whether your program works, you have to run the program and test it. Next step is to process the object file with linker. C:\TASM\BIN>TLINK filename.obj A Linker is a program used to join several object files into one layer object file NOTE: On IBM PC type Computers, You must run the LINK program on your .OBJ file even if it contains only one assembly module. The linker produces a link file with the .EXE extension (an execution file) Next Run C:\TASM\BIN> TD filename.exe

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 3

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 4

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

1.1 . INTRODUCTION TO ASSEMBLY LANGUAGE PROGRAMMING: LEVELS OF PROGRAMMING: There are three levels of programming 1. Machine language 2. Assembler language 3. High level language Machine language programs are programs that the computer can understand and execute directly. Assembly language instructions match machine language instructions, but are written using character strings so that they are more easily understood and High-level language instructions are much closer to the English language and are structured. Ultimately, an assembly language or high level language program must be converted into machine language by programs called translators. If the program being translated is in assembly language, the translator is referred to as an assembler, and if it is in a high level language the translator is referred to as a compiler or interpreter. ASSEMBLY LANGUAGE PROGRAM DEVELOPMENT TOOLS: EDITOR: An editor is a program, which allows you to create a file containing language statements for your program. the assembly

ASSEMBLER: An assembler program is used to translate the assembly language Mnemonic instructions to the corresponding binary codes. The second file generated by assembler is called the assembler List file. LINKER: A Linker is a program used to join several object files in to one large object file. The linkers produce link files with the .EXE extension. DEBUGGER: If your program requires no external hardware, then you can use a debugger to run and debug your program. A debugger is a program, which allows you to load your object code program into system memory, execute the program, and troubleshoot or debug it. ASSEMBLER DIRECTIVES: An assembler is a program used to convert an assembly language program into the equivalent machine code modules. The assembler decides the address of each label and substitutes the values for each of the constants and variables. It then forms the machine code for mnemonics and data in assembly language program. Assembler directives help the assembler to correctly understand assembly language programs to prepare the codes. Commonly used assembler directives are DB, DD, DW, DUP, ASSUME, BYTE, SEGMENT, MACRO, PROC, OFFSET, NEAR, FAR, EQU, STRUC, PTR, END, ENDM, ENDP etc. Some directives generate and store information in the memory, while others do not. DB :- Define byte directive stores bytes of data in memory.

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 5

Dept. of E.C.E BYTE PTR SEGMENT

Microprocessor & Microcontrollers Lab :- This directive indicates the size of data referenced by pointer. :- This directive is to indicate the start of the segment.

DUP (Duplicate) :- The DUP directive reserves memory locations given by the number Preceding it, but stores no specific values in any of these locations. ASSUME : - The ASSUME statement is only used with full segment definitions. This statement tells the assembler what names have been chosen for the code, data, extra and stack segments. EQU : - The equate directive equates a numeric ASCII or label to another label. ORG : - The ORG (origin) statement changes the starting offset address in a segment. PROC and ENDP: - The PROC and ENDP directives indicate start and end of a procedure (Sub routine). Both the PROC and ENDP directives require a label to indicate the name of the procedure. The PROC directive must also be followed with the NEAR or FAR. A NEAR procedure is one that resides in the same code segment as the program. A FAR procedure may reside at any location in the memory system. A MACRO is a group of instructions that performs one task, just as a procedure. The difference is that a procedure is accessed via a CALL instruction, while a macro is inserted in the program at the point of usage as a new sequence of instructions. MACRO : - The first statement of a macro is the MACRO directive preceded with name of the macro. ENDM : - The last statement of a macro is the ENDM instruction. Never place a label in front of the ENDM statement. PUBLIC &EXTRN : - The public and extern directives are very important to modular programming. We use PUBLIC to declare that labels of code, data or entire segments are available to other program modules. We use EXTRN to declare that labels are external to a module. Without this statement, we could not link modules together to create a program using modular programming techniques.
SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 6

Dept. of E.C.E OFFSET

Microprocessor & Microcontrollers Lab : - Offset of a label. When the assembler comes across the OFFSET operator along with a label, it first computes the 16 bit displacement of the particular label, and replaces the string OFFSET LABEL by the computed displacement.

LENGTH

: - Byte length of the label. This directive is used to refer to the length of data array or a string.

1.2. MICROPROCESSOR TRAINER KIT The microprocessor trainer kit (microprocessor development kit) is an aid to understand the architecture, interfacing and programming of a microprocessor. Here we describe the ESA 86/88 2trainer kit. ESA 86/88-2 is a powerful, general-purpose microcomputer system, which can be operated either with 8086 CPU or with 8088 CPU. The basic system can be easily expanded through the system BUS connector. The built in Assembler/ Disassembler feature simplifies the programmers task of entering Assembly language programs .The on-board provision for 8087 numeric data processor makes it useful for number crunching applications. On board battery backup provision is an added feature to take care of frequent power failures while conducting experiments of the trainer using manually assembled code. It is also provided with peripherals and controllers such as 8251A : Programmable communication Interface for serial communication. 8253-5 : Programmable Interval Timer 8255A : Two Programmable Peripheral Interface Devices provide 48 programmable I/O lines 8259A : Programmable Interrupt Controller provides interrupt vectors for 8 sources. 8288 : Bus Controller for generating control signals

ESA 86/88-2 is operated from the CRT terminals or a host computer system via the serial monitor and also can be operated from the on board key board. 8255 OPERATIONAL MODES 8255 ports can be initialized in three different modes. MODE 0: In this mode, all ports function as simple I/O ports without hand shaking.

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 7

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

MODE 1: This mode is handshake mode where by port A and port B use the bits Port C as handshake signals. MODE 2: Only port A can be initialized in mode 2. In this mode port A can be used for Bidirectional handshake data transfer. Port B can be initialized in mode 0 or mode1. 1.3. COMMUNICATION WITH A HOST COMPUTER SYSTEM ESA 86/88-2 operating in the serial mode can be connected to either CRT terminal or host computer system. When computer system is the controlling element it must be executing the driver software to communicate with ESA 86/88-2. XT86 is a package which allows the user to establish a communication link between ESA 86/88-2 system and a computer system. The link is established between asynchronous serial ports of the computer and ESA 86/88-2.A suitable RS232-C cables have to be used for connecting the kit to the computer system. User can develop assembly language programs on the computer system, cross- assemble them using a suitable cross assembler to generate object code files and then use XT86 to download these object code files into the trainer kit for execution. User can terminate XT86 and return control to DOS by typing Alt + X. XT86 also allows uploading of data from the memory of the kit to the computer. The data so uploaded is same in a disk file.

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 8

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

Mode Set flag 1=Active in i/o mode,0=Active bit set rest mode Mode Selection for Group A= 00-Mod 0, 01-Mode1, 10-Mode2 Port A 1=input, 0=output Port B 1=input, 0=output Mode Selection Group B=0-Mode 0, 1-Mode 1 Port C upper 1=input, 0=output Port C lower 1=input, t 0=output 1.4. INTEL 8086 MICROPROCESSOR PROGRAMMING USING DEBUG TO EXECUTE 80X86 PROGRAMS: DEBUG is a utility program that allows a user to load an 80x 86 programs in to memory and execute it step by step. DEBUG displays the contents of all processor registers after each instruction executes, allowing user to determine if the code is performing the desired task. DEBUG only displays the 16-bit portion of the general purpose registers. Code view is capable of displaying the entire 32 bits. DEBUG is a very useful debugging tool. We will use DEBUG to step through number of simple programs, gaining familiarity with DEBUG commands as we do. DEBUG contains commands that can display and modify memory, assemble instructions, disassemble code already placed into memory, trace through single or multiple instructions, load registers with data, and do much more. DEBUG loads into memory like any other program, in the fist available slot. The memory space used by DEBUG for the user program begins after the end of DEBUG code. If an .EXE or. COM file were specified, DEBUG would load the program according to the accepted conventions. To execute the program file PROG.EXE use this command: DEBUG PROG.EXE DEBUG uses a minus as its command prompt, so you should see a -appear on display. To get a list of some commands available with DEBUG is: T U trap(step by step execution) un assemble

D Dump G go (complete execution) H Hex E.g: To execute the program file PROG.ASM use the following procedure:
SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 9

Dept. of E.C.E TASM PROG.ASM TLINK PROG.OBJ DEBUG PROG.EXE

Microprocessor & Microcontrollers Lab

Turbo Assembler Version 5.3 Copyright (c) 1988, 2000 Inprise Corporation Syntax: TASM [options] source [,object] [,listing] [,xref] /a, /s /c /dSYM[=VAL] /e,/r /h,/? /iPATH /jCMD /kh# /l,/la /ml, /mx,/mu /mv# /m# /n Alphabetic or Source-code segment ordering Generate cross-reference in listing Define symbol SYM = 0, or = value VAL Emulated or Real floating-point instructions Display this help screen Search PATH for include files Jam in an assembler directive CMD (eg. /jIDEAL) Hash table capacity # symbols Generate listing: l=normal listing, la=expanded listing Case sensitivity on symbols: ml=all, mx=globals, mu=none Set maximum valid length for symbols Allow # multiple passes to resolve forward references Suppress symbol tables in listing

/os,/o,/op,/oi Object code: standard, standard w/overlays, Phar Lap, IBM /p /q /t /uxxxx /w0,/w1,/w2 Check for code segment overrides in protected mode Suppress OBJ records not needed for linking Suppress messages if successful assembly Set version emulation, version xxxx Set warning level: w0=none, w1=w2=warnings on

/w-xxx,/w+xxx Disable (-) or enable (+) warning xxx /x /z /zi,/zd,/zn Include false conditionals in listing Display source line with error message Debug info: zi=full, zd=line numbers only, zn=none

Turbo Link Version 4.01 Copyright (c) 1991 Borland International


SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 10

Dept. of E.C.E Syntax: TLINK objfiles, exefile, mapfile, libfiles, deffile @xxxx indicates use response file xxxx /m Map file with publics /i Initialize all segments /x No map file at all /l Include source line numbers

Microprocessor & Microcontrollers Lab

/L Specify library search paths /s Detailed map of segments /n No default libraries /d Warn if duplicate symbols in libraries

/c Case significant in symbols /3 Enable 32-bit processing /o Overlay switch /v Full symbolic debug information /A=NNNN Set NewExe segment alignment /yx Extended memory swapping

/P[=NNNNN] Pack code segments /ye Expanded memory swapping /e Ignore Extended Dictionary /t Create COM file (same as /Tdc)

/C Case sensitive exports and imports /Txx Specify output file type /Tdx DOS image (default) /Twx Windows image (third letter can be c=COM, e=EXE, d=DLL) DEBUG- Testing and edition tool help ; MS-DOS based program. MS-DOS prompt/debug [filename .exe/.com/others] assemble Compare Dump Enter Fill Go Hex Input A [address] C range address D [range] E address [list] F range list G [=address] [addresses] H value1 value2 I port
Page 11

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Dept. of E.C.E Load Move Name Output Proceed Quit Register Search Trace L [address] [drive] [firstsector] [number] M range address N [pathname] [arglist] O port byte P [=address] [number] Q R [register] S range list T [=address] [value] U [range]

Microprocessor & Microcontrollers Lab

Unassembled Write

W [address] [drive] [first sector] [number] XA [#pages] XD [handle] XM [Lpage] [Ppage] [handle] XS

Allocate expanded memory De allocate expanded memory Map expanded memory pages Display expanded memory status

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 12

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

2. ARITHMETIC OPERATIONS 2(A) MULTI BYTE ARTHEMETIC OPERATIONS


AIM: To write assembly language programs for performing following arithmetic operations. I) multi byte addition II) multi byte subtraction III) multi byte multiplication IV) multi byte division APPARATUS: Computer with TASM/MASM software I)Algorithm for adding two multi byte numbers and store the result as the third number: 1. Store the count. 2. Initialize the source index which contains the first source address. 3. Initialize the source index which contains the second source address 4. Initialize a register which contains the address at where the result has to be stored 5. Get the value from source1 memory to accumulator. 6. Perform addition on first and second sources 7. Put the result in allocated memory location 8. Increment the source1 register address. 9. Increment the source2 register address 10. Increment the register which contains address of result memory location . 11. End of the program execution. PROGRAM: DATA SEGMENT BYTES EQU 08H NUM1 DB 05H, 5AH, 6CH, 55H, 66H, 77H, 34H, 12H NUM2 DB 04H, 56H, 04H, 57H, 32H, 12H, 19H, 13H NUM3 DB 0AH DUP (00) DATA ENDS
SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 13

Dept. of E.C.E CODE SEGMENT ASSUME CS:CODE, DS:DATA START: MOV AX,DATA MOV DS,AX MOV CX,BYTES LEA SI,NUM1 LEA DI,NUM2 LEA BX,NUM3 MOV AX,0000 NEXT: MOV AL,[SI] ADC AL,[DI] MOV [BX],AL INC SI INC DI INC BX DEC CX JNZ NEXT INT 3H CODE ENDS END START

Microprocessor & Microcontrollers Lab

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 14

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

Machine code Address 5C7C:0000 5C7C:0003 5C7C:0005 5C7C:0008 5C7C:000B 5C7C:000E 5C7C:0011 mechine code B87A5C 8ED8 B90800 BE0000 BF0800 BB1000 B80000 mnemonics operands MOV MOV MOV MOV MOV MOV MOV AX,5C7A DS,AX CX,0008 SI,0000 DI,0008 BX,0010 AX,0000
Page 15

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Dept. of E.C.E 5C7C:0014 5C7C:0016 5C7C:0018 5C7C:001A 5C7C:001B 5C7C:001C 5C7C:001D 5C7C:001E INPUTS: 8A04 1205 8807 46 47 43 49 75F4 MOV ADC MOV INC INC INC DEC JNZ AL,[SI] AL,[DI] [BX],AL SI DI BX CX 0014

Microprocessor & Microcontrollers Lab

NUM1 DB 05H, 5AH, 6CH, 55H, 66H, 77H, 34H, 12H NUM2 DB 04H, 56H, 04H, 57H, 32H, 12H, 19H, 13H

OUTPUT:

NUM3 DB (09H,B0H,70H,ACH,98H,89H,4DH,25H)

II)Algorithm for Subtracting Two Multi Byte Numbers and Store the Result as the Third Number: 1. Store the count. 2. Initialize the source index which contains the first source address. 3. Initialize the source index which contains the second source address 4. Initialize a register which contains the address at where the result has to be stored 5. Get the value from source1 memory to accumulator. 6. Perform subtraction on first and second sources 7. Put the result in allocated memory location 8. Increment the source1 register address. 9. Increment the source2 register address 10. Increment the register which contains address of result memory location . 11. End of the program execution. PROGRAM: DATA SEGMENT BYTES EQU 08H NUM2 DB 05H,5AH,6CH,55H,66H,77H,34H,12H
SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 16

Dept. of E.C.E NUM1 DB 04H,56H,04H,57H,32H,12H,19H,13H NUM3 DB 0AH DUP (00) DATA ENDS CODE SEGMENT ASSUME CS: CODE,DS: DATA START: MOV AX,DATA MOV DS,AX MOV CX,BYTES LEA SI,NUM1 LEA DI,NUM2 LEA BX,NUM3 MOV AX,00 NEXT: MOV AL,[SI] SBB AL,[DI] MOV [BX],AL INC SI INC DI INC BX DEC CX JNZ NEXT INT 3H CODE ENDS END START

Microprocessor & Microcontrollers Lab

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 17

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

Machine code Address 5C7B:0000 5C7B:0003 5C7B:0005 5C7B:0008 5C7B:000B mechine code B8795C 8ED8 B90800 BE0800 BF0000 mnemonics operands MOV MOV MOV MOV MOV AX,5C79 DS,AX CX,0008 SI,0008 DI,0000
Page 18

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Dept. of E.C.E 5C7B:000E 5C7B:0011 5C7B:0014 5C7B:0016 5C7B:0018 5C7B:001A 5C7B:001B 5C7B:001C 5C7B:001D 5C7B:001E INPUTS: BB1000 B80000 8A04 1A05 8807 46 47 43 49 75F4 MOV MOV MOV SBB MOV INC INC INC DEC JNZ BX,0010 AX,0000 AL,[SI] AL,[DI] [BX],AL SI DI BX CX 0014

Microprocessor & Microcontrollers Lab

NUM2 DB 05H,5AH,6CH,55H,66H,77H,34H,12H NUM1 DB 04H,56H,04H,57H,32H,12H,19H,13H

OUTPUT:

NUM3 DB 01H,04H,68H,02H,34H,65H,14H,FFH,

III)Algorithm for Multiplying two multi byte numbers and store the result as the third number 1. Store the count. 2. Initialize the source index which contains the first source address. 3. Initialize the source index which contains the second source address 4. Initialize a register which contains the address at where the result has to be stored 5. Get the value from source1 memory to accumulator. 6. Perform multiplication on first and second sources 7. Put the result in allocated memory location 8. Increment the source1 register address. 9. Increment the source2 register address 10. Increment the register which contains address of result memory location . 11. End of the program execution.

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 19

Dept. of E.C.E PROGRAM: DATA SEGMENT BYTES EQU 08H NUM1 DB 05H, 0AH, 03H, 0CH, 05H, 06H, 07H, NUM2 DB 04H, 06H, 04H, 05H, 32H, 12H, 19H NUM3 DB 07H DUP (00) DATA ENDS CODE SEGMENT ASSUME CS:CODE, DS:DATA START: MOV AX,DATA MOV DS,AX MOV CX,BYTES LEA SI,NUM1 LEA DI,NUM2 LEA BX,NUM3 MOV AX,00 NEXT: MOV AL,[SI] MOV DL,[DI] MUL DL MOV [BX], AL MOV [BX+1],AH INC SI INC DI INC BX INC BX DEC CX JNZ NEXT
SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Microprocessor & Microcontrollers Lab

Page 20

Dept. of E.C.E INT 3H CODE ENDS END START

Microprocessor & Microcontrollers Lab

Machine code Address 5C7B:0000 5C7B:0003 5C7B:0005 5C7B:0008 5C7B:000B 5C7B:000E mechine code B8795C 8ED8 B90800 BE0000 BF0700 BB0E00 mnemonics operands MOV MOV MOV MOV MOV MOV AX,5C79 DS,AX CX,0008 SI,0000 DI,0007 BX,000E

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 21

Dept. of E.C.E 5C7B:0011 5C7B:0014 5C7B:0016 5C7B:0018 5C7B:001A 5C7B:001C 5C7B:001F B80000 8A04 8A15 F6E2 8807 886701 46 MOV MOV MOV MUL MOV MOV INC AX,0000 AL,[SI] DL,[DI] DL [BX],AL [BX+01],AH SI

Microprocessor & Microcontrollers Lab

INPUTS: NUM1 DB 05H, 0AH, 03H,0CH, 05H, 06H, 07H, NUM2 DB 04H, 06H, 04H, 05H, 32H, 12H, 19H, OUTPUT: NUM3 DB 14H, 3CH, 0CH, 3CH, FAH, 6CH, AFH, IV)Algorithm for dividing two multi byte numbers and store the result as the third number: 1. Store the count. 2. Initialize the source index which contains the first source address. 3. Initialize the source index which contains the second source address 4. Initialize a register which contains the address at where the result has to be stored 5. Get the value from source1 memory to accumulator. 6. Perform division on first and second sources 7. Put the result in allocated memory location 8. Increment the source1 register address. 9. Increment the source2 register address 10. Increment the register which contains address of result memory location . 11. End of the program execution. PROGRAM: DATA SEGMENT BYTES EQU 08H NUM2 DB 05H, 15H, 6CH, 05H, 06H, 07H, 04H, 02H NUM1 DW 0020H, 0056H, 0140H, 0057H, 0032H,0012H, 0019H, 0013H
SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 22

Dept. of E.C.E NUM3 DB 08H DUP (00) DATA ENDS CODE SEGMENT ASSUME CS: CODE, DS: DATA START: MOV AX, DATA MOV DS, AX MOV CX, BYTES LEA SI, NUM1 LEA DI, NUM2 LEA BX, NUM3 NEXT: MOV AX, 0000 MOV AX,[SI] MOV DL,[DI] DIV DL MOV [BX], AL MOV [BX+1],AH INC SI INC DI INC BX INC BX DEC CX JNZ NEXT INT 3H CODE ENDS END START

Microprocessor & Microcontrollers Lab

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 23

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

Machine code Address 5C7B:0000 5C7B:0003 5C7B:0005 5C7B:0008 5C7B:000B 5C7B:000E 5C7B:0011 5C7B:0014 machine code B8795C 8ED8 B90800 BE0800 BF0000 BB1800 B80000 8B04 mnemonics operands MOV MOV MOV MOV MOV MOV MOV MOV AX,5C79 DS,AX CX,0008 SI,0008 DI,0000 BX,0018 AX,0000 AX,[SI]
Page 24

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Dept. of E.C.E 5C7B:0016 5C7B:0018 5C7B:001A 5C7B:001C 5C7B:001F 8A15 F6F2 8807 886701 46 MOV DIV MOV MOV INC DL,[DI] DL [BX],AL [BX+01],AH SI

Microprocessor & Microcontrollers Lab

INPUTS: NUM2 DB 05H, 15H, 6CH, 05H, 06H, 07H, 04H, 02H NUM1 DW 0020H, 0056H, 0140H, 0057H, 0032H,0012H, 0019H, 0013H OUTPUT: NUM3 DB 06H, 04H, 02H, 11H, 08H, 02H , 06H, RESULT: The assembly language programs for performing arithmetic operations were written and executed successfully. Viva-Voice: 1) 2) 3) 4) 5) 6) Write instructions which perform addition operation in direct addressing, indirect addressing? What are the flags effected after executing ADD instruction? What is the difference between ADD&ADC instruction? What are the flags effected after executing MOV BX, 1230 instruction? What is the difference between SUB,SBB instruction? What are the flags effected after execution of HLT instruction ?

7) What are the flags effected after execute up ADD AX,DX instruction (Assume: AX=FFFFh,DX=0001h)? 8) What is the difference between MOV DX,[1050],MOV DX,1050?

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 25

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

2(B) SIGNED ARITHMETIC OPERATIONS


AIM: To write assembly language programs for performing following arithmetic operations. I) Signed multi byte multiplication II) Signed multi byte division APPARATUS: Computer with TASM/MASM software I)Algorithm for Multiplying two multi byte signed numbers and store the result as the third signed number 1. Store the count. 2. Initialize the source index which contains the first source address. 3. Initialize the source index which contains the second source address 4. Initialize a register which contains the address at where the result has to be stored 5. Get the value from source1 memory to accumulator. 6. Perform multiplication on first and second sources 7. Put the result in allocated memory location 8. Increment the source1 register address. 9. Increment the source2 register address 10. Increment the register which contains address of result memory location . 11. End of the program execution. PROGRAM: DATA SEGMENT BYTES EQU 08H NUM1 DB 0FBH, 0F6H, 0F4H,0F4H,0FBH,0FA H, 0F9H NUM2 DB 0FCH, 0FCH, 0FCH, 0FBH, 0CEH, 0EEH, 0E7H NUM3 DB 07H DUP (00) DATA ENDS CODE SEGMENT ASSUME CS:CODE, DS:DATA
SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 26

Dept. of E.C.E START: MOV AX,DATA MOV DS,AX MOV CX,BYTES LEA SI,NUM1 LEA DI,NUM2 LEA BX,NUM3 MOV AX,00 NEXT: MOV AL,[SI] MOV DL,[DI] IMUL DL MOV [BX], AL MOV [BX+1],AH INC SI INC DI INC BX INC BX DEC CX JNZ NEXT INT 3H CODE ENDS END START

Microprocessor & Microcontrollers Lab

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 27

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

Machine code Address mechine code 5C9F:0000 B89D5C 5C9F:0003 8ED8 5C9F:0005 B90800 5C9F:0008 BE0000 5C9F:000B BF0700 mnemonics operands MOV MOV MOV MOV MOV AX,5C9D DS,AX CX,0008 SI,0000 DI,0007

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 28

Dept. of E.C.E 5C9F:000E BB0E00 5C9F:0011 B80000 5C9F:0014 8A04 5C9F:0016 8A15 5C9F:0018 F6EA 5C9F:001A 8807 5C9F:001C 886701 5C9F:001F 46 5C9F:0018 F6EA 5C9F:001A 8807 5C9F:001C 886701 5C9F:001F 46 5C9F:0020 47 5C9F:0021 43 5C9F:0022 43 5C9F:0023 49 5C9F:0024 75EE 5C9F:0026 CC MOV MOV MOV MOV BX,000E AX,0000 AL,[SI] DL,[DI]

Microprocessor & Microcontrollers Lab

IMUL DL MOV MOV INC [BX],AL [BX+01],AH SI

IMUL DL MOV MOV INC INC INC INC DEC JNZ INT [BX],AL [BX+01],AH SI DI BX BX CX 0014 3

INPUTS: NUM1 DB 0FBH, 0F6H, 0F4H,0F4H,0FBH,0FA H, 0F9H NUM2 DB 0FCH, 0FCH, 0FCH, 0FBH, 0CEH, 0EEH, 0E7H OUTPUT: NUM3 DB 0028H, 0030H, 003C H, 00FAH, 006CH, 00AFH,FF B0H II)Algorithm for dividing two Signed numbers and store the result as the third signed number: 1. Store the count. 2. Initialize the source index which contains the first source address. 3. Initialize the source index which contains the second source address 4. Initialize a register which contains the address at where the result has to be stored 5. Get the value from source1 memory to accumulator.
SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 29

Dept. of E.C.E 6. Perform division on first and second sources 7. Put the result in allocated memory location 8. Increment the source1 register address. 9. Increment the source2 register address

Microprocessor & Microcontrollers Lab

10. Increment the register which contains address of result memory location . 11. End of the program execution. PROGRAM: DATA SEGMENT DATA ENDS CODE SEGMENT ASSUME CS:CODE, DS:DATA START: MOV AX,DATA MOV DS,AX MOV AX,6715H MOV BX,086AH IDIV BX INT 3H CODE ENDS END START

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 30

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

Machine code Address 68E1:0000 68E1:0003 68E1:0005 68E1:0008 68E1:000B 68E1:000D INPUT: machine code B8E168 8ED8 B81567 BB6A08 F7FB CC AX=6715 BX=086A BX=086A DX=021D mnemonics operands MOV MOV MOV MOV IDIV INT AX,68E1 DS,AX AX,6715 BX,086A BX 3

OUTPUT: AX=000C RESULT:

The assembly language programs for performing arithmetic operations were written and executed successfully. Viva-Voice: 1. Write instructions which perform addition operation in direct addressing, indirect addressing? 2. What are the flags effected after executing ADD instruction? 3. What is the difference between ADD&ADC instruction? 4. What are the flags effected after executing MOV BX, 1230 instruction?
SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 31

Dept. of E.C.E 5. What is the difference between SUB,SBB instruction?

Microprocessor & Microcontrollers Lab

6. What are the flags effected after execution of HLT instruction ? 7. What are the flags effected after execute up ADD AX,DX instruction (Assume: AX=FFFFh,DX=0001h)? 8. What is the difference between MOV DX,[1050],MOV DX,1050?

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 32

Dept. of E.C.E

Microprocessor & Microcontrollers Lab 2(C) ASCII OPERATIONS

AIM: To write assembly language programs for performing following ASCII operations. I)ASCII addition II)ASCII subtraction III) ASCII multiplication IV)ASCII division APPARATUS: Computer with TASM/MASM software I)Algorithm for ASCII Addition: 1. Store a ASCII value1 in one register. 2. Store a ASCIIvalue2 in one register. 3. Perform addition between two registers. 4. Perform ASCII ADJUST AFTER ADDITION operation. 5. Perform addition source register with 3030h . 6. End of the program execution. PROGRAM: CODE SEGMENT ASSUME CS: CODE START: MOV AL,5 MOV BL,9 ADD AL, BL AAA OR AX, 3030H INT 3H CODE ENDS END START

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 33

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

Machine code Address 5C79:0000 5C79:0002 5C79:0004 5C79:0006 5C79:0007 machine code B005 B309 02C3 37 0D3030 mnemonics operands MOV MOV ADD AAA OR AX,3030
Page 34

AL,05 BL,09 AL,BL

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Dept. of E.C.E 5C79:000A CC INT 3

Microprocessor & Microcontrollers Lab

INPUTS: AL=5 BL=9 OUTPUTS: AX=3134 II)Algorithm for ASCII Subtraction: 1. Store an ASCII value1 in one register. 2. Store an ASCIIvalue2 in one register. 3. Perform addition between two registers. 4. Perform ASCII ADJUST AFTER SUBTRACTION operation. 5. Perform addition source register with 3030h. 6. End of the program execution. PROGRAM: CODE SEGMENT ASSUME CS: CODE START: MOV AL,9 MOV BL,5 SUB AL, BL AAS OR AX, 3030H INT 3H CODE ENDS END START

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 35

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

Machine code Address 5C79:0000 5C79:0002 5C79:0004 5C79:0006 5C79:0007 machine code B009 B305 2AC3 3F 0D3030 mnemonics operands MOV MOV SUB AAS OR AX,3030
Page 36

AL,09 BL,05 AL,BL

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Dept. of E.C.E 5C79:000A INPUTS: AL=9 CC BL=5 INT 3

Microprocessor & Microcontrollers Lab

OUTPUTS: AX=3034 III)Algorithm for ASCII Multiplication: 1. Store a ASCII value1 in one register. 2. Store a ASCIIvalue2 in one register. 3. Perform addition between two registers. 4. Perform ASCII ADJUST AFTER MULTIPLICATION operation. 5. Perform addition source register with 3030h . 6. End of the program execution. PROGRAM: CODE SEGMENT ASSUME CS: CODE START: MOV AL, 5 MOV BL, 9 MUL BL AAM OR AX, 3030H INT 3H CODE ENDS END START

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 37

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

Machine code Address 5C79:0000 5C79:0002 5C79:0004 5C79:0006 5C79:0008 machine code B005 B309 F6E3 D40A 0D3030 mnemonics operands MOV MOV MUL AAM OR AX,3030
Page 38

AL,05 BL,09 BL

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Dept. of E.C.E 5C79:000B INPUTS: AL=5 CC BL=9 INT 3

Microprocessor & Microcontrollers Lab

OUTPUTS: AX=3435 IV)Algorithm for ASCII Division: 1. Store a ASCII value1 (unpacked form) in one register. 2. Store a ASCIIvalue2 in one register. 3. Perform addition between two registers. 4. Perform ASCII ADJUST BEFORE DIVISION operation. 5. Perform addition source register with 3030h . 6. End of the program execution. PROGRAM: CODE SEGMENT ASSUME CS: CODE START: MOV AX, 0607H MOV CH, 09H AAD DIV CH OR AX, 3030H INT 3H CODE ENDS END START

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 39

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

Machine code Address 68FC:0000 68FC:0003 68FC:0005 68FC:0007 68FC:0009 machine code B80706 B509 D50A F6F5 0D3030 mnemonics operands MOV MOV AAD DIV OR CH AX,3030
Page 40

AX,0607 CH,09

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Dept. of E.C.E 68FC:000C CC INT 3

Microprocessor & Microcontrollers Lab

INPUTS: AX=0607H, CH=09H OUTPUTS: AX=313 RESULT: The assembly language programs for performing ASCII operations were written and executed successfully. Viva-Voice: 1. Write instructions which perform ASCII addition operation? 2. What are the flags effected after executing AAA instruction? 3. What is the difference between ADD&AAA Instruction? 4. What are the flags effected after execution of HLT instruction?

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 41

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

3. LOGICAL OPERATIONS
AIM :To write assembly language programs for performing following logical operations. I. II. III. IV. V. VI. VII. AND OPERETION OR OPERETION XOR OPERETION NOT OPERETION NAND OPERETION PACKED BCD TO UNPACKED BCD CONVERSIONS BCD TO ASCII CONVERSIONS

APPARATUS:Computer with TASM/MASM softeare I)Algorithm for Logical AND: 1. Store a value1 in one register. 2. Store a value2 in one register. 3. Perform logical AND operation between two registers contents. 4. End of the program execution. PROGRAM CODE SEGMENT ASSUME CS: CODE START: MOV AL, 85H MOV BL, 99H AND AL, BL INT 3H CODE ENDS END START

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 42

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

Machine code Address 68FC:0000 68FC:0002 68FC:0004 68FC:0006 machine code B085 B399 22C3 CC mnemonics MOV MOV AND INT operands AL,85 BL,99 AL,BL 3

INPUTS: AL = 85H, BL=99H OUTPUTS: AL= 81H II)Algorithm for Logical OR: 1. Store a value1 in one register. 2. Store a value2 in one register.
SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 43

Dept. of E.C.E 3. Perform logical OR operation between two registers contents. 4. End of the program execution. PROGRAM: CODE SEGMENT ASSUME CS: CODE START: MOV AL, 85H MOV BL, 99H OR AL, BL INT 3H CODE ENDS END START

Microprocessor & Microcontrollers Lab

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 44

Dept. of E.C.E Machine code Address 68E5:0000 68E5:0002 68E5:0004 68E5:0006 machine code B085 B399 0AC3 CC mnemonics operands MOV MOV OR INT AL,85 BL,99 AL,BL 3

Microprocessor & Microcontrollers Lab

INPUTS: AL=85H,BL=99H OUTPUTS: AL=9DH III)Algorithm for Logical XOR: 1. Store a value1 in one register. 2. Store a value2 in one register. 3. Perform logical XOR operation between two registers contents. 4. End of the program execution. PROGRAM: CODE SEGMENT ASSUME CS: CODE START: MOV AL, 85H MOV BL, 99H XOR AL, BL INT 3H CODE ENDS END START

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 45

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

Machine code Address 68E5:0000 68E5:0002 68E5:0004 68E5:0006 machine code B085 B399 32C3 CC mnemonics operands MOV MOV XOR INT AL,85 BL,99 AL,BL 3

INPUTS: AL=85H, BL=99H OUTPUTS: AL=1CH IV)Algorithm for Logical NOT: 1. Store a value1 in one register. 2. Store a value2 in one register.
SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 46

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

3. Perform logical NOT operation between two registers contents. 4. End of the program execution. PROGRAM: CODE SEGMENT ASSUME CS: CODE START: MOV AL, 85H NOT AL INT 3H CODE ENDS END START

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 47

Dept. of E.C.E Machine code Address 68E5:0000 68E5:0002 68E5:0004 machine code B085 F6D0 CC mnemonics operands MOV NOT INT AL,85 AL 3

Microprocessor & Microcontrollers Lab

INPUTS: AL=85H, BL=99H OUTPUTS: AL=7AH V)Algorithm for Logical NAND: 1. Store a value1 in one register. 2. Store a value2 in one register. 3. Perform logical NAND operation between two registers contents. 4. End of the program execution. PROGRAM: CODE SEGMENT ASSUME CS: CODE START: MOV AL, 85H MOV BL, 99H AND AL, BL NOT AL INT 3H CODE ENDS END START

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 48

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

Machine code Address 68E5:0000 68E5:0002 68E5:0004 68E5:0006 68E5:0008 INPUTS: AL=85H OUTPUTS: AL=7EH machine code B085 B399 22C3 F6D0 CC mnemonics operands MOV MOV AND NOT INT AL,85 BL,99 AL,BL AL 3

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 49

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

VI)Algorithm For Converting Packed BCD to unpacked BCD: 1. Store the 8-bit value in lower byte of accumulator(AL). 2. Copy lower byte of accumulator into higher byte of register (AH). 3. Load 04 in CH register 4. Perform shift right operation of AH register content with account available in CH register . 5. Perform AND operation AX WITH 0F0Fh. 6. End of the program execution. PROGRAM: DATA SEGMENT NUM DB 45H DATA ENDS CODE SEGMENT ASSUME CS: CODE, DS: DATA START: MOV AX, DATA MOV DS, AX MOV AL, NUM MOV AH, AL MOV CL, 4 SHR AH, CL AND AX, 0F0FH INT 3H CODE ENDS END START

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 50

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

Machine code Address 68E6:0000 68E6:0003 68E6:0005 68E6:0008 68E6:000A 68E6:000C 68E6:000E 68E6:0011 INPUTS: AL=45H OUTPUTS: AX=0405
SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 51

machine code B8E568 8ED8 A00000 8AE0 B104 D2EC 250F0F CC

mnemonics operands MOV MOV MOV MOV MOV SHR AND INT 3 AX,68E5 DS,AX AL,[0000] AH,AL CL,04 AH,CL AX,0F0F

Dept. of E.C.E VII)Algorithm for Converting Converting BCD to ASCII: 1. Store the 8-bit value in lower byte of accumulator (AL).

Microprocessor & Microcontrollers Lab

2. Copy lower byte of accumulator into higher byte of Register (AH). 3. Load 04 in CH register 4. Perform shift right operation of AH register content with account available in CH Register. 5. Perform AND operation AX WITH 0F0Fh. 6. Perform OR operation with AX and 3030h 7. End of the program execution. PROGRAM: DATA SEGMENT NUM DB 45H DATA ENDS CODE SEGMENT ASSUME CS: CODE, DS: DATA START: MOV AX, DATA MOV DS, AX MOV AX, NUM MOV AH, AL MOV CL, 4 SHR AH, CL AND AX, 0F0FH OR AX, 3030H INT 3H CODE ENDS END START

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 52

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

Machine code Address 68DE:0000 68DE:0003 68DE:0005 68DE:0008 68DE:000A machine code B8DD68 8ED8 A00000 8AE0 B104 mnemonics operands MOV MOV MOV MOV MOV AX,68DD DS,AX AL,[0000] AH,AL CL,04
Page 53

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Dept. of E.C.E 68DE:000C 68DE:000E 68DE:0011 68DE:0014 INPUTS: AL=45H OUTPUTS: AX=3435 RESULT: D2EC 250F0F 0D3030 CC SHR AND OR INT AH,CL AX,0F0F AX,3030 3

Microprocessor & Microcontrollers Lab

The assembly programs for logical operations were written and executed successfully. Viva voice: 1. Explain the operation of XOR logic instruction. 2. What is the difference between PACKED BCD,UNPACKED BCD 3. What is meant by masking

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 54

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

4(A) STRING OPERATIONS


AIM: To write assembly language programs for performing following string operations. I) Move a Block of String II) String Reversal III) Strings Comparison IV) String Length V) Insertion Of Character VI) Deletion Of Character APPARATUS: Computer with TASM/MASM software I)Algorithm for Moving a Block using strings 1. Store the data in some memory location in data segment 2. Initialize the register which contains the source address in DATA SEGMENT. 3. Initialize the register which contains the destination address in EXTRA SEGMENT. 4. Store the count. 5. Perform the CLD (clear the direction flag). 6. Perform repeat operation. 7. Use MOVSB instruction to move the contents from one location to another location. 8. End of the program execution. PROGRAM: DATA SEGMENT SRC DB MICROPROCESSOR DB 10 DUP (?) DST DB 20 DUP (0) DATA ENDS CODE SEGMENT ASSUME CS: CODE, DS: DATA, ES: DATA START: MOV AX, DATA
SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 55

Dept. of E.C.E MOV DS, AX MOV ES, AX LEA SI, SRC LEA DI, DST MOV CX, 20 CLD REP MOVSB INT 3H CODE ENDS END START

Microprocessor & Microcontrollers Lab

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 56

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

Machine code Address 68E0:0000 68E0:0003 68E0:0005 68E0:0007 68E0:000A 68E0:000D 68E0:0010 68E0:0011 68E0:0012 68E0:0013 machine code B8DD68 8ED8 8EC0 BE0000 BF1800 B91400 FC F3 A4 CC mnemonics operands MOV MOV MOV MOV MOV MOV CLD REPZ MOVSB INT 3 AX,68DD DS,AX ES,AX SI,0000 DI,0018 CX,0014

INPUTS: SRC DB MICROPROCESSOR OUTPUTS: DST DB MICROPROCESSOR II)Algorithm For String reversal 1. Store the data in some memory location in data segment 2. Initialize a register which contain the source address in DATA SEGMENT.

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 57

Dept. of E.C.E 3. Initialize a register which contain the destination address. 4. Store the count. Add the count to source register to get the last value. 5. Get the value from source location to one register

Microprocessor & Microcontrollers Lab

6. Store the value from that register to destination location specified by destination register. 7. Decrement source register 8. Increment destination register 9. Decrement count, 10. If the count is not zero repeat the steps 5, 6,7,8,9 operations. 11. End of the program execution. PROGRAM: DATA SEGMENT ORG 2000H SRC DB MICROPROCESSOR$ COUNT EQU ($-SRC) DEST DB? DATA ENDS CODE SEGMENT ASSUME CS: CODE,DS:DATA START: MOV AX, DATA MOV DS, AX MOV CX, COUNT LEA SI,SRC LEA DI,DEST ADD SI,CX DEC CX BACK: MOV AL,[SI]
SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 58

Dept. of E.C.E MOV [DI],AL DEC SI INC DI DEC CX JNZ BACK INT 3H CODE ENDS END START

Microprocessor & Microcontrollers Lab

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 59

Dept. of E.C.E Machine code Address 6ADE:0000 6ADE:0003 6ADE:0005 6ADE:0008 6ADE:000B 6ADE:000E 6ADE:0010 6ADE:0011 6ADE:0013 6ADE:0015 6ADE:0016 6ADE:0017 6ADE:0018 6ADE:001A 6ADE:001B 6ADE:001E 6ADE:001F E882CC INPUTS: OUTPUTS: machine code B8DD68 8ED8 B90E00 BE0020 BF0E20 03F1 49 8A04 8805 4E 47 49 75F7 CC 207501 C3 CALL mnemonics operands MOV MOV MOV MOV MOV ADD DEC MOV MOV DEC INC DEC JNZ INT AND RET CCA4 AX,68DD DS,AX CX,000E SI,2000 DI,200E SI,CX CX AL,[SI] [DI],AL SI DI CX 0011 3 [DI+01],DH

Microprocessor & Microcontrollers Lab

SRC DB MICROPROCESSOR$ DEST DB $ROSSECORPORCIM

III) Algorithm for Comparison of two Strings 1. Store one string in data segment and one string in extra segment 2. Initialize the register which contains the source address in DATA SEGMENT. 3. Initialize the register which contains the destination address in EXTRA SEGMENT. 4. Store the count. 5. Perform the CLD (clear the direction flag).
SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 60

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

6. Perform REPE CMPSB instructions for comparing the two string contents one by one 7. If they are not equal give output as STRINGS R NOT EQUAL$ other wise STRINGS R EQUAL$ 8.STOP PROGRAM: PRINTSTRING MACRO MSG MOV AH, 09H LEA DX, MSG INT 21H ENDM DATA SEGMENT ORG 2000H STR1 DB MICROPROCESSORS LEN EQU ($-STR1) STR2 DB MICROPROCSSOR M1 DB STRINGS R EQUAL$ M2 DB STRINGS R NOT EQUAL$ DATA ENDS CODE SEGMENT ASSUME CS: CODE, DS: DATA, ES: DATA START: MOV AX, DATA MOV DS, AX MOV ES,AX LEA SI,STR1 LEA DI, STR2 MOV CX, LEN CLD
SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 61

Dept. of E.C.E REPE CMPSB JNE FAIL PRINTSTRING M1 INT 3H FAIL: PRINTSTRING M2 INT 3H CODE ENDS END START

Microprocessor & Microcontrollers Lab

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 62

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

Machine code Address 6AE1:0000 6AE1:0003 6AE1:0005 6AE1:0007 6AE1:000A 6AE1:000D 6AE1:0010 6AE1:0011 6AE1:0012 6AE1:0013 6AE1:0015 6AE1:0017 6AE1:001A 6AE1:001C 6AE1:001D machine code B8DD68 8ED8 8EC0 BE0020 BF0F20 B90F00 FC F3 A6 7508 B409 BA1C20 CD21 CC B409 mnemonics operands MOV MOV MOV MOV MOV MOV CLD REPZ CMPSB JNZ MOV MOV INT INT MOV 001D AH,09 DX,201C 21 3 AH,09
Page 63

AX,68DD DS,AX ES,AX SI,2000 DI,200F CX,000F

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Dept. of E.C.E 6AE1:001F BA2B20 MOV DX,202B

Microprocessor & Microcontrollers Lab

INPUTS: STR1 DB MICROPROCESSORS STR2 DB MICROPROCSSOR OUTPUTS: M2 DB STRINGS R NOT EQUAL IV)Algorithm for a program that reads a string from keyboard and displays the length of the string on screen. 1. Initialize the data segment 2. Move data in to ax register 3. Call the macro for display operation 4. Read the key 5. Check the key whether it was predefined key or not 6. If It Was Not CR Key Then Increment Count, Read A Key Until Cr Was Pressed 7. If It Was CR Key then go to display macro 8. Increment the counter value and convert the pressed key from hex to ASCII PROGRAM DISP MACRO MSG MOV AH,09H MOV DX,OFFSET MSG INT 21H ENDM DATA SEGMENT CR EQU 0DH LF EQU 0AH LEN DB 04 DUP(0) MSG1 DB 10,13, 'ENTER THE STRING INPUT: ', '$' MSG2 DB CR,LF, 'THE LENTH OF THE STRING INPUT: ', '$' DATA ENDS
SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 64

Dept. of E.C.E CODE SEGMENT ASSUME CS:CODE; DS:DATA START: MOV AX,DATA MOV DS,AX DISP MSG1

Microprocessor & Microcontrollers Lab

MOV CX,00H;COUNT FOR LENGTH OF INPUT STRING RDKEY:MOV AH,01H INT 21H CMP AL,CR ;IF TYPED KEY IS NOT CR (ENTER KEY) JE AHEAD INC CX ; INCREMENT COUNT

JMP RDKEY ;READ A KEY UNTIL CR WAS PRESSED AHEAD:DISP MSG2 MOV SI,OFFSET LEN MOV AX,CX CALL PROC HEXA2ASCI ; CALL A NEAR PROCEDURE DISP LEN MOV AX,4C00H INT 21H CODE ENDS END START HEXA2ASCI PROC NEAR MOV BX,00H MOV DX,00H DIV BX ADD DL, '0' ADD AL,'0'
SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 65

Dept. of E.C.E MOV [SI],AL MOV [SI+1],DL MOV AL,'$' MOV [SI+2],AL RET HEXA2ASCI ENDP

Microprocessor & Microcontrollers Lab

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 66

Dept. of E.C.E Machine code Address 6900:0000 6900:0003 6900:0005 6900:0007 6900:000A 6900:000C 6900:000F 6900:0011 6900:0013 6900:0015 6900:0017 6900:0018 6900:001A 6900:001C 6900:001F machine code B8FB68 8ED8 B409 BA0400 CD21 B90000 B401 CD21 3C0D 7403 41 EBF5 B409 BA2000 CD21 mnemonics operands MOV MOV MOV MOV INT MOV MOV INT CMP JZ INC JMP MOV MOV INT AX,68FB DS,AX AH,09 DX,0004 21 CX,0000 AH,01 21 AL,0D 001A CX 000F AH,09 DX,0020 21

Microprocessor & Microcontrollers Lab

INPUT: ENTER STRING: SITE OUTPUT: LENGTH OF THE SITE IS 04 V)Algorithm to insert a character at the end of given string 1. Initialize the data segment ,segment registers 2. Copy the inserted character in al register 3. Compare AL,,SI 4. If both are equal(ZF=1) then put the character in si 5. Else increment the si value and repeat the process the until counter is zero PROGRAM: ASSUME CS:CODE,DS:DATA DATA SEGMENT
SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 67

Dept. of E.C.E CHAR DB 'F'; CHARACTER TO BE INSERTED STRNG DB 'ABCDE','$' DATA ENDS CODE SEGMENT START: MOV AX,DATA MOV DS,AX LEA SI,STRNG ;POINT TO STRING NXT: MOV AL,[SI] ;CHECK FOR END OF THESTRING CMPAL,'$' JE INSERT ;If String Is At The End Insert Character INC SI JMP NXT INSERT: MOV BL,CHAR MOV [SI],BL INC SI MOV BL,'$' MOV [SI],BL MOV AH,4CH INT 21H CODE ENDS END START REINSERT

Microprocessor & Microcontrollers Lab

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 68

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

Machine code Address 68FC:0000 68FC:0003 68FC:0005 68FC:0008 68FC:000A 68FC:000C machine code B8FB68 8ED8 BE0100 8A04 3C24 7403 mnemonics operands MOV MOV MOV MOV CMP JZ AX,68FB DS,AX SI,0001 AL,[SI] AL,24 0011

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 69

Dept. of E.C.E 68FC:000E 68FC:000F 68FC:0011 68FC:0015 68FC:0017 68FC:0018 68FC:001A 68FC:001C 68FC:001E 46 EBF7 8A1E0000 881C 46 B324 881C B44C CD21 INC JMP MOV MOV INC MOV MOV MOV INT SI 0008 BL,[0000] [SI],BL SI BL,24 [SI],BL AH,4C 21

Microprocessor & Microcontrollers Lab

INPUTS: BEFORE EXECUTING PROGRAM STRNG IS ABCDE$ OUTPUTS: AFTER EXECUTING STRING IS ABCDEF$ VI) Algorithm to delete first character of given string 1. Initialize the data segment ,segment registers 2. Exchange the values of [SI] , [SI+1] using ax as intermediate register. 3. Increment SI 4. Repeat the process up to counter is nonzero. 5. Put $ in the address of SI. PROGRAM: ASSUME CS:CODE, DS:DATA DATA SEGMENT STRNG DB 'ABCD',24H SLEN EQU ( $ - STRNG) ;LENGTH OF THE STRING DATA ENDS CODE SEGMENT START: MOV AX,DATA MOV DS,AX MOV CX,SLEN DEC CX MOV SI,OFFSET STRNG
SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 70

Dept. of E.C.E NXT:MOV AL,[SI+1] MOV [SI],AL INC SI DEC CX JNZ NXT MOV AH,4CH INT 21H CODE ENDS END START

Microprocessor & Microcontrollers Lab

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 71

Dept. of E.C.E Machine code Address 68FC:0000 68FC:0003 68FC:0005 68FC:0008 68FC:0009 68FC:000C 68FC:000F 68FC:0011 68FC:0012 68FC:0013 68FC:0015 68FC:0017 68FC:0019 68FC:001B 68FC:001D 68FC:001E INPUTS: ABCD OUTPUTS: BCD RESULT: machine code B8FB68 8ED8 B90500 49 BE0000 8A4401 8804 46 49 75F7 B44C CD21 2488 1CB4 4C CD21 mnemonics operands MOV MOV MOV DEC MOV MOV MOV INC DEC JNZ MOV INT AND SBB DEC INT AX,68FB DS,AX CX,0005 CX SI,0000

Microprocessor & Microcontrollers Lab

AL,[SI+01] [SI],AL SI CX 000C AH,4C 21 AL,88 AL,B4 SP 21

The programs for performing string operations were written and executed successfully. Viva voice: 1. 2. 3. 4. What is the purpose of SI register in program? What is the addressing mode of MOV AL,[SI] instruction? what is the addressing mode of MOV DI,2002 instruction? what is the difference between CMP AX,DX and SUB AX,DX instructions?

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 72

Dept. of E.C.E

Microprocessor & Microcontrollers Lab 4(B) STRING SORTING OPERATIONS

AIM: To write assembly language programs for performing following string operations. I) 16-bit unsigned ASCENDING ORDER): II) 16-bit signed ASCENDING ORDER III) 16-bit unsigned DECENDING ORDER): IV) 16-bit signed DECENDING ORDER APPARATUS: Computer with TASM/MASM software I)Algorithm for Sorting (16-bit unsigned ASCENDING ORDER): 1. Start the program. 2. Move count to CL register & copy the value into CH 3. Initialize source index register (SI) 4. Compare the content of AX with content in the incremented SI 5. If the carry flag is SET then exchange the contents of AX and incremented SI 6. Increment SI by two 7. Decrement the count by one 8. Repeat the same procedure until the count equal to zero. 9. Stop the program PROGRAM: DATA SEGMENT NUM DW 3497H,1110H, 5478H ,2213H CNT EQU DB 03H DATA ENDS CODE SEGMENT ASSUME CS: CODE, DS: DATA, ES: DATA START: MOV AX, DATA MOV DS, AX MOV CX,CNT
SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 73

Dept. of E.C.E LOOP1: MOV CH,CL MOV SI,NUM LOOP2:MOV AX,[SI] CMPAX,2[SI] JC LOOP3 XCHJ AX,2[SI] XCHG AX,[SI] LOOP3:INC SI INC SI DEC CH JNZ LOOP2 DCECL JNZ LOOP1 HLT CODE ENDS END START

Microprocessor & Microcontrollers Lab

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 74

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

Machine code Address 68FC:0000 68FC:0003 68FC:0005 68FC:0007 68FC:0009 68FC:000D 68FC:000F machine code B8FB68 8ED8 B104 8AE9 8B360000 8B04 3B4402 mnemonics operands MOV MOV MOV MOV MOV MOV CMP AX,68FB DS,AX CL,04 CH,CL SI,[0000] AX,[SI] AX,[SI+02]
Page 75

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Dept. of E.C.E 68FC:0012 68FC:0014 68FC:0017 68FC:0019 68FC:001A 68FC:001B 68FC:001D 68FC:001F 7205 874402 8704 46 46 FECD 75EE FEC9 JB 0019

Microprocessor & Microcontrollers Lab

XCHG AX,[SI+02] XCHG AX,[SI] INC INC DEC JNZ DEC SI SI CH 000D CL

INPUTS: 3497H,1110H, 5478H ,2213H OUTPUTS: 0111H,2213H,3497H,5478H II)Algorithm for Sorting (16-bit signed ASCENDING ORDER): 1. Start the program. 2. Move count to CL register & copy the value into CH 3. Initialize source index register (SI) 4. Compare the content of AX with content in the incremented SI 5. If the carry flag is SET then exchange the contents of AX and incremented SI 6. Increment SI by two 7. Decrement the count by one 8. Repeat the same procedure until the count equal to zero. 9. Stop the program PROGRAM: DATA SEGMENT NUM DW EE87H,FCACH,8688H,ABC7H CNT EQU DB 04H DATA ENDS CODE SEGMENT ASSUME CS: CODE, DS: DATA, ES: DATA
SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 76

Dept. of E.C.E START: MOV AX, DATA MOV DS, AX MOV CL,CNT LOOP1: MOV CH,CL MOV SI,NUM LOOP2:MOV AX,[SI] CMP AX,[SI+2] JL LOOP3 XCHG AX,[SI+2] XCHG AX,[SI] LOOP3:INC SI INC SI DEC CH JNZ LOOP2 DCE CL JNZ LOOP1 INT 03 CODE ENDS END START

Microprocessor & Microcontrollers Lab

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 77

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

Machine code Address 68FC:0000 68FC:0003 68FC:0005 68FC:0007 68FC:0009 68FC:000D 68FC:000F 68FC:0012 68FC:0014 68FC:0017 68FC:0019 68FC:001A 68FC:001B 68FC:001D 68FC:001F machine code B8FB68 8ED8 B104 8AE9 8B360000 8B04 3B4402 7C05 874402 8704 46 46 FECD 75EE FEC9 mnemonics operands MOV MOV MOV MOV MOV MOV CMP JL XCHG XCHG INC INC DEC JNZ DEC 000D CL AX,68FB DS,AX CL,04 CH,CL SI,[0000] AX,[SI] AX,[SI+02] 0019 AX,[SI+02] AX,[SI] SI SI CH

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 78

Dept. of E.C.E INPUTS: EE87H,FCACH,8688H,ABC7H OUTPUTS: 8688H,ABC7H,EE87H,FCACH

Microprocessor & Microcontrollers Lab

III)Algorithm for Sorting (16-bit Unsigned DESCENDING ORDER): 1. Start the program. 2. Move count to CL register & copy the value into CH 3. Initialize source index register (SI) 4. Compare the content of AX with content in the incremented SI 5. If the carry flag is SET then exchange the contents of AX and incremented SI 6. Increment SI by two 7. Decrement the count by one 8. Repeat the same procedure until the count equal to zero. 9. Stop the program PROGRAM: DATA SEGMENT NUM DW 3497H,1101H,5478H,2213H CNT EQU 04H DATA ENDS CODE SEGMENT ASSUME CS: CODE, DS: DATA, ES: DATA START: MOV AX, DATA MOV DS, AX MOV CX,CNT LOOP1: MOV CH,CL MOV SI,NUM LOOP2:MOV AX,[SI] CMPAX,2[SI] JNL LOOP3 XCHJ AX,2[SI]
SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 79

Dept. of E.C.E XCHG AX,[SI] LOOP3:INC SI INC SI DEC CH JNZ LOOP2 DCECL JNZ LOOP1 INT 03 CODE ENDS END START

Microprocessor & Microcontrollers Lab

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 80

Dept. of E.C.E Machine code Address 68FC:0000 68FC:0003 68FC:0005 68FC:0008 68FC:000A 68FC:000E 68FC:0010 68FC:0013 68FC:0015 68FC:0018 68FC:001A 68FC:001B 68FC:001C 68FC:001E machine code B8FB68 8ED8 B90400 8AE9 8B360000 8B04 3B4402 7F05 874402 8704 46 46 FECD 75EE mnemonics operands MOV MOV MOV MOV MOV MOV CMP JG XCHG XCHG INC INC DEC JNZ S000E SI SI CH 001A

Microprocessor & Microcontrollers Lab

AX,68FB DS,AX CX,0004 CH,CL SI,[0000] AX,[SI] AX,[SI+02]

AX,[SI+02] AX,[SI]

INPUT:3497H,1101H,5478H,2213H OUTPUT:5478H3497H,2213H,1101 IV)Algorithm for Sorting (16-bit signed DESCENDING ORDER): 1. Start the program. 2. Move count to CL register & copy the value into CH 3. Initialize source index register (SI) 4. Compare the content of AX with content in the incremented SI 5. If the carry flag is SET then exchange the contents of AX and incremented SI 6. Increment SI by two 7. Decrement the count by one 8. Repeat the same procedure until the count equal to zero.
SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 81

Dept. of E.C.E 9. Stop the program PROGRAM: DATA SEGMENT NUM DW EE87H,FCACH,8688H,ABC7H CNT EQU 04H DATA ENDS CODE SEGMENT ASSUME CS: CODE, DS: DATA, ES: DATA START: MOV AX, DATA MOV DS, AX MOV CX,CNT LOOP1: MOV CH,CL MOV SI,NUM LOOP2:MOV AX,[SI] CMPAX,2[SI] JG LOOP3 XCHJ AX,2[SI] XCHG AX,[SI] LOOP3:INC SI INC SI DEC CH JNZ LOOP2 DCECL JNZ LOOP1 INT 03 CODE ENDS END START

Microprocessor & Microcontrollers Lab

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 82

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

Machine code Address 68FC:0000 68FC:0003 68FC:0005 68FC:0008 68FC:000A 68FC:000E machine code B8FB68 8ED8 B90400 8AE9 8B360000 8B04 mnemonics operands MOV MOV MOV MOV MOV MOV AX,68FB DS,AX CX,0004 CH,CL SI,[0000] AX,[SI]
Page 83

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Dept. of E.C.E 68FC:0010 68FC:0013 68FC:0015 68FC:0018 68FC:001A 68FC:001B 68FC:001C 68FC:001E 3B4402 7D05 874402 8704 46 46 FECD 75EE CMP JGE AX,[SI+02] 001A

Microprocessor & Microcontrollers Lab

XCHG AX,[SI+02] XCHG AX,[SI] INC INC DEC JNZ SI SI CH 000E

INPUT:EE87H,FCACH,8688H,ABC7H OUTPUT: FCACH, EE87H, ABC7H, 8688H, RESULT: The programs for performing strings sorting operations were written and executed successfully. Viva voice: 1. 2. 3. 4. What is the purpose of SI register in program? What is the addressing mode of MOV AL,[SI] instruction? what is the addressing mode of MOV DI,2002 instruction? what is the difference between CMP AX,DX and SUB AX,DX instructions?

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 84

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

5. MODULAR PROGRAM
AIM: To write assembly language program converting BCD to binary number using modular programs. APPARATUS: Computer with TASM/MASM software Algorithm To call a near procedure for converting a BCD number into binary number 1. Initialize the data segment 2. Load the offset value of variable in to stack 3. Move the BCD value in to al 4. Call BCD2BIN procedure 5. Mask lower, higher nibble of BL,AL registers 6. Rotate right AL 4 times 7. Move 0A in to BH register 8. Multiply AH,BH 9. Add AL,BL 10. AL contains binary no PROGRAM DATA SEGMENT BCD DB 17 BIN DB ? DATA ENDS STACK SEGMENT DW 100 DUP(0) TOP LABEL WORD STAK ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA,SS:STAK START: MOV AX,DATA MOV DS,AX ;Initialization Of data segment MOV AX,STACK
SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 85

Dept. of E.C.E MOV SS,AX; Initialization Of Stack Segment MOV SP,OFFSET TOP MOV AL,BCD CALL BCD2BIN MOV BIN,AL JMP EXIT ;THIS IS A NEAR PROCEDURE NUMBERINTO ;A BINARY NUMBER BCD2BIN PROC NEAR PUSHF PUSHBX PUSH CX MOV BL,AL AND BL,0FH ;MASK LOWERNIBBLE AND AL,F0H ;MASK HIGHER NIBBLE MOV CL,04 ROR AL,CL MOV BH,0AH ;MULTIPLYWITH 10 MUL BH ADD AL,BL POP CX POP BX POPF RET BCD 2 BIN ENDP EXIT: MOV AH,4CH INT 21H WHICH

Microprocessor & Microcontrollers Lab

CONVERTS

GIVEN

BCD

; END OF THE PROCEDURE

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 86

Dept. of E.C.E CODE ENDS END START

Microprocessor & Microcontrollers Lab

Machine code Address 6909:0000 6909:0003 6909:0005 6909:0008 machine code B8FB68 8ED8 B8FC68 8ED0 mnemonics operands MOV MOV MOV MOV AX,68FB DS,AX AX,68FC SS,AX
Page 87

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Dept. of E.C.E 6909:000A 6909:000D 6909:0010 6909:0013 6909:0016 6909:0018 6909:0019 6909:001A 6909:001B 6909:001C 6909:001E BC0000 A00000 E80600 A20100 EB1B 90 9C 53 51 8AD8 80E30F MOV MOV SP,0000 AL,[0000]

Microprocessor & Microcontrollers Lab

CALL 0019 MOV JMP NOP PUSHF PUSH PUSH MOV BX CX BL, AL [0001],AL 0033

AND BL, 0F

INPUT: BCD IN CL 17 OUTPUT: BIN IN BL 11H RESULT: The assembly language program for converting BCD no in to binary using modular program was written and executed successfully. Viva voice: 1. What is the function of procedure? 2. Which instructions can be used to call procedure?

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 88

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

6.DOS/BIOS PROGRAMMING
AIM: To write assembly language program for character reading from key board using DOS/BIOS programs. I) Algorithm for read a character from keyboard with Echo II)Algorithm for reading a Key without Echo III)Algorithm to read a string of 10 characters into a buffer from keyboard. APPARATUS: Computer with TASM/MASM software THEORY: DOS AND BIOS Programming: DOS (Disk operating System), BIOS (Basic I/O System) are used by assembly language to control the personal computer. The function calls control the personal computer .The function calls control everything from reading and writing disk data to managing the keyboard and displays. DOS Function Calls: - In order to use DOS function calls, always place function number into register AH, and load other information into registers. Following is INT 21H, which is software interrupt to execute a DOS function. All function calls use INT 21H, and AH contains function call number. User can access the hardware of PC using DOS subroutine .DOS subroutines are invoked or called via software interrupt INT 21H. BIOS Function Calls: - In addition to DOS Function call INT 21H, some other BIOS function calls are useful in controlling the I/O environment of a computer. BIOS function calls are found Stored in the system and video BIOS ROMs. These BIOS ROM functions directly control the I/O Devices with or without DOS loaded into a system. INT 10H: - The INT 10H BIOS interrupt is often called the video services interrupt because it directly controls the video display in a system .The INT 10H instruction uses AH to select the video service provided by this interrupt. INT 11H: - This function is used to determine the type of equipment installed in the system. INT 12H: - The memory size is returned by the INT 12 H instruction. INT 13H: - This call controls the diskettes, and also fixed or hard disk drives attached to the system. DOS FUNCTIONS: Reading a key with an echo: To read and echo a character, the AH is loaded with DOS function number 01H. This is followed by the INT 21H instruction. Upon return from the INT 21H, the AL register contains the ASCII character typed; the video display also shows the typed character.
SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 89

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

Reading a key without an echo: To read a key without an Echo the AH register is loaded with DOS function number 06H and DL=0FFH to indicate that the function call will read the key board an echo. Read an entire line with an echo: Sometimes it is advantageous to read an entire line of data with one function call. Function call number 0AH reads entire line of information up to 255 characters from the keyboard. It continues to acquire keyboard data until it either enter key (0DH) is typed or the character count expires. Writing to video display: With almost any program, data must be displayed on the video display. We use functions 02H or 06H for displaying one character at a time or function 09H for displaying an entire string of characters. Because function 02H and 06H are identical, we intend to use function 06H because it is also used to read a key. The character string can be of any length and may contain control characters such as carriage return (0DH) and line feed (0AH). Terminate a process: To terminate a process the AH register is loaded with function value 4CH. This function returns control to DOS with the error code saved. DOS / BIOS Programming FUNCTION CALLS SHOULD BE AVAILABLE IN AH REGISTER I) Algorithm for read a character from keyboard with Echo Step 1: Load DOS function call for reading a key Step 2: Execute DOS function call Program: MODEL TINY CODE SEGMENT ASSUME CS:CODE START: MOV AH, 01H INT 21H INT 03 CODE ENDS END START ; exit to DOS ; end of file ; Select function 01H ; access DOS to read key ; Select tiny model ; Start CODE Segment

After execution ASCII equivalent of typed character will be in AL and typed character can be seen on the screen.

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 90

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

II)Algorithm for reading a Key without Echo Step 1: Load DOS function call for reading a key Step 2: Execute DOS function call Program: MODEL TINY CODE SEGMENT START:MOV AH, 07H INT 21H CODE ENDS END START ; end of file ; Select tiny model ; Start CODE Segment ; Read without an echo ; access DOS to read key

After execution AL will have ASCII equivalent of the typed character

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 91

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

III) Algorithm to read a string of 10 characters into a buffer from keyboard. 1. Define Buffer in data segment 2. Initialize length of buffer 3. Load DOS function calls for reading into buffer 4. Execute the DOS function calls Program: MODEL SMALL DATA SEGMENT BUF DB 257 DUP (?) DATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA
SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 92

; Select SMALL Model ; Start data segment ; define buffer

; start code segment

Dept. of E.C.E START: MOV BUF, 12 MOV DX, OFFSET BUF MOV AH, 0AH INT 21H INT 03 CODE ENDS END START ; end of file

Microprocessor & Microcontrollers Lab ; character count of 10 ; address buffer ; read a line ; access DOS to read key

Assembly Language Program after execution:

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 93

Dept. of E.C.E RESULT:

Microprocessor & Microcontrollers Lab

The assembly language programs using DOS/BIOS programs were written and executed successfully. Viva voice: 1. What is the use of BIOS calls? 2. Hw the BIOS calls will work?

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 94

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

7. INTERFACING 8255
AIM: To Write an ALP to generate Sinusoidal Wave Using 8255 APPARATUS: 8086 development board 8255 interfacing card CRO ALGORITHM: 1. Initialize the data segment 2. Load string in to SI register 3. Load SI in to AL 4. For generation of positive peak add 128 to AL register 5. Increment SI 6. Repeate the process 7. For generation of negative peak sub 128 from AL register. 8. Decrement SI 9. Repeate the process PROGRAM DATA SEGMENT SINE DB 0,11,22,33,43,54,63,72,81,90,97,104,109,115,119,122 DB 125,,126,127,126,122,119,115,109,104,97,90,81,72,63,54,43,33,22,11 PA EQU 44A0H CR EQU 44A3H DATA ENDS CODE SEGMENT ASSUME CS: CODE,DS:DATA START: MOV AX, DATA MOV DS, AX MOV DX, CR
SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 95

Dept. of E.C.E MOV AL, 80H OUT DX, AL REPEAT: MOV DX, PA LEA SI, SINE MOV CX, 36 NEXT: MOV AL,[SI] ADD AL, 128 OUT DX, AL INC SI LOOP NEXT MOV CX, 36 LEA SI, SINE NEXT1: MOV AL, 128 MOV AH,[SI] SUB AL, AH OUT DX, AL INC SI LOOP NEXT1 JMP REPEAT MOV AH, 4CH INT 21H CODE ENDS END START Machine code Address 5CC3:0000 5CC3:0003 machine code B8C05C 8ED8 mnemonics operands MOV MOV AX,5CC0 DS,AX

Microprocessor & Microcontrollers Lab

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 96

Dept. of E.C.E 5CC3:0005 5CC3:0008 5CC3:000A 5CC3:000B 5CC3:000E 5CC3:0011 5CC3:0014 5CC3:0016 5CC3:0018 5CC3:0019 5CC3:001A 5CC3:001C 5CC3:001F OUTPUT BAA344 B080 EE BAA044 BE0000 B92400 8A04 0480 EE 46 E2F8 B92400 BE0000 MOV MOV OUT MOV MOV MOV MOV ADD OUT INC LOOP MOV MOV DX,44A3 AL,80 DX, AL DX, 44A0 SI, 0000 CX, 0024 AL, [SI] AL, 80 DX, AL SI 0014 CX, 0024 SI, 0000

Microprocessor & Microcontrollers Lab

RESULT: An ALP to generate Sinusoidal Wave Using 8255 was written and executed successfully. Viva voice: 1. What is meant by PPI 2. What are the operating modes of 8255? 3. What is meant by quantization? 4. What is the formula for duty cycle?

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 97

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

8. SPECIAL INSTRUCTIONS
AIM: an ALP which uses special instructions like SWAP, BIT/BYTE, SET/RESET. APPARATUS: Computer with TASM/MASM software ALGORITHM: 1. INITIALISE AX REGISTER 2. SWAP THE CONTENTS OF AX REGISTER AND EXAMINE THE AX REGISTER 3. DEFINE A BYTE OF DATA FOR COUNT 4. SET CARRY FLAG 5. RESET PARITY FLAG 6. EXAMINTHE FLAGS PROGRAM DATA SEGMENT COUNT DB 01 DUP(02) DATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA START:MOV AX,5500H SWAP AX STC LAHF CLC INT 03 CODE ENDS END START

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 98

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

Machine code Address 68FC:0000 68FC:0002 68FC:0004 68FC:0008 machine code B005 B050 8A0E0000 F9 mnemonics operands MOV MOV MOV STC
Page 99

AL,05 AL,50 CL,[0000]

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Dept. of E.C.E 68FC:0009 68FC:000A INPUT: AL=05 OUTPUT AL=50 CY=0 RESULT: AH=03 9F F8 LAHF CLC

Microprocessor & Microcontrollers Lab

an ALP which uses special instructions like SWAP, BIT/BYTE, SET/RESET was written and executed successfully Viva voice: 1. What is meant by SWAP operation? 2. What is the result when ZF is set to 1? 3. Is there any alternate instruction instead of SET/RESET?

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 100

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 101

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 102

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 103

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

10. INTERFACING 8259


AIM: To Write an ALP to interface 8259 to 8086 microprocessor and process interrupt. APPARATUS: 8086 development board 8259 interfacing card THEORY: DESCRIPTION OF THE MODULE: The Study module card is connected to the 8086 kit through a 50 pin FRC cable. Before making connections check the polarity of the cable. It consists of 8259, switches, debounce switches for single stepping, Buffers and Tags for applying interrupts, Vcc TAGS, LEDS To Display status. The toggle switch at top is for enabling single stepping. Push to ON for single stepping of every instruction. When single stepping enable will show each data transferred in an instruction on the data bus, including chip select, Read, Write, Interrupt and Interrupt Acknowledge Signals. 8259 is connected to IR4

DEMONSTRATION: This is a demonstration in which 8259 will be used in the stand alone mode. Program 1 will be used to illustrate this concept. In the main loop of program, it will be displaying (HELP), and when L to H pulse is applied to IRO line using patch cord in the ISR, it displays IRO Step 1 Connect the 8259 PIC study module through 50 pin FRC cable. Step 2 Enter the program as given Step 3 Enable Single Stepping by Switch of module & kit. Step 4 Execute the Program and observe the results on the LEDs Step 5 0 implies LED is OFF and 1 implies LED is ON DATABUS
SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 104

Dept. of E.C.E Comments START 17 0 1 --- 0 1 ICW1 RD WR INTA 0 A CS STEP 1 00 0 1 --- 1 1 ICW2 STEP 2 01 0 1 --- 1 1 ICW4 STEP 3 FE 0 1 --- 1 1 Enable IR0 STEP 4 FF 1 0 --- 1 - ICW1 for Slave

Microprocessor & Microcontrollers Lab

At this stage WAITING FOR INT will display on the LCD of VMC 8609. Give the interrupt to the study card by connecting IRO (Lower) to VCC. Just after giving the interrupt IRO will display on LCD. Addresses FOR 8086 CPU

IRR ( Interrupt Request Register) - 60 H IMR (Interrupt Mask Register) - 66 H Note : While using 8259 Study Module with 8086 kit switch of all position of SW1 Dip Switch Position. ALGORITHM: 1. initialize Data segment is to zero 2. define interrupt location 3. initialize ICW1 Command in AL and send through OUTPUT port 4. initialize ICW2 Command in AL and send through OUTPUT port 5. initialize ICW4 Command in AL and send through OUTPUT port 6. unmask IRQ0 7. clear display 8. input parameter of subprogram is stored in BL, clear1st l ine 9. write all the commands in AL into LCD modulator 10. starting address of table is stored into SI 11. store table checking length in CX 12. clear direction flag 13. input AL data into LCD modulator
SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 105

Dept. of E.C.E 14. set interrupt flag 15. write all the commands in Al into LCD modulator 16. store address of table is in Si 17. store table length in CX 18. input AL data into LCD modulator 19. return to the execution program PROGRAM:

Microprocessor & Microcontrollers Lab

; This program is to demonstrate the use of 8259 PIC. Here only Master 8259 is used, during the main ; program, HELP is displayed while in the interrupt service loop, IRO is displayed. MOV AX,0000 ; Data segment is initialize to zero MOV DS,AX MOV AX,2000 ; interrupt location is defined MOV [0000], AX MOV AX,0000 MOV [0002], AX MOV AL,17 ; ICW1 Command OUT 60,AL MOV AL,00 ;ICW2 Command OUT 66,AL MOV AL,01 ; ICW4 Command OUT 66,AL MOV AL,FE ; unmask IRQ0 OUT 66, AL CALL F0000 : F07C ; clear display MOV BL,80; input parameter of subprogram is stored in BL, clear1st l ine CALL F000 :F078 MOV AL,80 ; write all the commands in AL into LCD modulator
SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 106

Dept. of E.C.E CALL F000 : F044 PUSH CS POP DS MOV SI,600 ; starting address of table is stored into SI MOV CX,000F ; store table checking length in CX L1:CLD L0 :DSB CALL F000 : F048 ; input AL data into LCD modulator LOOP 043E STI JMP ; set interrupt flag 0448 ; clear direction flag

Microprocessor & Microcontrollers Lab

Interrupt Sub routine at 0000: 2000 CALL F000: F07C ; clear the display MOV BL,80 ; delete the first line

CALL F000 : F078 MOV AL, 86 ; write all the commands in Al into LCD modulator CALL F000: F044 PUSH CS POP DS ; address of table is stored in Si ; table length stored in CX

MOV SI,621 MOV CX,0D L3: CLD L0: DSB

CALL F000 : F048 ; input AL data into LCD modulator LOOP 201B IRET ; return to the execution program

Machine code
SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 107

Dept. of E.C.E Address 0400 0403 0405 0408 040C 040F 0413 0415 0417 0419 041B 041D 041F 0421 0423 0428 042A 042F 0431 0436 0437 0438 043B 043E 043F 0440 machine code B8 00 00 8E D8 B8 00 20 89 06 00 00 B8 00 00 89 06 02 00 B0 17 E6 60 B0 00 E6 66 B0 01 E6 66 BO FE E6 66 9A 7C F0 00 F0 B3 80 9A 78 F0 00 F0 B0 80 9A 44 F0 00 F0 0E 1F BE 00 06 B9 0F 00 FC AC 9A 48 F0 00 F0 mnemonics operands MOV AX,0000 MOV DS,AX MOV AX,2000 MOV [0000], AX MOV AX,0000 MOV [0002], AX MOV AL,17 OUT 60,AL MOV AL,00 OUT 66,AL MOV AL,01 OUT 66,AL MOV AL,FE OUT 66, AL CALL F0000 : F07C MOV BL,80 CALL F000 :F078 MOV AL,80

Microprocessor & Microcontrollers Lab

CALL F000 : F044 PUSH CS POP DS MOV SI,600 SI

MOV CX,000F L1:CLD L0 :DSB CALL F000 : F048


Page 108

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Dept. of E.C.E 0445 0447 0448 ISR 2000 2005 2007 200C 9A 7C F0 00 F0 B3 80 9A 78 F0 00 F0 B0 86 E2 F7 FB E9 FD FF LOOP 043E STI JMP 0448

Microprocessor & Microcontrollers Lab

CALL F000: F07C ; clear the display MOV BL,80 ; delete the first line

CALL F000 : F078 MOV AL, 86 ; write all the commands in Al into

LCD modulator 200E 2013 2014 2015 2018 201B 201C 201D 2022 2024 IN PUT HELP IR0 OUT PUT 0600 57 41 49 54 49 4E 47 20 46 4F 52 20 49 4E 54 FF 0621 49 52 30 20 49 4E 54 45 52 52 55 50 54
SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 109

9A F0 00 F0 0E 1F BE 21 06 B9 0D 00 FC AC 9A 48 F0 00 F0 E2 F7 CF

CALL F000: F044 PUSH CS POP DS ; address of table is stored in Si ; table length stored in CX

MOV SI,621 MOV CX,0D ` L3: CLD L0: DSB

CALL F000 : F048 ; input AL data into LCD modulator LOOP 201B IRET ; return to the execution program

WAITING FOR IRQ0 INTERRUPT [HELP]

[IR0]

Dept. of E.C.E RESULT:

Microprocessor & Microcontrollers Lab

The ALP to interface 8259 to 8086 microprocessor and process interrupt was written and executed successfully. Viva voice: 1. What is meant by 8259 PIC 2. How many intrupts can be handled by 8259 PIC ? 3. What is meant by intrupt cycle? 4. Explain ISR,IVT?

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 110

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

11.8279 KEYBOARD DISPLAY


AIM: Interface keyboard and display controller 8279 with 8086 at addresses 0080H. Write an ALP to set up 8279 in scanned keyboard mode with encoded scan, N-key rollover mode. APPARATUS:8086 Kit, 8279 interfacing card. THEORY: The 8279 is interfaced with lower byte of the data bus, i.e. D0-D7. Hence the A0 input of 8279 is connected with address line A1. The data register of 8279 is to be addressed as 0080H, i.e. A0=0. For addressing the command or status word A0 input of 8279 should be 1 (the address line A1 of 8086 should be 1), i.e. the address of the command word should be 0082H. Procedure: Step1: Set 8279 command words according to program i.e. Keyboard/Display Mode Set CW, Program clock selection, Clear Display RAM, Read FIFO, Write Display RAM Commands. Step2: Read FIFO command for checking display RAM. Step3: Wait for clearing of Display RAM by reading FIFO Du bit of the status word i.e. if Du bit is not set wait, else proceed. Step4: Read FIFO command for checking key closure, also read FIFO status. Step5: Mask all bits except the number of characters bits. If any key is pressed, take required action; otherwise proceed to write display RAM by using write display command. Step 6: Write the byte 55H to all display RAM locations. Step 7: Call routine to read the key code of the pressed key is assumed available. This Program displays the code of the key, which is pressed on the keyboard pad. The code is displayed in the data field and remains unchanged till the next key is pressed. Description of the Program: The port of 8255 i.e. P1 is initialized to make port A as input port and port C as output port. The three Rows of the key are scanned one by one and process is repeated till the key is pressed, in the routine code and F code (final code). The information of code is then displayed and the monitor jumps back again to see if any other key is pressed. ALGORITHM: 1. Initialize the port B and C as an output ports
SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 111

Dept. of E.C.E 2. Initialize the final key code in Reg. BH

Microprocessor & Microcontrollers Lab

3. Put the walking one pattern in register C with one LSB position 4. Move the pattern in AL on port C 5. Input Port A 6. Classify the 8 word into 8 bits 7. Any Key closure 8. Yeas go to display it 9. Increment the PC code in the partial result 10. as PC code become 18 Yes go start scanning from Row 0 11. No Move the walking one to scan the next line 12. Continue scanning 13. OR the PA code with PC code 14. Display the code in data field 15. CALL OUTWARDS 16. Go to scan the keyboard again 17. Checking for valid key press 18. If yes go to code2 else move 08 in AL.

19. Go to return if this bit was one 20. Increment counter 21. Check the next bit PROGRAM: MOV DX,FFFF MOV AL,90 OUT DX,AL INIT:MOV BH,00 MOB BL,01 SCAN:MOV AL, BL ;Initialize the final key code in Reg. BH ; Put the walking one pattern in register C with one LSB position ; Move the pattern in AL on port C
Page 112

;Initialize the port B and C as an output

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Dept. of E.C.E MOV DX, FFFD OUT DX, AL MOV DX, FFF9 IN AL,DX CALL CODE CMP AL,08 JS DISP ADD BH,08 CMP BH,18H JNS INIT ;Input Port A ;Classify the 8 word into 8 bits ;Any Key closure ;Yeas go to display it

Microprocessor & Microcontrollers Lab

;Increment the PC code in the partial result. ; as PC code become 18 ;Yes go start scanning from Row 0 ; No Move the walking one to scan the next line

MOV AL,BL RCL AL,01 MOV BL,AL JMP SCAN Continue scanning DISP:OR AL,BH ;OR the PA code with PC code MOV AH, 00 PUSH AX MOV AL, 00 PUSH AX MOV AL, 01 PUSH AX PUSH AX CALL DB OUTWARDS JMP INIT ; Go to scan the keyboard again ; Display the code in data field

CODE: OR AL, AL ;Checking for valid key press JNZ CODE2 ;If yes go to code2 else
Page 113

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Dept. of E.C.E MOV AL, 08 RET CODE 2: MOV CH, 00 CODE 5: ROR Al,01 Let LSB in AL go to carry JC CODE 10 INC CH JMP CODE5 CODE10: MOV AL,CH RET Machine code Address 0400 0403 0405 0406 0408 040A 040C 040F 0410 0413 0414 0417 0419 041B 041E 0421 machine code BA FF FF KBD B0 90 EE B7 00 B3 01 88 D8 BA FD FF EE BA F9 FF EC E8 27 00 3C 08 78 10 80 C7 08 80 FF 18 79 E3 mnemonics operands MOV DX,FFFF MOV AL,90 OUT DX,AL INIT:MOV BH, MOB BL,01 SCAN:MOV AL, BL MOV DX, FFFD OUT DX, AL MOV DX, FFF9 IN AL,DX CALL CODE CMP AL,08 JS DISP ADD BH,08 CMP BH,18H JNS INIT

Microprocessor & Microcontrollers Lab

Go to return if this bit was one Increment counter Check the next bit

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 114

Dept. of E.C.E 0423 0425 0427 0429 042B 042D 042F 0430 0432 0433 0435 0436 0437 043C 043E 0440 0442 0444 0445 0447 0449 044B 044D 044F 0451 INPUT: OUTPUT: 88 D8 D0 D0 88 C3 EB DF 08 F8 B4 00 50 B0 00 50 B0 01 50 50 9A E0 0B 00 FF EB C8 08 C0 75 03 B0 08 C3 B5 00 D0 C8 72 04 FE C5 EB F8 88 E8 C3 S A S I S A S I MOV AL,BL RCL AL,01 MOV BL,AL JMP SCAN DISP:OR AL,BH MOV AH, 00 PUSH AX MOV AL, 00 PUSH AX MOV AL, 01

Microprocessor & Microcontrollers Lab

PUSH AX PUSH AX CALL DB OUTWARDS JMP INIT

CODE: OR AL, AL JNZ CODE2

MOV AL, 08 RET CODE 2: MOV CH, 00 CODE 5: ROR Al,01 JC CODE 10 INC CH JMP CODE5 CODE10: MOV AL,CH RET

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 115

Dept. of E.C.E RESULT:

Microprocessor & Microcontrollers Lab

Interfacing of keyboard and display controller 8279 with 8086. an ALP to set up 8279 in scanned ykeyboard mode with encoded scan, N-key rollover mode was written and executed successfully . Viva voice: 1. What are common commanda used for Display interfacing 2. What is the address of data register in 8279

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 116

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

PART-B 12. READING AND WRITING ON A PARALLEL PORT


AIM: To Write an ALP for 8051 micro controller to access IO ports. APPARATUS: 8051development board. Reading and writing on a parallel port. Algorithm: 1: Initialize the Port '0' 2: Load the accumulator with contents of the port '0' 3: write the contents of the accumulator into the Port1 4: Stop the program INPUT: FF IN PORT0 OUT PUT:FF IN A OUT PUT:FF IN PORT1 D7 D6 D5 D4 D3 D2 D1 D0 1 1 1 1 1 1 1 1 Program: Mnemonic MOV IN OUT LCALL

Operand 0x80, FF A, 0x80 0x90, A 003

Comments ; Initialize the Port '0' with FF ; Load the accumulator with contents of the port 0 : Move the contents of the accumulator into the Port1 ; stop the program

MECHINE CODE: Address 5000:0000 5000:0003 5000:0006 5000:0009

opcode B8FF00 A18000 A39000 E8F7FE

Mnemonics Operand MOV A,#FF IN A,[80] OUT [90],A LCALL 0003

RESULT: An ALP for 8051 micro controller to access IO ports has been written and executed successfully.
SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 117

Dept. of E.C.E Viva voice: 1. How many ports will be present in 8051 2. What is the RAM ,ROM size in 8051 3. How many the address and data lines are present in 8051

Microprocessor & Microcontrollers Lab

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 118

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

13. TIMER IN DIFFERENT MODES


AIM: To Write an ALP for 8051 micro controller to use timers in different modes. APPARATUS: 8051development board. THEORY:The basic 8051 has two on-chip timers that can be used for timing durations or for counting external events Interval timing allows the programmer to perform operations at specific instants in time. For example, in our LED flashing program the LED was turned on for a specific length of time and then turned off for a specific length of time. We achieved this through the use of time delays. Since the microcontroller operates at a specific frequency, we could work out exactly how many iterations of the time delay was needed to give us the desired delay. However, this is cumber some and prone to error. And there is another disadvantage; the CPU is occupied, stepping through the loops. If we use the on-chip timers, the CPU could be off doing something more useful while the timers take on the menial task of keeping track of time The Timers' SFRs The 8051 has two 16-bit timers. The high byte for timer 1 (TH1) is at address 8DH while the low byte (TL1) is at 8BH The high byte for timer 0 (TH0) is at 8CH while the low byte (TL0) is at 8AH.Both timers can be used in a number of different modes. The programmer sets the timers to a specific mode by loading the appropriate 8-bit number into the Timer Mode Register (TMOD) which is at address 89H. Timer Mode Register TMOD Bit Name Timer Description 7 BIT Gate 1 Gate bit; when set, timer only runs while INT-bar is high. This bit is used in conjunction with interrupts and will be dealt with later. 6 BIT C/T-bar 1 Counter/timer select bit; when set timer is an event counter, when cleared timer is an interval timer. 5BIT M1 1 Mode bit 1 4BIT M0 1 Mode bit 0 3BIT Gate 0 Gate bit; when set, timer only runs while INT-bar is high. 2 BITC/T-bar 0 -Counter/timer select bit; when set timer is an event counter, when cleared timer is an interval timer. 1BIT M1 0 Mode bit 1 0BIT M0 0 Mode bit 0

The functions of the 8-bits of TMOD are described in the above table. The top four bits are for timer 1 and the bottom four bits have the exact same function but for timer 0. The Gate bits are used in conjunction with interrupts and will be dealt with at a later stage. For the moment we can take it that
SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 119

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

bits 7 and 3 are always cleared. As mentioned above, the timers can be used for counting external events or for timing intervals. If you wish the timer to be an event counter you set the corresponding C/Tbar bit. Similarly, if you wish it to be an interval timer you reset the corresponding C/T-bar bit. There are two mode bits (M1 and M0) for each timer. The table below describes their function M1 M0 Mode Description 0 0 0 13-bit timer mode (this mode exists simply to keep the 8051 backwards compatible with its predecessor, the 8048, which had a 13-bit timer) - we will not be using mode 0. 0 1 1 16-bit timer mode 1 0 2 8-bit auto-reload mode 1 1 3 Split timer mode - this mode will be dealt with at a later stage There are four timer modes, set by the bits M1 and M0. Mode 0 is not commonly used. Mode 1 - 16-bit mode The high byte (THx) is cascaded with the low byte (TLx) to produce a 16-bit timer. This timer counts from 0000H to FFFFH - it has 216 (65,536) states. An overflow occurs during the FFFFH to 0000H transition, setting the overflow flag (to be dealt with shortly). Mode 2- 8-bit auto-reload mode The timer low byte (TLx) operates as an 8-bit timer (counting to FFH) while the high-byte holds a reload value. When the timer overflows from FFH, rather than starting again from 00H, the value in THx is loaded into TLx and the count continues from there. Algorithm: 1:load the TMOD register indicating timer0,is to be used and mode 0selected. 2: load registers TL and TH with initial count value. 3: start the timer. 4: keep monitoring the timer flag(TF)with the jump instruction to see if it is raised, get out of the loop when TF becomes high. 5:stop the timer. 6: clear the TF flag for the next round. 7: go back to step2 to load TH and TL again.

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 120

Dept. of E.C.E PROGRAM: Mnemonic MOV MOV MOV CPL ACALL SJMP DELAY: SETB AGAIN: JNB CLR CLR RET MECHINE CODE Address opcode 8000 8003 8006 8009 758901 7581AF2 758CFF B295 HERE: LABLE Mnemonic MOV MOV MOV CPL ACALL SJMP DELAY: AGAIN: SETB JNB CLR CLR RET Operand TMOD,#01 TLO,#F2 THO,#FF P1.5 DELAY HERE TR0 Operand TMOD,#01 TLO,#F2 THO,#FF P1.5 DELAY HERE TR0 Comments ;timer0,mode1 selected ;initialize TLD value ;initialize THD value

Microprocessor & Microcontrollers Lab

;complement the port1 value ;call the sub program ;short jump of program ; set the timer flag

TFO, AGAIN ; jump if is not set TRO TFO ; clear TRO flag ; clear timer flag ; return to main program

Comments ;timer0,mode1 selected ;initialize TLD value ;initialize THD value ;complement the port1 value ;call the sub program ;short jump of program ; set the timer flag

800B 110F 800D 80FA 800F D28C 8011 8014 8016 8018 308DFD C28C C28D 22

TFO, AGAIN ; jump if is not set TRO TFO ; clear TRO flag ; clear timer flag ; return to main program

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 121

Dept. of E.C.E OUTPUT:

Microprocessor & Microcontrollers Lab

RESULT: An ALP for 8051 micro controller to generate a pulse with 50%duty cycle has written successfully and executed. Viva voice: 1. How many timers are present in 8051 2. What are the timeroperating modes? 3. What is meant by TMOD Register? 4. Which timer of the 8051 is used for band rate programming? 5. Which mode of the timer is used for band rate programming? 6. Is SMOD bit high or low when the 8051 is powered up?

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 122

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

14. SERIAL COMMUNICATION IMPLEMENTATION


AIM: To Write an ALP for 8051 micro controller to implement serial communication. APPARATUS: 8051development board. THOERY:All communication we are dealing with can be serial or parallel. In Parallel communication, data being transferred between one location and another (R0 to the accumulator, for example) travel along the 8-bit data bus. Because of this data bus, data bytes can be moved about the microcontroller at high speed. However, parallel communication has the disadvantage of requiring at least eight separate lines (in an 8-bit system) and in most cases extra lines to synchronize the data transfer (in the case of the microcontroller, the control bus). Serial communication has the advantage of requiring only one line for the data, a second line for ground and possibly a third line for the clock. Therefore, because serial communication requires less physical wires, it is more suitable for transmitting data over longer distances. The obvious disadvantage of serial communication, compared with parallel, is the reduction in the data transfer rate. If we imagine a system where it takes 1us for data to settle on the data bus, we could say it takes 1us to transfer a data byte using parallel communication. If we imagine the same time frame for data bits settling on the serial line, it would take 8us to transfer a data byte using serial communication (1us for each bit). Synchronous Serial Communication Synchronous serial communication requires an extra line for the clock signal. For serial communication, the 8-bit parallel data byte must be shifted down the serial line (in transmission). Therefore, one bit is followed by another. Some kind of system must be used to determine how long each bit is on the line. For example, the serial system designer may decide each bit will be on the line for 1us and, as explained above, transmission of the full eight bits would take 8us. With synchronous communication, the clock signal is transmitted on a separate line. In this way, the receiver is synchronized with the transmitter. As we shall see, the 8051 serial port in mode 0 is an example of synchronous serial communication. Asynchronous Serial Communication A good example of asynchronous serial communication is the interface between a keyboard and a computer. In this case, the keyboard is the transmitter and the computer is the receiver. With asynchronous communication, a clock signal is not sent with the data. There are a number of reasons why this form of communication might be desirable over synchronous communication. One advantage is the fact that the physical line for the clock is not needed. Also, asynchronous communication is better over long distances. If we try to synchronize a remote receiver by sending the clock signal, due to propagation delays and interference, the validity of the clock is lost. Another reason for not transmitting the clock arises when the data rate is erratic. For example, data rate from a keyboard to a computer is dependent upon the typist. The user may type at a rate of sixty words per minute, but at other times he/she may type a lot less. And for long periods there may be no data sent at all. Because of this erratic data rate an asynchronous communication system is suitable.
SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 123

Dept. of E.C.E Serial Communication Protocol

Microprocessor & Microcontrollers Lab

In any communication system, the receiver must know what kind of data to expect and at what rate the data will arrive. In both synchronous and asynchronous serial communication, the receiver needs to know with which bit the transmitter begins. In most systems the LSB is the first bit transmitted. For an asynchronous system, the number of bits transmitted per second must be known by the receiver. Since the clock signal is not transmitted, the receiver needs to know what clock frequency the transmitter is using so that it can use the same. The receiver also needs to know how many bits per word the transmitter is using (in most cases we deal with 8-bit words, but we will see cases where nine bits are transmitted per word). And the receiver needs to know where the data begins and where the data stops. All these parameters make up the protocol. If the receiver uses the same protocol as the transmitter is should receive the data correctly (although errors can occur and we will look at how we catch these errors at a later date). If the receiver uses a protocol other than the one used by the transmitter, then the two devices are effectively speaking two different languages and the data received will be garbage. Start Bits and Stop Bits In asynchronous communication, at least two extra bits are transmitted with the data word; a start bit and a stop bit. Therefore, if the transmitter is using an 8-bit system, the actual number of bits transmitted per word is ten. In most protocols the start bit is a logic 0 while the stop bit is logic 1. Therefore, when no data is being sent the data line is continuously HIGH. The receiver waits for a 1 to 0 transition. In other words, it awaits a transition from the stop bit (no data) to the start bit (logic 0). Once this transition occurs the receiver knows a data byte will follow. Since it knows the data rate (because it is defined in the protocol) it uses the same clock as frequency as that used by the transmitter and reads the correct number of bits and stores them in a register. For example, if the protocol determines the word size as eight bits, once the receiver sees a start bit it reads the next eight bits and places them in a buffer. Once the data word has been read the receiver checks to see if the next bit is a stop bit, signifying the end of the data. If the next bit is not logic 1 then something went wrong with the transmission and the receiver dumps the data. If the stop bit was received the receiver waits for the next data word, ie; it waits for a 1 to 0 transition The 8051 Serial Port The 8051 includes an on-chip serial port that can be programmed to operate in one of four different modes and at a range of frequencies. In serial communication the data is rate is known as the baud rate, which simply means the number of bits transmitted per second. In the serial port modes that allow variable baud rates, this baud rate is set by timer 1. The 8051 serial port is full duplex. In other words, it can transmit and receive data at the same time. The block diagram above shows how this is achieved. If you look at the memory map you will notice at location 99H the serial buffer special function register (SBUF). Unlike any other register in the 8051, SBUF is in fact two distinct registers the write-only register and the read-only register. Transmitted data is sent out from the write-only register while received data is stored in the read-only register. There are two separate data lines, one for transmission (TXD) and one for

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 124

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

reception (RXD). Therefore, the serial port can be transmitting data down the TXD line while it is at the same time receiving data on the RXD line. The TXD line is pin 11 of the microcontroller (P3.1) while the RXD line is on pin 10 (P3.0). Therefore, external access to the serial port is achieved by connecting to these pins. For example, if you wanted to connect a keyboard to the serial port you would connect the transmit line of the keyboard to pin 10 of the 8051. If you wanted to connect a display to the serial port you would connect the receive line of the display to pin 11 of the 8051. This is detailed in the diagram below. Transmitting and Receiving Data Essentially, the job of the serial port is to change parallel data into serial data for transmission and to change received serial data into parallel data for use within the microcontroller. Serial transmission is changing parallel data to serial data. Serial reception is changing serial data into parallel data. Both are achieved through the use of shift registers. As discussed earlier, synchronous communication requires the clock signal to be sent along with the data while asynchronous communication requires the use of stop bits and start bits. However, the programmer wishing to use the 8051 need not worry about such things. To transmit data along the serial line you simply write to the serial buffer and to access data received on the serial port you simply read data from the serial buffer. For example: MOV SBUF, #45H MOV A, SBUF - this sends the byte 45H down the serial line - this takes whatever data was received by the serial port and puts it in the accumulator. How do we know when the complete data byte has been sent? As mentioned earlier, it takes a certain length of time for a data byte to be transmitted down the serial line (determined by the baud rate). If we send data to SBUF and then immediately send more data to SBUF, as shown below, the initial character will be overwritten before it was completely shifted down the line. MOV SBUF, #23H MOV SBUF, #56H Therefore, we must wait for the entire byte to be sent before we send another. The serial port control register (SCON) contains a bit which alerts us to the fact that a byte has been transmitted; ie; the transmit interrupt flag (TI) is set by hardware once an entire byte has been transmitted down the line. Since SCON is bit-addressable we can test this bit and wait until it is set, as shown below: MOV SBUF, #23H; JNB TI, $; CLR TI; send the first byte down the serial line wait for the entire byte to be sent the transmit interrupt flag is set by hardware but must be cleared by software
Page 125

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Dept. of E.C.E MOV SBUF, #56H;

Microprocessor & Microcontrollers Lab send the second byte down the serial line

How do we know when data has been received? Similarly, we need to know when an entire byte has been received by the serial port. Another bit in SCON, the receive interrupt flag (RI) is set by hardware when an entire byte is received by the serial port. The code below shows how you would program the controller to wait for data to be received and to then move that data into the accumulator. JNB RI, $; CLR RI; MOV A, SBUF; ALGORITHM: 1. The TMOD register is loaded with the value 20H, indicating the use of timer1 in mode2 to set the baud rate. 2. The TH1 is loaded with one of the value set the baud rate foe serial data transfer. 3. The SCON register is loaded with the value of 50H, indicating serial mode1 where an 8bit data is framed with start and stop bits. 4. TR1 is set to 1 to start timer 1. 5. TI is cleared by the "CLRTI" instruction. 6. The character byte to be transferred serially is written in to the SBUF register. 7. The TI flag bit is monitored with the use of the instruction to see if the Character has been transferred completely. 8. To transfer the next character goes to step5. PROGRAM: lable Mnemonic Operand Comments ; Initialize the TMOD register ; set the band rate to 9600 ; Initialize the SCON register ; set the TR flag ; load they' ASCII value ; call the sub-program
Page 126

wait for an entire byte to be received the receive interrupt flag is set by hardware but must be cleared by software move the data stored in the read-only buffer to the accumulator

MOV TMOD, #20H MOV TH1, #--3 MOV SCON, #50 SETB TR1 AGAIN : MOV A,#"Y" ACALL TRANS

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Dept. of E.C.E MOV A,#"E" ; call the sub-program ACALL TRANS ; call the sub-program MOV A,#"S" ; load the 's' ASCII value ACALL TRANS ; call the sub-program SJMP AGAIN ; repeat the same process TRANS: MOV SBUF,A ; Initialize the buffer register HERE: JNB TI,HERE ; check the TI flag CLR TI ; clear TI RET ; return to main Memory opcode 8000 758920 8003 858DFD 8006 758950 8009 D28E 800B 7459 800D 1119 800f 7445 8011 1119 8013 7453 8015 1119 8017 80F2 8019 F599 801B 308F1D 801E C28F 8020 22 Results: Label Mnemonic Operand

Microprocessor & Microcontrollers Lab

Comments

MOV TMOD, #20H ; Initialize the TMOD register MOV TH1, #--3 ; set the band rate to 9600 MOV SCON, #50 ; Initialize the SCON register SETB TR1 ; set the TR flag AGAIN: MOV A,#"Y" ; load they' ASCII value ACALL TRANS ; call the sub-program MOV A,#"E" ; call the sub-program ACALL TRANS ; call the sub-program MOV A,#"S" ; load the 's' ASCII value ACALL TRANS ; call the sub-program SJMP AGAIN ; repeat the same process TRANS: MOV SBUF,A ; Initialize the buffer register HERE: JNB TI,HERE ; check the TI flag CLR TI ; clear TI RET ; return to main

Using the 8051 micro controller program transfers the message "YES" serially at 9600 band rate. Viva voice: 1. What is meant by baud rate? 2. What is the operation of mode 1 in timers? 3. What are the interrupts in timers?

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 127

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

15. UNDERSTANDING OF MEMORY ACCESS OF 00 TO FF


AIM: To Write an ALP for 8051 micro controller to to understand the memory access of 00 to FF. APPARATUS: 8051development board. Algorithm: 1. Initialize the source memory location. 2. address 3. Initialize destination address 4. Transfer the count into B register 5. Increment source pointer 6. Transfer the first number into ACC 7. Transfer ACC data to destination 8. Increment destination pointer 9. Decrement counter and repeat same process 10. Stop the program PROGRAM: Mnemonic Operand Comments MOV R0,#10 ; Initialize the source address MOV R1,#31 ; Initialize destination address MOV B,@R0 ; Transfer the count into B register INC R0 ; Increment source pointer

MOV A,@R0 ; Transfer the first number into ACC MOV @R1,A ; Transfer ACC data to destination INC R1 ; Increment destination pointer

DJNZ B,GO ; Decrement counter and repeat same process LCALL 0003 ; Stop the program Memory opcode Mnemonic Operand 8000 7810 Comments

MOV R0,#10 ; Initialize the source address


Page 128

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Dept. of E.C.E 8002 8004 8006 8007 8008 8009 800A 800D INPUT: 31 : AA 32 : BB 33 : CC 34 : DD OUTPUT: 31 : 66 ` 32 : 00 33 : 03 34 : 12 7931 840b 08 E6 F7 09 D50BF9 120003 INC

Microprocessor & Microcontrollers Lab MOV R1,#31 ; Initialize destination address MOV B,@R0 ; Transfer the count into B register R0 ; Increment source pointer

MOV A,@R0 ; Transfer the first number into ACC MOV @R1,A ; Transfer ACC data to destination INC R1 ; Increment destination pointer

DJNZ B,GO ; Decrement counter and repeat same process LCALL 0003 ; Stop the program

RESULT: an alp in 8051 micro controller to transfer a block of data from one memory location to another was written successfully and executed. Viva voice:
1. 2.

What is the size of flag register in the 8051? Which bits of the PSW register are user-definable?

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 129

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

PART-C 16. ARITHMETIC EXPRESSION


AIM: To write assembly language programs using DOS/BIOS programs. APPARATUS: Computer with TASM/MASM software Algorithm to Perform Arithmetic Operations On Below Expression Exp = P + (Q*R)/S-T 1. Initialize the data segment. 2. 3. 4. 5. Load the data data in to AX register. Extended Sign Of AL In To AH Multiply BL with the accumulator AL and save result in to R1. Divide BL with the accumulator AL and save result in to R2.

6. Save remainder in to R3. 7. Compute . P + (Q*R)/S-T 8. Move the result from AX to RESULT. PROGRAM ASSUME CS: CODE , DS: DATA DATA SEGMENT P DB 05 Q DB-03; (FDH) R DB -01; (FFH) S DB -02; (FEH) T DB 05 R1 DW? ; PRODUCT AFTER IMUL R2 DB? ; QUOTIENT AFTER IDIV R3 DB? ; REMAINDER AFTER IDIV EXP DW? DATA ENDS CODE SEGMENT START: MOV AX,DATA
SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 130

Dept. of E.C.E MOV DS,AX MOV AL,Q MOV BL,R CBW IMUL BL MOV R1, AX CBW IDIV BL MOV R2, AL MOV R3, AH SUB AL, T MOV RESULT, AX MOV AH, 4CH INT 21H CODE ENDS END START

Microprocessor & Microcontrollers Lab

; EXTENDED SIGN OF AL IN TO AH

; COMPUTE Q*R MOV BL, S ; EXTENDED SIGN OF AL IN TO AH ; COMPUTE (Q*R/S) ; SAVE QUOTIENT ; SAVE REMAINDER ADD AL,P ; COMPUTE P + (Q*R)/S-T

INPUTS: P= 05, Q=-03(FDH), R= -01 (FFH), S= -02 (FEH), T= 5 OUTPUTS: R1 03 R2 FFH (-01) R3 01 EXP 01FFH

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 131

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

Machine code Address 5C7A:0000 5C7A:0003 5C7A:0005 5C7A:0008 5C7A:000C 5C7A:000D 5C7A:000F 5C7A:0012 5C7A:0013 5C7A:0015 5C7A:0018 5C7A:001C machine code B8795C 8ED8 A00100 8A1E0200 98 F6EB A30700 98 F6FB A20900 88260A00 2A060400 mnemonics operands MOV MOV MOV MOV CBW IMUL BL MOV CBW IDIV MOV MOV SUB BL [0009],AL [000A],AH AL,[0004] [0007],AX AX,5C79 DS,AX AL,[0001] BL,[0002]

RESULT: an alp for 8086 micro processor to implement the arithmetic formula was written and executed successfully Viva voice: 1. Implement subtraction using 2complement method. 2. What is auxiliary carry 3. In which position carry will be generated
SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 132

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

17. FACTORIAL OF A NUMBER


AIM: To write assembly language programs using DOS/BIOS programs. APPARATUS: Computer with TASM/MASM software ALGORIRHM: 1. Initialize the data segment with a required number 2. Load the number in to AX,CX register. 3. Multiply AX with CX register 4. Decrement CX register 5. Continue step 3 till CX is zero 6. Load the value of AX in to result TO FIND FACTORIAL OF A NUMBER DATA SEGMENT NUM DW 5 FACT DW ? DATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA START: MOV AX,DATA MOV DS,AX MOV AX,NUM MOV CX,NUM DEC CX REPEAT: MUL CX LOOP REPEAT MOV FACT,AX INT 21H

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 133

Dept. of E.C.E CODE ENDS END START INPUTS: AX=0005 OUTPUTS:FACT=78H

Microprocessor & Microcontrollers Lab

Machine code Address 68ED:0000 68ED:0003 machine code B8EC68 8ED8 mnemonics operands MOV MOV AX,68EC DS,AX
Page 134

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Dept. of E.C.E 68ED:0005 68ED:0008 68ED:000C 68ED:000D 68ED:000F 68ED:0011 68ED:0014 A10000 8B0E0000 49 F7E1 E2FC A30200 CD21 MOV MOV DEC MUL LOOP MOV INT AX,[0000] CX,[0000] CX CX 000D [0002],AX 21

Microprocessor & Microcontrollers Lab

RESULT: an alp for 8086 micro processor to implement the factorial of given number was written and executed successfully Viva voice: 1. Explain the execution of factorial operation. 2. What is meant by INT 3

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 135

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

18. INTERFACING OF SEVEN SEGMENT DISPLAY


Aim: Write an ALP to Interface Seven Segment Display with 8086 microprocessor Apparatus: 8086 Microprocessor kit, Seven segment display Interfacing Kit, interfacing card. Theory: A seven segment display is the most basic electronic display device that can display digits from 09. They find wide application in devices that display numeric information like digital clocks, radio, microwave ovens, electronic meters etc. The most common configuration has an array of eight LEDs arranged in a special pattern to display these digits. They are laid out as a squared-off figure 8. Every LED is assigned a name from 'a' to 'h' and is identified by its name. Seven LEDs 'a' to 'g' are used to display the numerals while eighth LED 'h' is used to display the dot/decimal. A seven segment is generally available in ten pin package. While eight pins correspond to the eight LEDs, the remaining two pins (at middle) are common and internally shorted. These segments come in two configurations, namely, Common cathode (CC) and Common anode (CA). In CC configuration, the negative terminals of all LEDs are connected to the common pins. The common is connected to ground and a particular LED glows when its corresponding pin is given high. In CA arrangement, the common pin is given a high logic and the LED pins are given low to display a number. Which is ON either on 1 or zero but here we use the format ON on zero. Seven segment is a display which may be either common anode or common cathode. Which is ON either on 1 or zero but here we use the format ON on zero.

Algorithm for getting data to be displayed: 1. Initialize the 8255,assume port A as input and port C as output 2. Load 04(count of seven segment displays) in CH register 3. Load AL with FFH 4. Call procedure to refresh the seven segment display
SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 136

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

5. Decrement CH if it is not zero go to step 4 otherwise go to next step 6. Load BX with 2000 (location at which displayed data is stored) 7. Load AX with 0000 8. Add AX with BX 9. Load CH with 04 10. Load SI with 08(no of segments including dp) 11. Get the content from memory to AL 12. Call FOUR 13. Decrement CH if it is zero go to 14. Increment BX register to get the next value 15. Stop the program. Algorithm for Refreshing & displaying program: 1. Load SI register with 08 2. Out the AL content through Port B 3. Load AL content to CL register 4. Call delay program 5. Load AL with 00 6. Out this content to Port C 7. Load AL with FF 8. Out this content to Port C (The above four steps are to check the each segment in seven segment display unit) 9. Decrement the count of segments SI if it is not Zero 10. Copy the content of CL to AL register 11. Rotate right the content of AL one time and jump to step2 Program: 5000 5002 5005 5006 B080 BAC6FF EE B504 MOV AL,80H MOV DX,0FFC6H OUT DX,AL MOV CH,04H
Page 137

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Dept. of E.C.E 5008 500A 500D 500F 5011 5014 5017 5019 501B 501E 5020 5023 5025 5027 5028 502A B0FF E8F31F FECD 75F9 BB0020 B80000 01C3 B504 B0800 8A07 E8E01F FECD 74EF 43 EBF1 F4 MOV AL,OFFH ONE:CALL PRO DEC CH JNZ ONE MOV BX,2000H MOV AX,0000H ADD BX,AX MOV CH,04H TWO:MOV SI,0008H MOV AL,[BX] CALL FOUR DEC CH JZ THR INC BX JMP TWO THR:HLT

Microprocessor & Microcontrollers Lab

Program (Refreshing Procedure in seven segment display): 7000 7003 7006 7007 7009 700C 700E 7011 7012 7014 BE0800 BAC2FF EE 88C1 E8F40F B000 BAC4FF EE B0FF EE PRO:MOV SI,0008H FOUR:MOV DX,0FFC2H OUT DX,AL MOV CL,AL CALL DELAY MOV AL,00H MOV DX,0FFC4H OUT DX,AL MOV AL,0FFH OUT DX,AL
Page 138

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Dept. of E.C.E 7015 7016 7018 701A 701C 701E 4E 7406 88C8 B0C8 EBE5 C3 DEC SI JZ FIVE MOV AL,CL ROR AL,1H JMP FOUR FIVE:RET

Microprocessor & Microcontrollers Lab

Delay Program: 8000 8003 8004 8005 8007 Tabular form: Number to be displayed E C E 2 Observations: Memory address(H) 2000 2001 2002 2003 Content 25H 61H 63H 61H a 0 0 0 0 b 1 1 1 0 c 1 1 1 1 d 0 0 0 0 e 0 0 0 0 f 0 0 0 1 g 0 1 0 0 dp 1 1 1 1 Opcode 61 63 61 25 BF9912 90 4E 75FC C3 DELAY:MOV DI,129AH SIX:NOP DEC DI JNZ SIX RET

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 139

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

Result: Interfacing of Seven Segment Display with 8086 microprocessor is verified. Viva voice: 1. What is the data to be sent to seven segment display to display5? 2. What is the value of power supply given to seven segment display? 3. What is meant by CC,CA configurations?

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 140

Dept. of E.C.E

Microprocessor & Microcontrollers Lab

19.INTERFACING OF ANALOG TO DIGITAL CONVERTER


Aim: write an ALP to interfacing of Analog to Digital Converter Apparatus: 8086 Microprocessor kit, ADC Interfacing Kit, power supply, data cable etc interfacing card. Theory: The ADC-0809 data acquisition component is a monolithic CMOS device with an 8-bit analog to digital converter, 8 channel multiplexed control logic. The 8 bit A/D converter uses successive approximation as the converter technique. The converter features a high impedance chopper stabilized comparator, a 256R voltage divider with analog switch free and a successive approximation register. The 8 channel multiplexed can directly access any of 8 single ended analog signal. General algorithm for ADC interfacing contains the following steps: 1. Ensure the stability of analog input, applied to the ADC. 2. Issue start of conversion pulse to ADC 3. Read end of conversion signal to mark the end of conversion processes. 4. Read digital data output of the ADC as equivalent digital output.

Features: 1. 2. 3. 4. 5. 6. 7. Resolution 8 bits Conversion time 100 micro sec. Single supply 5V 8 channel multiplexed with latched control logic easy interface to all microprocessor 0 to 5V analog input voltage range with single 5V supply low power consumption 15mW
Page 141

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Dept. of E.C.E 8. latched tristate output Working:

Microprocessor & Microcontrollers Lab

ADC interface consists of a NAND gate oscillator which feeds 50 KHz as the input clock to ADC, input to channel is given through terminal blocks provided on the card. Channel selection is done using port lines PC0, PC1 & PC2, START OF CONVERSION and ALE is controlled by port line PC7. Converted digital output is read by ADC through PORTA lines by enabling OE. OE line is connected to port line PC6. In this method of interfacing microprocessor is continuously monitoring EOC line (which is connected to port line PA7). When this goes high, make OE (PC6) high & then low, this will put the digital equivalent of analog voltage of the given channel on data lines of ADC. Read the digital data through port lines PA0 to PA7 and display the same data.

Algorithm Interfacing of Analog to Digital Converter 1. Initialize the 8255 by loading 90h in CWR 2. Get the data to be converted 3. Out the data to the ADC through the Port C 4. Enable bit Pc7(7th pin of port c) in BSR register 0F 5. Call delay 6. Set the Pc6 bit by giving 0E in accumulator and outing through 0FFC6 address 7. Reset start of conversion signal by loading 0E in accumulator register 8. Get the data from Port A into accumulator 9. Perform AND operation accumulator with 80 10. Compare accumulator with 80( because the END OF CONVERSION SIGNAL is available of Pc7 bit) if zero flag is not set go to step 9 11. Load AL with 0D and out CWR to reset the Pc6 12. Get the digital data from PORT A to the accumulator 13. Stop the program Program: 6000 6002 6005 6006 6009 600C 600D B090 BAC6FF EE A00020 BAC4FF EE B00F MOV AL,90H MOV DX,0FFC6H OUT DX,AL MOV AL,[2000] MOV DX,0FFC4H OUT DX,AL MOV AL,OFH
Page 142

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Dept. of E.C.E 600F 6012 6013 6016 6018 6019 601B 601C 601F 6020 6022 6024 6026 6028 602B 602C 602F 6030 6032 BAC6FF EE E8EA1F B00E EE B00C EE BAC0FF EC 2480 3C80 75F6 B000 DAC6FF EE BAC0FF EC B400 F4 MOV DX,0FFC6H OUT DX,AL CALL DELAY MOV AL,0EH OUT DX,AL MOV AL,OCH OUT DX,AL ONE:MOV DX,OFFC0H IN AL,DX AND AL,80H CMP AL,80H JNZ ONE MOV AL,00H MOV DX,0FFC6H OUT DX,AL MOV DX,0FFC0H IN AL,AX MOV AH,00H HLT

Microprocessor & Microcontrollers Lab

Delay Program 8000 8003 8004 8005 8007 BFFFF F 90 4E 75F6 C3 DELAY:MOV SI,0FFFFH TWO:NOP DEC SI JNZ TWO RET

SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING

Page 143

Dept. of E.C.E Observations: ANALOG 0V 1V 2V 3V 4V 5V

Microprocessor & Microcontrollers Lab

DIGITAL 00H 33H 66H 99H CCH FFH

Theoretical Calculations: N=0=>(0/5)*FF=00H N=1=>(1/5)*FF=33H N=2=>(2/5)*FF=66H N=3=>(3/5)*FF=99H N=4=>(4/5)*FF=CCH N=5=>(5/5)*FF=FFH Operating frequency=5MHZ Time needed for one clock cycle=1/5MHZ=0.2 sec No. of clock cycles required= required delay time/time for one clock cycle =10msec/0.2 sec=50,000 Required count= No. of required clock cycles-4 + (3+2+4)/execution time for loop = (50,000-4-9) / (3+3+16) = 23800=094CH Result: The analog to digital converter was interfaced and the conversion from analog digital is done. Viva voice: 1. What is the successive approximation process? 2. How many channels will be present in ADC 0809? 3. What is the value of input clock for ADC0809?
SASI INSTITUTE OF TECHNOLOGY AND ENGINEERING Page 144

You might also like