You are on page 1of 85

MPI LAB

Introduction to MASM
MASM: (Microsoft Macro 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.
SKEC ECE DEPT Page 1

MPI LAB

C:\MASM\BIN>LINK filename . obj Run File [ Filename1.exe] : filename1.exe List file [ nul.map] : NUL Libraries [.lib] : library_name Definitions File [ nul.def] : Creation of Library: 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

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

SKEC ECE DEPT Page 2

MPI LAB
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. Why Assembly? Assembly has several features that make it a good choice many some situations. 1. It's fast Assembly programs are generally faster than programs created in higher level language es. Often, programmers write speed-essential functions in assembly. 2. It's powerful You are given unlimited power over your assembly programs. Sometimes, higher level languages have restrictions that make implementing certain things difficult. 3. It's small Assembly programs are often much smaller than programs written in other languages. This can be very useful if space is an issue. ASSEMBLY LANGUAGE PROGRAM DEVELOPMENT TOOLS: EDITOR: An editor is a program, which allows you to create a file containing the assembly language statements for your program. 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.

SKEC ECE DEPT Page 3

MPI LAB

ARCHITECTURE OF 8086

2 units are: 1. BIU 2. EU BIU (bus interface unit) sends out addresses, fetches instructions from memory, reads data from ports and memory, and writes data to ports and memory. In other words, the BIU handles all transfers of data and addresses on the buses for the execution unit.
SKEC ECE DEPT Page 4

MPI LAB
EU (execution unit) of the 8086 tells the BIU where to fetch instructions or data from, decodes instructions, and executes instructions.

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. BYTE PTR :- This directive indicates the size of data referenced by pointer. SEGMENT :- 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. EX. ASSUME CS:CODE, DS:DATA 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.
SKEC ECE DEPT Page 5

MPI LAB
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 create a program using modular programming techniques. OFFSET : - 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.

The syntax for DUP: number DUP ( value(s) ) number - number of duplicate to make (any constant value). value - expression that DUP will duplicate. for example: c DB 5 DUP(9) is an alternative way of declaring: c DB 9, 9, 9, 9, 9 one more example:d DB 5 DUP(1, 2) is an alternative way of declaring: d DB 1, 2, 1, 2, 1, 2, 1, 2, 1, 2

Arrays
Arrays can be seen as chains of variables. A text string is an example of a byte array, each character is presented as an ASCII code value (0..255). Here are some array definition examples: a DB 48h, 65h, 6Ch, 6Ch, 6Fh, 00h b DB 'Hello', 0 b is an exact copy of the a array, when compiler sees a string inside quotes it automatically converts it to set of bytes. This chart shows a part of the memory where these arrays are declared:

You can access the value of any element in array using square brackets, for example:
SKEC ECE DEPT Page 6

MPI LAB
MOV AL, a[3] You can also use any of the memory index registers BX, SI, DI, BP, for example: MOV SI, 3 MOV AL, a[SI]

Getting the Address of a Variable


There is LEA (Load Effective Address) instruction and alternative OFFSET operator. Both OFFSET and LEA can be used to get the offset address of the variable. LEA is more powerful because it also allows you to get the address of an indexed variable REG: AX, BX, CX, DX, AH, AL, BL, BH, CH, CL, DH, DL, DI, SI, BP, SP. memory: [BX], [BX+SI+7], variable, etc... immediate: 5, -24, 3Fh, 10001101b, etc... SEGMENT REGISTERS CS - points at the segment containing the current program. DS - generally points at segment where variables are defined. ES - extra segment register, it's up to a coder to define its usage. SS - points at the segment containing the stack. Although it is possible to store any data in the segment registers, this is never a good idea. The segment registers have a very special purpose - pointing at accessible blocks of memory. Segment registers work together with general purpose register to access any memory value. For example if we would like to access memory at the physical address 12345h (hexadecimal), we should set the DS = 1230h and SI = 0045h. This is good, since this way we can access much more memory than with a single register that is limited to 16 bit values. CPU makes a calculation of physical address by multiplying the segment register by 10h and adding general purpose register to it (1230h * 10h + 45h = 12345h):

The address formed with 2 registers is called an effective address. By default BX, SI and DI registers work with DS segment register; BP and SP work with SS segment register. Other general purpose registers cannot form an effective address! Also, although BX can form an effective address, BH and BL cannot! SPECIAL PURPOSE REGISTERS IP - the instruction pointer. Flags Register - determines the current state of the processor.

SKEC ECE DEPT Page 7

MPI LAB
IP register always works together with CS segment register and it points to currently executing instruction. Flags Register is modified automatically by CPU after mathematical operations, this allows to determine the type of the result, and to determine conditions to transfer control to other parts of the program. Generally you cannot access these registers directly.

INTEL 8086 MPU PROGRAMMING


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

5. 6. 7.

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
SKEC ECE DEPT Page 8

MPI LAB
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- trace (step by step execution) U -un assemble D -Dump G -go (complete execution) H -Hex E.g.: to execute the program file PROG.ASM use the following procedure: MASM PROG.ASM MLINK PROG.OBJ DEBUG PROG.EXE DEBUGGER COMMANDS ASSEMBLE: To write assembly language program from the given address. A starting address <cr> Eg: a 4000 <cr> Starts program at an offset of 4000. DUMP: To see the specified memory contents D memory location first address last address (While displays the set of values stored in the specified range, which is given above) Eg: d 2000, 2010 <cr> Display the contents of memory locations from 2000 to 2010 (including). GO: To execute the program G: one instruction executes (address specified by IP) G address <cr>: executes from current IP to the address specified G first address last addresses <cr>: executes a set of instructions specified between the given addresses. QUIT: To exit from the debugger. Q < cr > REGISTER: Shows the contents of Registers R register name Eg: r ax Shows the contents of register.
SKEC ECE DEPT Page 9

MPI LAB
TRACE: To trace the program instruction by instruction. T = 2000 <cr>: traces only the current instruction. (Instruction specified by IP) T = 1000 02 <cr>: Traces instructions from 100 to 101, here the second argument specifies the number of instructions to be traced. UNASSEMBLE : To unassembled the program. Shows the op-codes along with the assembly language program. U 4000 <cr>: unassembled from 4000 onwards instructions. U 5000 6000 <cr>: unassembles the lines from 5000 to 6000
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 load move name output proceed quit register search trace unassemble write

A [address] C range address D [range] E address [list] F range list G [=address] [addresses] H value1 value2 I port 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] W [address] [drive] [firstsector] [number]

allocate expanded memory XA [#pages] deallocate expanded memory XD [handle] map expanded memory pages XM [Lpage] [Ppage] [handle] display expanded memory status XS

SKEC ECE DEPT Page 10

MPI LAB

ARITHMETIC OPERATIONS 1A). ALP FOR ADDITION OF TWO 16 BIT NUMBERS USING INDIRECT ADDRESSING MODE
ASSUME CS:CODE,DS:DATA DATA SEGMENT NO1 DW 6644H NO2 DW 3322H RESULT DW 01H DUP(?) DATA ENDS CODE SEGMENT START: MOV AX,DATA MOV DS,AX MOV AX,NO1 MOV BX,NO2 ADD AX,BX MOV DI, OFFSET RESULT MOV [DI],AX INT 21H CODE ENDS END START RESULT:

INPUT:NO1 6644(AX) NO2 3322 (BX) OUTPUT: 9966(AX)

VIVA QUESTIONS: 1) Write instructions which perform addition operation in direct addressing, indirect addressing? A: Direct addressing mode : ADD AL,[2000], Indirect Addressing mode : ADD AL,[BX] 2) What are the flags effected after executing ADD instruction? A: All Flags effected (S,Z,A,P,C flags)

SKEC ECE DEPT Page 11

MPI LAB

1B). ALP FOR SUBTRACTION OF TWO 16 BIT NUMBERS USING INDIRECT ADDRESSING MODE
ASSUME CS:CODE,DS:DATA DATA SEGMENT NO1 DW 6644H NO2 DW 3322H RESULT DW 01H DUP(?) DATA ENDS CODE SEGMENT START:MOV AX,DATA MOV DS,AX MOV AX,NO1 MOV BX,NO2 SUB AX,BX MOV DI, OFFSET RESULT MOV [DI],AX INT 21H CODE ENDS END START

RESULT: INPUT:NO1 6644(AX) OUTPUT: 3322(AX)

VIVA QUESTIONS: 1 ) What is the difference between SUB,SBB instruction? A: SUB instruction subtracts two operands, SBB instruction subtracts two operands along with the borrow/carry 2) What are the flags effected after execution of HLT instruction ? A: No flags are effected

SKEC ECE DEPT Page 12

MPI LAB

1C). ALP FOR MULTIPLICATION OF TWO 16 BIT NUMBERS USING INDIRECT ADDRESSING MODE ASSUME CS:CODE,DS:DATA DATA SEGMENT A DW 0FF87H ; FIRST SIGNED NUMBER A = (-79H) = FF87H (2'COMPLIMENT FORM) B DW 0FF84H ; SECOND SIGNED NUMBER B = (-7CH) = FF84H (2'COMPLIMENT FORM) RES DW 01H DUP(?) ; VARIABLE C TO STORE RESULT DATA ENDS CODE SEGMENT START: MOV AX,DATA MOV DS,AX ; INITIALIZE DATA SEGMENT MOV SI,0000H ; INITIALIZE SI TO 0000H MOV AX,A ;TAKE FIRST NUMBER A IN AX REGISTER MOV CX,B ;TAKE SECOND NUMBER B IN CX REGISTER MUL CX ; PERFORMS UNSIGNED MULTIPLICATION DX:AX = AX CX MOV SI, OFFSET RES MOV [SI],DX ; STORE HIGHER 16-BIT RESULT MOV [SI+2],AX ; STORE LOWER 16-BIT RESULT INT 21H CODE ENDS END START
RESULT:

INPUT:

FF87 FF84 = FF0B 3A9C H A = 0FF87 H (2'COMPLIMENT OF -79H) B = 0FF84 H (2'COMPLIMENT OF -7CH)

OUTPUT: C = FF0B 3A9C H VIVA QUESTIONS: 1) What are the flags effected after execute up ADD AX,DX instruction (Assume: AX=FFFFh,DX=0001h)? A:Z=1,P=1,AC=1,CY =1,S=0, other flags are not effected 2). What is the difference between MOV DX,[1050],MOV DX,1050?
SKEC ECE DEPT Page 13

MPI LAB
A: MOV DX,[1050] ; the contents of memory location whose address

1050 moved to DL register,1,1051 contents moved to DH register MOV DX,[1050] ;50h moved to D register 10h moved to DH register 1D) ALP FOR DIVISION OF TWO 16 BIT NUMBERS USING INDIRECT ADDRESSING MODE ASSUME CS:CODE,DS:DATA DATA SEGMENT NUM1 DW 4567H,2345H NUM2 DW 4111H QUO DW 2 DUP(0) REM DW 1 DUP(0) DATA ENDS CODE SEGMENT START: MOV AX,DATA MOV DS,AX MOV AX,NUM1 ;MOVE THE LOWER BIT OF DIVIDEND TO AX MOV DX,NUM1+2 ; MOVE THE HIGHER BIT OF DIVIDEND TO DX DIV NUM2 ; PERFORM THE DIVISION OPERATION MOV QUO,AX ; STORE THE QUOTIENT TO AX MOV REM,DX ; STORE THE REMINDER TO DX INT 21H CODE ENDS END START RESULT: INPUT: DIVIDEND 23454567, DIVISOR 4111, 0UTPUT: AX 8AC5H (QUOTIENT); DX 0952H (REMINDER);

VIVA QUESTIONS: 1. What is the result of DIV BX? A: Quotient stored at AX , Remainder stored at DX register 2. What is range of signed numbers for 8 bit microprocessor? A. + 127 to -127
SKEC ECE DEPT Page 14

MPI LAB

LOGICAL OPERATIONS 2A). ALP FOR LOGICAL AND OF TWO 16 BIT NUMBERS USING INDIRECT ADDRESSING MODE.
ASSUME CS: CODE,DS:DATA DATA SEGMENT NO1 DW 8585H NO2 DW 9999H RES DW 01H DUP(0) DATA ENDS CODE SEGMENT START: MOV AX,DATA MOV DS,AX MOV AX,NO1 MOV BX,NO2 AND AX,BX MOV DI,OFFSET RES MOV [DI],AX INT 21H CODE ENDS END START RESULT: INPUT: OUTPUT: 8585H 9999H 8181H

VIVA QUESTIONS: 1). What is mnemonic? 2). What is opcode? 3). What is segment? 4). What are the various segment registers in 8086? A: Code, Data, Stack, Extra Segment registers in 8086. 5). Which segment is used for storing data items.

SKEC ECE DEPT Page 15

MPI LAB

2B). ALP FOR LOGICAL OR OF TWO 16 BIT NUMBERS USING INDIRECT ADDRESSING MODE.
ASSUME CS: CODE,DS:DATA DATA SEGMENT NO1 DW 8585H NO2 DW 9999H RES DW 01H DUP(0) DATA ENDS CODE SEGMENT START: MOV AX,DATA MOV DS,AX MOV AX,NO1 MOV BX,NO2 OR AX,BX MOV DI,OFFSET RES MOV [DI],AX INT 21H CODE ENDS END START RESULT: INPUT: OUTPUT: 8585H 9999H 9D9DH

VIVA QUESTIONS: 1). What is the use of DI register? 2).What is the meaning of DUP(?)? 3).Which segment is use for storing instructions? 4) What is the use of OR instruction? 5). Functions of Accumulator or AX register?

SKEC ECE DEPT Page 16

MPI LAB

2C). ALP FOR LOGICAL XOR OF TWO 16 BIT NUMBERS USING INDIRECT ADDRESSING MODE.
ASSUME CS: CODE,DS:DATA DATA SEGMENT NO1 DW 8585H NO2 DW 9999H RES DW 01H DUP(0) DATA ENDS CODE SEGMENT START: MOV AX,DATA MOV DS,AX MOV AX,NO1 MOV BX,NO2 XOR AX,BX MOV DI,OFFSET RES MOV [DI],AX INT 21H CODE ENDS END START RESULT: INPUT: OUTPUT: 8585H 9999H 1C1CH

VIVA QUESTIONS: 1). What is the use of INT 21h? 2).What is the meaning of DUP(00)? 3).Which segment is use for storing instructions? 4) What is the use of XOR instruction?

SKEC ECE DEPT Page 17

MPI LAB

2D). ALP FOR LOGICAL NOT OF TWO 16 BIT NUMBERS USING INDIRECT ADDRESSING MODE.
ASSUME CS: CODE,DS:DATA DATA SEGMENT NO1 DW 8585H RES DW 01H DUP(0) DATA ENDS CODE SEGMENT START: MOV AX,DATA MOV DS,AX MOV AX,NO1 NOT AX MOV DI,OFFSET RES MOV [DI],AX INT 21H CODE ENDS END START RESULT: INPUT: OUTPUT: 8585H 1C1CH

VIVA QUESTIONS: 1). What is the meaning of DW? 2).What is the meaning of DUP(00)? 3).Which instructions is used for initialization of data segment? 4) What is the use of NOT instruction?

SKEC ECE DEPT Page 18

MPI LAB

2E). ALP FOR LOGICAL SHIFT RIGHT OPERATION USING INDIRECT ADDRESSING MODE.
ASSUME CS: CODE,DS:DATA DATA SEGMENT NO1 DB 46H RES DW 01H DUP(0) DATA ENDS CODE SEGMENT START: MOV AX,DATA MOV DS,AX MOV AL,NO1 MOV CL,04 SHR AL,CL MOV DI,OFFSET RES MOV [DI],AX INT 21H CODE ENDS END START

RESULT: INPUT:AL=46h CL=04h OUTPUT:AL=04h

VIVA QUESTIONS: 1. What are the flags updated after execution of INC AH instruction? A. All flags(Zero,Parity,AC,Sign) except carry flag. 2. What are the flags in 8086? A: In 8086 Carry flag, Parity flag, Auxiliary carry flag, Zero flag, Overflow flag, Trace flag, Interrupt flag, Direction flag, and Sign flag. 3). Which Stack is used in 8086? A: FIFO (First In First Out) stack is used in 8086.In this type of Stack the first stored information is retrieved first.
SKEC ECE DEPT Page 19

MPI LAB

2F). ALP FOR LOGICAL SHIFT LEFT OPERATION USING INDIRECT ADDRESSING MODE.
ASSUME CS: CODE,DS:DATA DATA SEGMENT NO1 DB 46H RES DW 01H DUP(0) DATA ENDS CODE SEGMENT START: MOV AX,DATA MOV DS,AX MOV AL,NO1 MOV CL,04 SHL AL,CL MOV DI,OFFSET RES MOV [DI],AX INT 21H CODE ENDS END START

RESULT: INPUT:AL=46h CL=04h OUTPUT:AL=60h VIVA QUESTIONS: 1. When microprocessor is restarted it goes to which address? A. FFF0 2. Why do we need 16 bit address to be converted in to 20 bit address? A. Physical address of the memory is 20bit 3). Which is the tool used to connect the user and the computer? A: Interpreter is the tool used to connect the user and the tool.

SKEC ECE DEPT Page 20

MPI LAB
2G). ALP FOR LOGICAL ROTATE RIGHT WITHOUT CARRY OPERATION USING INDIRECT ADDRESSING MODE.
ASSUME CS: CODE,DS:DATA DATA SEGMENT NO1 DB 68H RES DW 01H DUP(0) DATA ENDS CODE SEGMENT START: MOV AX, DATA MOV DS, AX MOV AL, NO1 MOV CL, 04 ROR AL, CL MOV DI, OFFSET RES MOV [DI], AX INT 21H CODE ENDS END START

RESULT: INPUT:AL=46h CL=04h OUTPUT:AL=86h VIVA QUESTIONS: 1). What is the meaning of DB? 2).What is the meaning of ROR? 3).Which instructions is used for initialization of data segment? 4) What is the use of CL register? 5). What is the position of the Stack Pointer after the PUSH instruction? A:The address line is 02 less than the earlier value.

SKEC ECE DEPT Page 21

MPI LAB
2H). ALP FOR LOGICAL ROTATE LEFT WITHOUT CARRY OPERATION USING INDIRECT ADDRESSING MODE.
ASSUME CS: CODE,DS:DATA DATA SEGMENT NO1 DB 60H RES DW 01H DUP(0) DATA ENDS CODE SEGMENT START: MOV AX,DATA MOV DS,AX MOV AL,NO1 MOV CL,04 ROL AL,CL MOV DI,OFFSET RES MOV [DI],AX INT 21H CODE ENDS END START

RESULT: INPUT:AL=60h CL=04h OUTPUT:AL=06h VIVA QUESTIONS: 1). What is the difference between ROR and ROL? 2).What is the meaning of ROL? 3) What is the use of END START instruction? 4). What is the position of the Stack Pointer after the PUSH instruction? A:The address line is 02 less than the earlier value.

SKEC ECE DEPT Page 22

MPI LAB
2I). ALP FOR LOGICAL ROTATE RIGHT WITH CARRY OPERATION USING INDIRECT ADDRESSING MODE.
ASSUME CS: CODE,DS:DATA DATA SEGMENT NO1 DB 56H RES DW 01H DUP(0) DATA ENDS CODE SEGMENT START: MOV AX,DATA MOV DS,AX MOV AL,NO1 MOV CL,03 RCR AL,CL MOV DI,OFFSET RES MOV [DI],AX INT 21H CODE ENDS END START

RESULT: INPUT:AL=56h CL=03h OUTPUT:AL=8Ah VIVA QUESTIONS: 1). What is the difference between ROR and RCR? 2).What is the meaning of RCR? 3).How many segments are used in the above program? 4) What is the purpose of RCR AL,CL instruction? 5). Logic calculations are done in which type of registers? A:Accumulator is the register in which Arithmetic and Logic calculations are done.

SKEC ECE DEPT Page 23

MPI LAB

2J). ALP FOR LOGICAL ROTATE LEFT WITH CARRY OPERATION USING INDIRECT ADDRESSING MODE.
ASSUME CS: CODE,DS:DATA DATA SEGMENT NO1 DB 56H RES DW 01H DUP(0) DATA ENDS CODE SEGMENT START: MOV AX,DATA MOV DS,AX MOV AX,NO1 MOV CL,03 RCL AL,CL MOV DI,OFFSET RES MOV [DI],AX INT 21H CODE ENDS END START

RESULT: INPUT:AL=56h CL=03h OUTPUT:AL=B1h VIVA QUESTIONS: 1. What is the purpose of the instruction ROR AL, CL? 2. What is the purpose of the instruction AND AL, 0FH .? 3. What is the expansion of UPBCD? 4. What is the use of DAA instruction? 5. What is the reason for packing unpacked BCD? 6. What is common between unpacked BCD and ASCII?

SKEC ECE DEPT Page 24

MPI LAB
3A). ALP FOR PACKED TO UNPACKED BCD OPERATION USING INDIRECT ADDRESSING MODE. ASSUME CS:CODE, DS:DATA DATA SEGMENT N1 DB 56H, 49H, 33H N2 DB 06H DUP(00) DATA ENDS CODE SEGMENT START: MOV AX, DATA MOV DS, AX XOR AX, AX MOV SI, OFFSET N1 MOV DI, OFFSET N2 MOV DX, 0003H BACK: MOV AL, [SI] MOV BL, AL AND AL, 0F0H MOV CL,04H ROR AL,CL AND BL, 0FH MOV [DI], AL INC DI MOV [DI], BL INC SI INC DI DEC DX JNZ BACK INT 21H CODE ENDS END START RESULT: I/P : 56H 49H 33H O/P : 05H,06H, 04H,09H, 03H,03H VIVA QUESTIONS: 1) What are the contents of AH Register, after executing AND AH, F0, Assume that AH contains 98h ? A: 98h ANDed with F0 ,Low order nibble of 98h is masked ,Result is 90h stored at AH Register 2)What is the addressing mode of MOV [3000],AX instruction ? A: Direct addressing mode 3). What is meant by Maskable interrupts? A: An interrupt that can be turned off by the programmer is known as Maskable interrupt.
SKEC ECE DEPT Page 25

MPI LAB
3B). ALP FOR UNPACKED TO PACKED BCD OPERATION USING INDIRECT ADDRESSING MODE. ASSUME CS:CODE, DS:DATA DATA SEGMENT N1 DB 05H, 06H RES DB 01H DUP(0) DATA ENDS CODE SEGMENT START: MOV AX, DATA MOV DS, AX XOR AX, AX MOV AL, N1 MOV BL, AL MOV CL, 04H ROR BL, CL OR AL, BL MOV DI OFFSET RES MOV [DI],AL INT 21H CODE ENDS END START RESULT: I/P : 05H 06H O/P : 56H

VIVA QUESTIONS: 1. What are the flags effects in this program? 2. What is the purpose of XOR AX, AX ? 3. What is the use of INT 21H? 4. Why AX is called as accumulator? 5. How many segments & what is the use of Extra Segment?

SKEC ECE DEPT Page 26

MPI LAB
3C). ALP FOR BCD TO ASCII CONVERSION USING INDIRECT ADDRESSING MODE. ASSUME CS:CODE, DS:DATA DATA SEGMENT N1 DB 05H, 06H RES DB 01H DUP(0) DATA ENDS CODE SEGMENT START: MOV AX, DATA MOV DS, AX XOR AX, AX MOV AL, N1 MOV BL, AL MOV CL, 04H ROR BL, CL OR AL, BL MOV DI OFFSET RES MOV [DI],AL INT 21H CODE ENDS END START RESULT: I/P : 05H 06H O/P : 56H

VIVA QUESTIONS: 1. What are the flags effects in this program? 2. What is the purpose of XOR AX, AX ? 3. What is the use of INT 21H? 4. Why AX is called as accumulator? 5. How many segments & what is the use of Extra Segment?

SKEC ECE DEPT Page 27

MPI LAB
3D).WRITE ASSEMBLY LANGUAGE PROGRAM TO CONVERT BINARY TO ASCII (OR) HEXDECIMAL TO ASCII ASSUME CS:CODE,DS:DATA DATA SEGMENT NO1 DB 7AH RES DB 02H DUP(0) DATA ENDS CODE SEGMENT START:MOV AX,DATA MOV DS,AX MOV AL,NO1 AND AL,0FH CALL SUBROUT MOV RES,AL MOV AL,NO1 AND AL,0F0H MOV CL,04H ROR AL,CL CALL SUBROUT MOV RES+1,AL INT 21H SUBROUT PROC NEAR CMP AL,09H JBE DIGIT ADD AL,07H DIGIT:ADD AL,30H RET SUBROUT ENDP CODE ENDS END START RESULT: INPUT: 7AH OUTPUT: 37H 41H

VIVA QUESTIONS: 1. What is the use of AND instruction? 2. What is use of JBE INSTRUCTION? 3. What is the ASCII instruction, which is used before the airthematic operation? 4. What is the Expansion of BCDIP? 5. What is the need for SUBROUTINE? 6. What is the purpose of RET instruction?
SKEC ECE DEPT Page 28

MPI LAB
3E). WRITE ASSEMBLY LANGUAGE PROGRAM TO CONVERT ASCII TO BCD CONVERSION. ASSUME CS: CODE, DS: DATA DATA SEGMENT N1 DB 35H N2 DB 02H DUP (00) DATA ENDS CODE SEGMENT START: MOV AX, DATA MOV DS, AX XOR AX, AX MOV AL, N1 AND AL, 0FH MOV DI, OFFSET N2 MOV [DI], AL INT 21H CODE ENDS END START RESULT: I/P : 35H O/P : 05H VIVA QUESTIONS: 1. What is the use of DAA instruction? 2. What is the reason for packing & Un-Packed BCD? 3. What is the ASCII instruction, which is used before the airthematic operation? 4. What is the Expansion of BCDIP? 5. What is the need for segmentation? 6). Why we indicate FF as 0FF in program?

SKEC ECE DEPT Page 29

MPI LAB
4(A) ALP FOR MULTY BYTE ADDITION USING INDIRECT ADDRESSING MODE. ASSUME CS: CODE, DS: DATA DATA SEGMENT N1 DB 55H, 66H, 77H N2 DB 11H, 22H, 33H RESULT DB 3H DUP (00) DATA ENDS CODE SEGMENT START: MOV AX, DATA MOV DS, AX MOV SI, OFFSET N1 MOV DI, OFFSET N2 MOV BX, OFFSET RESULT CLC MOV CX, 0003H MOV AX, 0000H BACK: MOV AL, [SI] MOV DL, [DI] ADC AL, DL MOV [BX], AL INC SI INC DI INC BX DEC CX JNZ BACK INT 21H CODE ENDS END START RESULT: 55H 66H 44H 11H 22H 33H 66H 88H 77H VIVA QUESTIONS: 1)What is the difference between ADD&ADC instruction? A: ADD instruction adds two operands,ADC instruction adds two operands and the carry 2) What are the flags effected after executing MOV BX, 1230 instruction? A : No flags are effected 3. What is the purpose of INT 3H?
SKEC ECE DEPT Page 30

MPI LAB
4(B ).ALP FOR MULTY BYTE SUBTRACTION USING INDIRECT ADDRESSING MODE. ASSUME CS: CODE, DS: DATA DATA SEGMENT N1 DB 55H, 66H, 77H, 88H N2 DB 11H, 22H, 33H, 44H RESULT DB 4H DUP(00) DATA ENDS CODE SEGMENT START: MOV AX, DATA MOV DS, AX MOV SI, OFFSET N1 MOV DI, OFFSET N2 MOV BX, OFFSET RESULT CLC MOV CX, 0004H MOV AX, 0000H BACK: MOV AL, [SI] MOV DL, [DI] SBB AL, DL MOV [BX], AL INC SI INC DI INC BX LOOP BACK INT 21H CODE ENDS END START RESULT: 55H 66H 77H 88H 11H 22H 33H 44H 44H 44H 44H 44H

VIVA QUESTIONS: 1. Why subtract with carry instruction is used in the loop? 2. What is the purpose served by BX register? 3. Why subtraction is done with AL register why not with AX ? 4. What is the other instruction which can be used instead of MOV DI, offset N2 ? 5. What is the Function of CLC? 6. What is the purpose of MOV AH, 4CH and INT 21H in the program?.
SKEC ECE DEPT Page 31

MPI LAB
4(C) ALP FOR MULTY BYTE MULTIPLICATION USING INDIRECT ADDRESSING MODE. ASSUME CS: CODE, DS: DATA DATA SEGMENT N1 DB 05H, 04H, 02H N2 DB 01H, 02H, 03H RESULT DB 4H DUP (00) DATA ENDS CODE SEGMENT START: MOV AX, DATA MOV DS, AX MOV SI, OFFSET N1 MOV DI, OFFSET N2 MOV BX, OFFSET RESULT MOV CL, 03H MOV AX, 0000H MOV DX, 0000H BACK: MOV AL, [SI] MOV DH, [DI] MUL DH MOV [BX], AL INC SI INC DI INC BX LOOP BACK INT 21H CODE ENDS END START

RESULT: 05H 04H 02H 01H 02H 03H 05H 08H 06H VIVA QUESTIONS: 1. After multiplying the AL with BL the result is stored in : AX Register 2. After multiplying AX with BX the result is stored in : DX.AXRegisters 3. What is the other instruction which can be used instead of MOV SI offset N1? 4. What is the use of stack pointer? 5 What is a directive? 6. What is a pseudo operation?
SKEC ECE DEPT Page 32

MPI LAB
4(D) ALP FOR MULTY BYTE DIVISION USING INDIRECT ADDRESSING MODE. ASSUME CS:CODE, DS:DATA DATA SEGMENT N1 DB 55H, 66H, 99H N2 DB 11H, 22H, 33H RESULT DB 3H DUP(00) DATA ENDS CODE SEGMENT START: MOV AX, DATA MOV DS, AX MOV SI, OFFSET N1 MOV DI, OFFSET N2 MOV BX, OFFSET RESULT MOV CL, 03H MOV AX, 0000H MOV DX, 0000H BACK: MOV AL, [SI] MOV DH, [DI] DIV DH MOV [BX], AL INC SI INC DI INC BX LOOP BACK INT 21H CODE ENDS END START RESULT: 55H 66H 99H 11H 02H 03H 05H 33H 33H VIVA QUESTIONS: 1. What AL has been used and not AX ? 2. What happens if num1 contains 0AAH and num2 contains 0FFH. ? 3. How do you account for the difference obtained in previous question? 4. Why should AX be used not AL. ? 5. What happens if num1 and num2 values are interchanged? 6. If carry is set to 1 before subtraction what is the instruction to be used? 7. What is an extended accumulator?
SKEC ECE DEPT Page 33

MPI LAB
ASCII ARITHMETIC OPERATION
5(A)ALP FOR ASCII ADDITION USING INDIRECT ADDRESSING MODE. ASSUME CS:CODE, DS:DATA DATA SEGMENT N1 DB 14H N2 DB 04H N3 DB 2H DUP (00) DATA ENDS CODE SEGMENT START: MOV AX, DATA MOV DS, AX XOR AX, AX MOV AL, N1 MOV CL, N2 MOV BX, OFFSET N3 ADD AL, CL AAA OR AX,3030H MOV [BX], AX INT 21H CODE ENDS END START RESULT: INPUT:14 04 OUTPUT: 08 VIVA QUESTIONS:

38 30

1. Difference between CMPS&SCAS instruction


2. Difference between AAA&DAA instruction 3. What is the purpose of AAA instruction? 4. What is the importance of ASCII addition? 5. What is the difference between addition and ASCII addition? 6. What is the importance of INT 21H? 7. What is meant by pipe lining?

SKEC ECE DEPT Page 34

MPI LAB
5(B). ALP FOR ASCII SUBTRACTION USING INDIRECT ADDRESSING MODE. ASSUME CS:CODE, DS:DATA DATA SEGMENT N1 DB 04H N2 DB 02H N3 DB 02H DUP (00) DATA ENDS CODE SEGMENT START: MOV AX, DATA MOV DS, AX XOR AX, AX MOV AL, N1 MOV BX, OFFSET N3 SUB AL, N2 AAS OR AX,3030H MOV [BX], AX INT 21H CODE ENDS END START RESULT: INPUT:04 02 OUTPUT: 02

32 30

VIVA QUESTIONS: 1. What is the purpose of ASCII subtraction? 2. What is the instruction used for ASCII subtraction? 3. What is the purpose of AAS? 4. What is difference between AAS and AAA? 5. What is the importance of ASCII Nos? 6. AL and BL are used for multiplying why not AX & BX? 7. Instead of using MOV BL is it not possible to MUL num2? 8. What is the instruction used for signed multiplication?

SKEC ECE DEPT Page 35

MPI LAB
5(C). ALP FOR ASCII MULTIPLICATION USING INDIRECT ADDRESSING MODE. ASSUME CS:CODE, DS:DATA DATA SEGMENT N1 DB 04H N2 DB 03H N3 DB 02H DUP(00) DATA ENDS CODE SEGMENT START: MOV AX, DATA MOV DS, AX XOR AX, AX MOV AL, N1 MOV BX, OFFSET N3 MUL N2 AAM OR AX,3030H MOV [BX], AX INT 21H CODE ENDS END START RESULT: INPUT:04 03 OUTPUT: 0C

32 31

VIVA QUESTIONS: 1. What is the purpose of XCHG instruction is ASCII adjust after multiplication. ? 2. Why is ASCII adjust after multiply cab be called as 1 byte binary to BCD conversion? 3. What does AL & AH contains? 4). What is meant by cross-compiler? A: A program runs on one machine and executes on another is called as cross-compiler. 5). While accepting no. from user why u need to subtract 30 from that? 6) While displaying no. from user why u need to add 30 to that?

SKEC ECE DEPT Page 36

MPI LAB
5(D). ALP FOR ASCII DIVISION USING INDIRECT ADDRESSING MODE. ASSUME CS:CODE, DS:DATA DATA SEGMENT N1 DB 06H N2 DB 04H N3 DB 02H DUP (00) DATA ENDS CODE SEGMENT START: MOV AX, DATA MOV DS, AX XOR AX, AX MOV AL, N1 MOV BX, OFFSET N3 DIV N2 AAD OR AX,3030H MOV [BX], AX INT 21H CODE ENDS END START RESULT: INPUT:06 04 OUTPUT:01 02

31 32

VIVA QUESTIONS: 1. What is the ASCII instruction, which is used before the arithmetic operation? 2. Why is ASCII adjust before division is done before actual division? 3. What does AL & AH contains? 4. ORG 2000H implies what? 5. Al register is used why not AX? 6. What is the purpose of INT3 in the program?

SKEC ECE DEPT Page 37

MPI LAB
6(A).TO WRITE ALP FOR ASCENDING ORDER OF GIVEN SERIES ASSUME CS:CODE, DS:DATA DATA SEGMENT N1 DB 56H, 49H, 33H,05H,12H,17H,08H COUNT EQU 7 DATA ENDS CODE SEGMENT START: MOV AX, DATA MOV DS, AX XOR AX, AX MOV DX,COUNT-1 L1:MOV CX,DX MOV SI, OFFSET N1 L2:MOV AL,[SI] CMP AL,[SI+1] JL L3 XCHG [SI+1],AL XCHG [SI],AL L3:INC SI LOOP L2 DEC DX JNZ L1 INT 21H CODE ENDS END START RESULT: I/P : 56H, 49H, 33H,05H,12H,17H,08H O/P : 05H, 08H,12H,17H, 33H, 49H, 56H, VIVA QUESTIONS: 1. What is the function of JBE ? 2. What is the need of CMP instructions? 3. What is the difference between conditional and unconditional jump instructions? 4. What is the function of XCHG in the program? 5. What is significance of accumulator?

SKEC ECE DEPT Page 38

MPI LAB
6(B).TO WRITE ALP FOR DESCENDING ORDER OF GIVEN SERIES ASSUME CS:CODE, DS:DATA DATA SEGMENT N1 DB 56H, 49H, 33H,05H,12H,17H,08H COUNT EQU 7 DATA ENDS CODE SEGMENT START: MOV AX, DATA MOV DS, AX XOR AX, AX MOV DX,COUNT-1 L1:MOV CX,DX MOV SI, OFFSET N1 L2:MOV AL,[SI] CMP AL,[SI+1] JG L3 XCHG [SI+1],AL XCHG [SI],AL L3:INC SI LOOP L2 DEC DX JNZ L1 INT 21H CODE ENDS END START RESULT: I/P : 56H, 49H, 33H,05H,12H,17H,08H O/P : 56H, 49H,33H,17H,12H,08H,05H VIVA QUESTIONS: 1. What is the function of JAE? 2. What IS the need of CMP instructions? 3. What is the difference between conditional and unconditional jump instructions? 4. What is the function of XCHG in the program? 5. What is significance of accumulator?

SKEC ECE DEPT Page 39

MPI LAB
6(C).TO WRITE ALP FOR LARGEST NUMBER IN AN ARRRAY ASSUME CS:CODE, DS:DATA DATA SEGMENT ARRAY DB 56H,49H,33H,05H,12H,17H,08H COUNT EQU 6 RES DB 01H DUP(?) DATA ENDS CODE SEGMENT START: MOV AX, DATA MOV DS, AX XOR AX, AX LEA SI,ARRAY MOV CL,COUNT MOV AL,[SI] AGAIN: CMP AL,[SI+1] JNL NEXT MOV AL,[SI+1] NEXT: INC SI DEC CL JNZ AGAIN MOV SI,OFFSET RES MOV [SI],AL INT 21H CODE ENDS END START RESULT: INPUT: 56H,49H,33H,05H,12H,17H,08H OUTPUT: 56H,49H,33H,05H,12H,17H,08H,56H VIVA QUESTIONS:
1. 2. 3. 4.

What is the function of JNL? What is the function of LEA? What is the function of JNZ? What is the function of XOR?

SKEC ECE DEPT Page 40

MPI LAB

6(D).TO WRITE ALP FOR SMALLEST NUMBER IN AN ARRRAY ASSUME CS:CODE, DS:DATA DATA SEGMENT ARRAY DB 56H,49H,33H,05H,12H,17H,08H COUNT EQU 6 RES DB 01H DUP(?) DATA ENDS CODE SEGMENT START: MOV AX, DATA MOV DS, AX XOR AX, AX LEA SI,ARRAY MOV CL,COUNT MOV AL,[SI] AGAIN: CMP AL,[SI+1] JNG NEXT MOV AL,[SI+1] NEXT: INC SI DEC CL JNZ AGAIN MOV SI,OFFSET RES MOV [SI],AL INT 21H CODE ENDS END START RESULT: INPUT: 56H,49H,33H,05H,12H,17H,08H OUTPUT: 56H,49H,33H,05H,12H,17H,08H 05h VIVA QUESTIONS:
1. 2. 3. 4.

What is the function of JNG? What is the function of LEA? What is the function of JNZ? What is the function of XOR?

SKEC ECE DEPT Page 41

MPI LAB
APPLICATION PROGRAMS 7A). ALP FOR FINDING SUM OF NATURAL NUMBERS ASSUME CS:CODE, DS:DATA DATA SEGMENT N1 DB 1H,2H,3H,4H,5H,6H COUNT EQU 6H RES DB 01H DUP(0) DATA ENDS CODE SEGMENT START: MOV AX, DATA MOV DS, AX MOV CL,COUNT XOR AX, AX XOR BX,BX MOV SI, OFFSET N1 BACK: MOV BL, [SI] ADD AL,BL INC SI DEC CL JNZ BACK MOV DI, OFFSET RES MOV [DI],AL INT 21H CODE ENDS END START RESULT: INPUT:1H,2H,3H,4H,5H,6H OUTPUT:AL=15H VIVA QUESTIONS:
1. 2. 3. 4.

What is the equivalent instruction of MOV SI,OFFSET N1? What is the use of LOOP instruction? What is the difference between MOV BL,[SI] and MOV [BL],SI? What is the purpose of DEC CL?

SKEC ECE DEPT Page 42

MPI LAB
7B). ALP FOR FINDING SQURES OF NATURAL NUMBERS ASSUME CS:CODE, DS:DATA DATA SEGMENT N1 DB 1H,2H,3H,4H,5H COUNT EQU 5H RES DB 01H DUP(0) DATA ENDS CODE SEGMENT START: MOV AX, DATA MOV DS, AX MOV CX,COUNT XOR AX, AX MOV BX,00 LEA SI,N1 BACK: MOV AL, [SI] MUL AL ADD BL,AL INC SI DEC CL JNZ BACK MOV DI, OFFSET RES MOV [DI],BX INT 21H CODE ENDS END START RESULT: INPUT:1H,2H,3H,4H,5H OUTPUT:AX=37H VIVA QUESTIONS:
1. 2. 3. 4.

What is the equivalent instruction of LEA SI,N1? Where is the output stored for the instruction MUL AL? What is the difference between MOV instruction and LEA instruction? What is the purpose of INC SI?

SKEC ECE DEPT Page 43

MPI LAB
7C). ALP FOR FINDING QUBES OF NATURAL NUMBERS ASSUME CS:CODE, DS:DATA DATA SEGMENT N1 DB 1H,2H,3H,4H,5H COUNT EQU 5H RES DB 01H DUP(0) DATA ENDS CODE SEGMENT START: MOV AX, DATA MOV DS, AX MOV CX,COUNT XOR AX, AX MOV BX,00 LEA SI,N1 BACK: MOV AL, [SI] MUL AL ADD BL,AL INC SI DEC CL JNZ BACK MOV DI, OFFSET RES MOV [DI],BX INT 21H CODE ENDS END START RESULT: INPUT:1H,2H,3H,4H,5H OUTPUT:AX=E1H VIVA QUESTIONS:
1. 2. 3. 4.

What is the equivalent instruction of LEA SI,N1? Where is the output for the instruction XOR AX,AX? What is the difference between ADD AL,BL and ADD BL,AL? What is the difference between MOV BX,00 and XOR BX. BX?

SKEC ECE DEPT Page 44

MPI LAB
7D). ALP TO FIND A FACTORIAL OF A GIVEN NUMBER.
ASSUME CS:CODE,DS:DATA DATA SEGMENT NUM1 DW 01H NUM2 DW 06H RESULT DW 01H DUP(?) DATA ENDS CODE SEGMENT START : MOV AX,DATA MOV DS,AX MOV AX,NUM1 MOV BX,NUM2 NEXT: MUL BX DEC BX JNZ NEXT MOV DI,OFFSET RESULT MOV [DI],AX INT 21H CODE ENDS END START
RESULT: INPUT: 7 OUTPUT:02D0H(720)

VIVA QUESTIONS: 1. What is the function of JNZ in the program? 2. What are the branch instructions? 3. What is the difference between conditional and unconditional jump instructions? 4. What is significance of accumulator?

SKEC ECE DEPT Page 45

MPI LAB
7E).WRITE ALP FOR FINDING PERFECT SQURE ROOT OF A GIVEN NUMBER.
ASSUME CS:CODE,DS:DATA DATA SEGMENT NUM EQU 36 RESULT DB 01H DUP(?) DATA ENDS CODE SEGMENT START : MOV AX,DATA MOV DS,AX MOV CL,NUM MOV BL,01 MOV AL,0 UP: CMP CL,0 JZ ZRESULT SUB CL,BL INC AL ADD BL,02 JMP UP ZRESULT: MOV RESULT,AL INT 21H CODE ENDS END START RESULT: INPUT:36 OUTPUT:06

VIVA QUESTIONS: 1. What is the function of JNZ in the program? 2. What are the branch instructions? 3. What is the difference between conditional and unconditional jump instructions? 4. What is significance of accumulator?

SKEC ECE DEPT Page 46

MPI LAB
8 (A). WRITE ALP FOR COUNTING OF EVEN AND ODD NUMBERS IN GIVEN SERIES. ASSUME CS:CODE, DS:DATA DATA SEGMENT N1 DB 56H, 49H, 33H RES DB 01H DUP(0) DATA ENDS CODE SEGMENT START: MOV AX, DATA MOV DS, AX XOR AX, AX MOV SI, OFFSET N1 MOV DX, 0000H MOV BX, 0000H MOV CX, 0003H BACK: MOV AL, [SI] ROR AL, 01H JC X INC BX JMP Y X: INC DX Y: INC SI DEC CX JNZ BACK MOV DI, OFFSET RES MOV [DI],BX INC DI MOV [DI],DX INT 21H CODE ENDS END START RESULT: I/P : 56H 49H 33H O/P : BX=0001H,DX=0002H VIVA QUESTIONS: 1). What is the function of BX? 2). What are the branch instructions? 3). What is the difference between conditional and unconditional jump instructions? 4). What is the function of Ax in the program? 5). What is significance of accumulator?
SKEC ECE DEPT Page 47

MPI LAB
8 (B).WRITE ALP FOR COUNTING OF POSITIVE AND NEGATIVE NUMBERS IN GIVEN SERIES. ASSUME CS:CODE, DS:DATA DATA SEGMENT N1 DB 51H, 20H, 33H,80H,19H RES DB 01H DUP(0) DATA ENDS CODE SEGMENT START: MOV AX, DATA MOV DS, AX XOR AX, AX MOV SI, OFFSET N1 MOV DX, 0000H MOV BX, 0000H MOV CX, 0005H BACK: MOV AL, [SI] ROL AL, 01H JC X INC BX JMP Y X: INC DX Y: INC SI DEC CX JNZ BACK MOV DI,OFFSET RES MOV [DI],BX INC DI MOV [DI],DX INT 21H CODE ENDS END START RESULT: I/P : 56H 49H 33H O/P : BX=0004H,DX=0001H VIVA QUESTIONS: 1). What is the function of ROL? 2). What are the branch instructions? 3). What is the difference between conditional and unconditional jump instructions? 4). What is the function of JC in the program? 5). How does U differentiate between positive and negative numbers?
SKEC ECE DEPT Page 48

MPI LAB
8C). TO FIND NUMBER OF LOGICAL ONES AND ZEROS IN A GIVEN DATA ASSUME CS: CODE,DS:DATA DATA SEGMENT X DB 0AAH ONE DB ? ZERO DB ? DATA ENDS CODE SEGMENT START: MOV AX,DATA MOV DS,AX MOV AH,X MOV BL,8 ;Initialize BL to 8. MOV CL,1 ;Initialize CL to 1. UP: ROR AH,CL ;Perform the single bit rotate operation with respect to right. JNC DOWN ;If no carry go to DOWN label. INC ONE ;Increment one. JMP DOWN1 ;Jump to DOWN1. DOWN: INC ZERO ;Increment ZERO. DOWN1: DEC BL ;Decrement the BL. JNZ UP ;If no zero go to UP label. MOV AH,4CH INT 21H CODE ENDS END START RESULT: Input: 0AAh(1010 1010) Output: Ones04 Zeros04 VIVA QUESTIONS: 1).Which Segment is used to store interrupt and subroutine return address registers? A: Stack Segment in segment register is used to store interrupt and subroutine return address registers. 2). Which Flags can be set or reset by the programmer and also used to control the operation of the processor? A:Trace Flag, Interrupt Flag, Direction Flag.

SKEC ECE DEPT Page 49

MPI LAB
8D). WRITE ALP TO GENERATE FIBONNACI SERIES.
ASSUME CS:CODE,DS:DATA DATA SEGMENT NUM1 DB 00H NUM2 DB 01H COUNT EQU 0AH M DB 09H DUP(?) DATA ENDS CODE SEGMENT START : MOV AX,DATA MOV DS,AX XOR AX,AX MOV AL,NUM1 MOV BL,NUM2 MOV CL,COUNT LEA SI,M UP: MOV [SI],AL INC SI MOV [SI],AL ADD AL,BL XCHG AL,BL DEC CL JNZ UP INT 21H CODE ENDS END START
RESULT: INPUT: 00,01 OUTPUT:00,01,01,02,03,05,08,0D,15

VIVA QUESTIONS: 1. What is the function of JNZ in the program? 2. What are the branch instructions? 3. What is the difference between conditional and unconditional jump instructions? 4. What is significance of accumulator?

5). What is range for these numbers?

SKEC ECE DEPT Page 50

MPI LAB
8E). WRITE A PROGRAM FOR FINDING AVERAGE OF TWO 8-BITS USING SHIFT

OPERATOR. ASSUME CS:CODE, DS:DATA DATA SEGMENT N1 DB 63H N2 DB 23H AVG DB 01H DUP(0) DATA ENDS CODE SEGMENT START: MOV AX, DATA MOV DS, AX XOR AX, AX MOV AL,N1 MOV BL,N2 ADD BL,AL ADC AH,00 SHR AX,01 MOV DI, OFFSET AVG MOV [DI],AX INT 21H CODE ENDS END START RESULT: INPUT: AL=63H,BL=23H OUTPUT:AL=43 VIVA QUESTIONS: 1). What is the difference between 8086 and 8088? A: The BIU in 8088 is 8-bit data bus & 16- bit in 8086.Instruction queue is 4 byte long in 8088and 6 byte in 8086. 2). What is the difference between min mode and max mode of 8086? 3). What is the difference between min mode and max mode of 8086? 4). What is the difference between min mode and max mode of 8086?
SKEC ECE DEPT Page 51

MPI LAB
8F).ALP FOR FINDING THE 1S COMPLEMENT OF AN GIVEN 8 BIT NUMBER USING INDIRECT ADDRESSING MODE
ASSUME CS:CODE,DS:DATA DATA SEGMENT NUMBER DB 55h COMPLIMENT DB 1 DUP(0) DATA ENDS CODE SEGMENT START:MOV AX,DATA MOV DS,AX XOR AX,AX MOV AL,NUMBER NOT AL MOV COMPLIMENT, AL INT 21H CODE ENDS END START RESULT: INPUT:AX=55H OUTPUT:AX=AAH

VIVA QUESTIONS: 1). What is the difference between instructions DIV & IDIV? 2). What is difference between shifts and rotate instructions? 3). What is the advantage of using internal registers? 4). What is the advantage of using internal registers?

SKEC ECE DEPT Page 52

MPI LAB
8G). ALP FOR FINDING THE 1S COMPLEMENT OF AN GIVEN 8 BIT NUMBER SERIES USING INDIRECT ADDRESSING MODE ASSUME CS:CODE,DS:DATA DATA SEGMENT LIST DB 02h,03H,05H,07H,11H,13H COUNT EQU 06 COMPLIMENT DB 6 DUP(0) DATA ENDS CODE SEGMENT START:MOV AX,DATA MOV DS,AX XOR AX,AX MOV CL,COUNT LEA SI, LIST MOV BX,OFFSET COMPLIMENT UP:MOV AL,[SI] NOT AL MOV [BX],AL INC BX INC SI DEC CL JNZ UP INT 21H CODE ENDS END START RESULT: INPUT: 02H,03H,05H,07H,11H,13H OUTPUT:FDH,FCH,FAH,F8H,EEH,ECH

VIVA QUESTIONS: 1). What is flag? A:Flag is a flip-flop used to store the information about the status of a processor and the status of the instruction executed most recently 2). What is stack? A:Stack is a portion of RAM used for saving the content of Program Counter and general purpose registers.
SKEC ECE DEPT Page 53

MPI LAB
8H).ALP FOR FINDING THE 2S COMPLEMENT OF AN GIVEN 8 BIT NUMBER USING INDIRECT ADDRESSING MODE
ASSUME CS:CODE,DS:DATA DATA SEGMENT NUMBER DB 55h COMPLIMENT DB 1 DUP(0) DATA ENDS CODE SEGMENT START:MOV AX,DATA MOV DS,AX XOR AX,AX MOV AL,NUMBER NOT AL ADD AL,01H MOV COMPLIMENT, AL INT 21H CODE ENDS END START RESULT: INPUT:AX=55H OUTPUT: AX=ABH

VIVA QUESTIONS: 1).What is BUS? A: Group of conducting wires used to transfer data.
2).What is queue? A: . FIFO based data storage element. 3).What is addressing mode? A: The way in which the operand is specified is called its addressing mode.

SKEC ECE DEPT Page 54

MPI LAB
8I).ALP FOR FINDING THE 2S COMPLEMENT OF AN GIVEN 8 BIT NUMBER SERIES USING INDIRECT ADDRESSING MODE
ASSUME CS:CODE,DS:DATA DATA SEGMENT LIST DB 02h,03H,05H,07H,11H,13H COUNT EQU 06 COMPLIMENT DB 6 DUP(0) DATA ENDS CODE SEGMENT START:MOV AX,DATA MOV DS,AX XOR AX,AX MOV CL,COUNT LEA SI, LIST MOV BX,OFFSET COMPLIMENT UP:MOV AL,[SI] NOT AL ADD AL,01 MOV [BX],AL INC BX INC SI DEC CL JNZ UP INT 21H CODE ENDS END START

RESULT:

INPUT: 02H,03H,05H,07H,11H,13H OUTPUT:FEH,FDH,FBH,F9H,EFH,EDH

VIVA QUESTIONS: 1).What is pipelining? A: . Fetching the next instruction while the current instruction is being executed. 2).What is assembler sirective? A: ASSEMBLER DIRECTIVES: Statements written in source program but are meant only for the use by the
assembler Or Assembler directives are directions to the assembler. The assembler follows these directions during the assembling of the program but does not generate machine code for them. SKEC ECE DEPT Page 55

MPI LAB
8J).ALP FOR ARITHMETIC MEAN OF 8-BIT NUMBER USING INDIRECT ADDRESSING MODE
ASSUME CS:CODE,DS:DATA DATA SEGMENT FIRST DW 5H MEAN DW 1 DUP(0) DATA ENDS CODE SEGMENT START:MOV AX,DATA MOV DS,AX MOV AX,0000H XOR CX,CX MOV CX,FIRST MOV BX,FIRST UP: ADD AX,CX DEC CL JNZ UP DIV BX MOV MEAN,AX INT 21H CODE ENDS END START

RESULT: INPUT: 05H OUTPUT: 03

VIVA QUESTIONS:

1).What is modular programming? A: A large program is divided into small modules, which has an independent function of their own. This
can be done with the help of Procedures, Macros etc.,

2).What is procedure? A: A section of program, which can be called for execution from other modules, is called procedure. 3).What is macro? A: It is a section of program which is placed wherever it is invoked.
SKEC ECE DEPT Page 56

MPI LAB
8K).ALP FOR SWAPPING OF TWO 16BIT NUMBERS USING INDIRECT ADDRESSING MODE
ASSUME CS:CODE,DS:DATA DATA SEGMENT FIRST DW 1234H SECOND DW 5678H SWAPP DW 2 DUP(0) DATA ENDS CODE SEGMENT START:MOV AX,DATA MOV DS,AX MOV AX,FIRST MOV BX,SECOND XCHG AX,BX MOV SWAPP,AX MOV SWAPP+2,BX INT 21H CODE ENDS END START

RESULT: INPUT:AX=1234H,BX=5678H OUTPUT: AX=5678H,BX=1234H


VIVA QUESTIONS: 1). What is the address bus and data bus size of 8086? 2). How many GPRs (General Purpose Registers) are there in 8086 and what are they? 3). What is the size of instruction Queue of 8086? 4). Group of wires used for data transfer is known as _____.
SKEC ECE DEPT Page 57

MPI LAB
8L). WRITE ALP TO CONVERT 8 BIT BINARY NUMBER INTO EQUIVALENT
GRAY CODE
ASSUME CS:CODE,DS:DATA DATA SEGMENT NUM EQU 34H RESULT DB 01H DUP(?) DATA ENDS CODE SEGMENT START: MOV AX,DATA MOV DS,AX MOV AL,NUM MOV BL,AL CLC RCR AL,1 XOR BL,AL MOV RESULT,BL INT 21H CODE ENDS END START

RESULT: INPUT: AL=34H

OUTPUT:AL=2E

VIVA QUESTIONS: 1). Direction of Data bus is ______. 2). What is Intels first microprocessor? 3). The 8086 architecture is mainly divided into ____ and ____. 4). The maximum size of each segment in 8086 is______. 5). . DF = 1 in the flag register indicates ________.

SKEC ECE DEPT Page 58

MPI LAB
9A).WRITE A ALP FOR THE ADDITION OF TWO 3X3 MATRICES. THE MATRICES ARE STORED IN THE FORM OF LISTS(ROW WISE). STORE THE RESULT OF ADDITION IN THE THIRD LIST.
ASSUME CS:CODE,DS:DATA DATA SEGMENT DIM EQU 09H MAT1 DB 01,02,03,04,05,06,07,08,09 MAT2 DB 01,02,03,04,05,06,07,08,09 RMAT3 DW 09H DUP(?) DATA ENDS CODE SEGMENT START: MOV AX,DATA MOV DS,AX MOV CX,DIM MOV SI ,OFFSET MAT1 MOV DI , OFFSET MAT2 MOV BX,OFFSET RMAT3 NEXT: XOR AX,AX MOV AL,[SI] ADD AL,[DI] MOV WORD PTR [BX],AX INC SI INC DI ADD BX,02 LOOP NEXT INT 21H CODE ENDS END START

RESULT: INPUT: MAT1 :01,02,03,04,05,06,07,08,09 MAT2: 01,02,03,04,05,06,07,08,09 OUTPUT:RMAT3: 02 00,04 00,06 00 ,08 00,0A 00,0C 00,0E 00,10 00,12 00
VIVA QUESTIONS: 1). The instruction used to transfer data between memory and I/O is _____. 2). . Full form of ASCII is ______________ 3). XCHG instruction is used to ___________

SKEC ECE DEPT Page 59

MPI LAB
STRING OPERATIONS
10A). WRITE ALP FOR 8086 STRING MANIPULATION SORTING
ASSUME CS: CODE, DS: DATA DATA SEGMENT LIST DW 53H, 25H, 19H, 02H COUNT EQU 04H DATA ENDS CODE SEGMENT START: MOV AX, DATA MOV DS, AX MOV DX, COUNT-1 LOOP2: MOV CX, DX MOV SI, OFFSET LIST AGAIN: MOV AX, [SI] CMP AX, [SI+2] JC LOOP1 XCHG [SI +2], AX XCHG [SI], AX LOOP1: ADD SI, 02 LOOP AGAIN DEC DX JNZ LOOP2 INT 21H CODE ENDS END START RESULT: INPUT: LIST: 53H, 25H, 19H, 02H OUTPUT:LIST: 02H, 19H, 25H, 53H

VIVA QUESTIONS:

1).Which are string instructions? 2). Is the data bus is Bi-directional? A: The data bus is Bi-directional because the same bus is used for transfer of data between Micro Processor and memory or input / output devices in both the direction

SKEC ECE DEPT Page 60

MPI LAB
10B). WRITE ALP FOR SEARCHING WORD IN A GIVEN STRING.
ASSUME CS: CODE, DS: DATA DATA SEGMENT LIST DW 53H, 15H, 19H, 02H DEST EQU 3000H COUNT EQU 05H DATA ENDS CODE SEGMENT START: MOV AX, DATA MOV DS, AX MOV AX, 15H MOV SI, OFFSET LIST MOV DI, DEST MOV CX, COUNT MOV AX, 00 CLD REP SCASW JZ LOOP MOV AX, 01 LOOP: MOV [DI], AX INT 21H CODE ENDS END START RESULT: INPUT:LIST: 53H, 15H, 19H, 02H OUTPUT: 3000 01

VIVA QUESTIONS: 1. What is the advantage in using the EQU directive in detecting a constant value? A. Assume that there is a constant used in many different places in the program, and the programmer wants to change its value throughout. By the use of EQU one can change it once and the assembler will change all of its occurrences, rather than search the entire program trying to find every occurrence. 2. Which program produces the obj file? A. Assembler program.

SKEC ECE DEPT Page 61

MPI LAB
10C) WRITE ALP FOR DATA TRANSFER FROM ONE SEGMENT TO ANOTHER SEGMENT ASSUME CS:CODE, DS:DATA, ES:EXTRA DATA SEGMENT N1 DB 01H,02H,03H DATA ENDS EXTRA SEGMENT N2 DB 03H DUP (00) EXTRA ENDS CODE SEGMENT START: MOV AX, DATA MOV DS, AX MOV AX, EXTRA MOV ES, AX MOV SI, OFFSET N1 MOV DI, OFFSET N2 CLD MOV CX, 0003H REP MOVSB INT 21H CODE ENDS END START RESULT: I/P : 01H, 02H, 03H O/P : 01H, 02H, 03H VIVA QUESTIONS: 1. If the DF=1, will the SI and DI register decremented? 2. The destination memory is pointed by which register combination? 3. The source is pointed to by which register combination? 4. What is the purpose of instruction pointer? 5. What is the purpose of stack pointer?

SKEC ECE DEPT Page 62

MPI LAB
10D). WRITE 8086 ASSEMBLY LANGUAGE PROGRAM FOR MOVING A BLOCK USING STRINGS
ASSUME CS: CODE, DS: DATA, ES: DATA DATA SEGMENT SRC DB MICROPROCESSOR DB 10 DUP (?) DST DB 20 DUP (0) DATA ENDS CODE SEGMENT START: MOV AX, DATA MOV DS, AX MOV ES, AX LEA SI, SRC LEA DI, DST MOV CX, 20 CLD REP MOVSB INT 21H CODE ENDS END START RESULT: OUTPUT:-d 0000 002c 13BC:0000 4D 49 43 52 4F 50 52 4F 43 45 53 53 4F 52 00 00 MICROPROCESSOR.. 13BC:0010 00 00 00 00 00 00 00 00 4D 49 43 52 4F 50 52 4F .MICROP 13BC:0020 43 45 53 53 4F 52 00 00 00 00 00 00 00 00 00 00 ROCESSOR

VIVA QUESTIONS: 1.What is the addressing mode of MOV [BX+DI], AX A. Base plus Index addressing mode 2. What is the purpose of REP instruction? A. Repeat the set of instructions until CX becomes zero

SKEC ECE DEPT Page 63

MPI LAB

10E) WRITE 8086 ASSEMBLY LANGUAGE PROGRAM FOR STRING REVERSAL.


ASSUME CS:CODE,DS:DATA DATA SEGMENT ORG 2000H SRC DB MICROPROCESSOR$ COUNT EQU ($-SRC) DEST DB ? DATA ENDS CODE SEGMENT 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] MOV [DI],AL DEC SI INC DI DEC CX JNZ BACK INT 21H CODE ENDS END START RESULT: -D 2000 201D 13D6:2000 4D 49 43 52 4F 50 52 4F 43 45 53 53 4F 52 24 00 MICROPROCESSOR$. 13D6:2010 24 52 4F 53 53 45 43 4F 52 50 4F 52 43 49 4D $R0SSECORPORCIM

VIVA QUESTIONS: 1) What is the addressing mode of MOV DI,2002 instruction? a) Immediate addressing mode. 2) What is the difference between CMP AX,DX and SUB AX,DX instructions? a) In CMP AX, DX instruction, perform AX-DX, but AX is not modified. b) SUB AX, DX instruction performs AX-DX.,result is stored at AX register
SKEC ECE DEPT Page 64

MPI LAB
10F).WRITE 8086 ALP FOR STRING COMPARISION. DATA SEGMENT STRING1 DB 'EMPTY' STRLEN EQU ($-STRING1) NOTSFUL DB 'STRINGS ARE UNEQUAL$' SFUL DB 'STRINGS ARE EQUAL$' DATA ENDS EXTRA SEGMENT STRING2 DB 'EMPTY' EXTRA ENDS CODE SEGMENT ASSUME CS:CODE, DS:DATA, ES:EXTRA START: MOV AX, DATA MOV DS, AX MOV AX, EXTRA MOV ES, AX MOV SI, OFFSET STRING1 MOV DI, OFFSET STRING2 CLD MOV CX,LENGTH STRING1 MOV CX, STRLEN REP CMPSB JZ FORW MOV AH, 09H MOV DX, OFFSET NOTSFUL INT 21H JMP EXITP FORW:MOV AH,09H MOV DX, OFFSET SFUL INT 21H EXITP: NOP INT 21H CODE ENDS VIVA QUESTIONS: 1). What is the significance of CLD? 2). How does CMPSB perform the comparison? 3). Which are strings related instructions? 4). over flow flag, interrupt flag ,direction flag, trap flag?
SKEC ECE DEPT Page 65

MPI LAB
10G)WRITE 8086 ASSEMBLY LANGUAGE PROGRAM FOR COMPARISON OF TWO STRINGS
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 REPE CMPSB JNE FAIL PRINTSTRING M1 INT 3H FAIL: PRINTSTRING M2 INT 3H CODE ENDS END START

RESULT: INPUT: OUTPUT:STRINGS ARE EQUAL

VIVA QUESTIONS: 1). What does microprocessor speed depend on? A:The processing speed depends on DATA BUS WIDTH. 2). Is the address bus unidirectional? A: The address bus is unidirectional because the address information is always given by the Micro Processor to address a memory location of an input / output devices.
SKEC ECE DEPT Page 66

MPI LAB
10H).WRITE 8086 ALP FOR FINDING THE LENGTH OF THE STRING. DATA SEGMENT STRING1 DB 'EMPTY VESSELS MAKE MORE NOISE$' STRLEN EQU ($-STRING1) RES DB 0 CORT DB 'STRLENGTH FOUND CORRECT$' INCORT DB 'STRLENGTH FOUND INCORRECT$' DATA ENDS CODE SEGMENT ASSUME CS:CODE, DS:DATA START: MOV AX, DATA MOV DS, AX SUB CL, CL MOV BL, STRLEN MOV SI, OFFSET STRING1 BACK: LODSB INC CL CMP AL,'$' JNZ BACK MOV RES, CL CMP CL, BL JZ CORRECT MOV DX, OFFSET INCORT MOV AH, 09 INT 21H CORRECT: MOV DX, OFFSET CORT MOV AH, 09 INT 21H MOV AH, 4CH INT 21H CODE ENDS END START VIVA QUESTIONS: 1).What is the purpose of SI register in above program? A: SI register used as Memory pointer 2) What is the addressing mode of MOV AL,[SI] instruction? A: Indirect addressing mode: address 3). What is the operation performed by the instruction cmp al,$ ? 4. What is function 09h / int 21h performed? 5). Why SI is not been incremented is the program?
SKEC ECE DEPT Page 67

MPI LAB
10I). 8086 STRING MANIPULATION FIND AND REPLACE A WORD
AIM: To find and replace a word from a string. PROGRAM: ASSUME CS: CODE, DS: DATA DATA SEGMENT LIST DW 53H, 15H, 19H, 02H REPLACE EQU 30H COUNT EQU 05H DATA ENDS CODE SEGMENT START: MOV AX, DATA MOV DS, AX MOV AX, 15H MOV SI, OFFSET LIST MOV CX, COUNT MOV AX, 00 CLD REP SCASW JNZ LOOP MOV DI, LABEL LIST MOV [DI], REPLACE LOOP MOV AH, 4CH INT 21H CODE ENDS END START INPUT: OUTPUT LIST: 53H, 15H, 19H, 02H LIST: 53H, 30H, 19H, 02H

VIVA QUESTIONS: 1). What is the size of flag register in 8086? 2). Which is faster- Reading word size data whose starting address is at even or at odd address of memory in 8086? 3). Which are the default segment base: offset pairs? 4). What do you mean by 20 dup (0)?

SKEC ECE DEPT Page 68

MPI LAB
11) PROGRAM TO FIND FACTORIAL OF A NUMBER USING PROCEDURE ASSUME CS:CODE,DS:DATA DATA SEGMENT NUM EQU 3 MSG DB 'FACTORIAL OF ',NUM+'0',' IS:' ASCRES DB 4 DUP(?),'H',0DH,0AH,'$' RES DW ? HEXCODE DB '0123456789ABCDEF' DATA ENDS HEX_ASC PROC MOV DL,10H MOV AH,0 MOV BX,0 DIV DL ;DIV AL/DL WHERE AL=CHAR & DL=10H MOV BL,AL ;AL=QUOTIENT MOV DH,HEXCODE[BX] MOV BL,AH ;AH=REMAINDER MOV DL,HEXCODE[BX] RET HEX_ASC ENDP FACT PROC CMP AX,01 JE EXIT PUSH AX DEC AX ;N1 CALL FACT ;FACT(N1) POP AX MUL RES ;N*FACT(N1) MOV RES,A X RET EXIT:MOV RES,01 RET FACT ENDP MAIN: MOV AX,@DATA MOV DS,AX MOV AX,NUM ;AX=N CALL FACT MOV AL,BYTE PTR RES+1 CALL HEX_ASC
SKEC ECE DEPT Page 69

;IF N=1, FACT=1 ELSE FACT=N*FACT(N1)

;RES=FACTORIAL

;CONVERT MSB OF RESULT TO ASCII

MPI LAB
MOV ASCRES,DH MOV ASCRES+1,DL MOV AL,BYTE PTR RES CALL HEX_ASC MOV ASCRES+2,DH MOV ASCRES+3,DL MOV AH,09H MOV DX,OFFSET MSG INT 21H MOV AH,4CH ;EXIT INT 21H ALIGN 16 END MAIN
Output: Factorial of the number is 06

;CONVERT LSB OF RESULT TO ASCII

;DISPLAY MSG

VIVA QUESTIONS:

1). What is diff between macro and procedure? 2). What do u mean by assembler? 3). What do u mean by linker? 4). What do u mean by loader? 5). What do u mean by compiler?

SKEC ECE DEPT Page 70

MPI LAB

INTERFACE PROGRAMS
12).WRITE ALP FOR INTERFACING 16 CHANNEL ADC WITH 8086 MICROPROCESSOR.
; Assumes the interface is connected over J4 of trainer . ; This program starts at 0:2000H location. ; This program displays the Channel No. and the digital ; equivalent of the analog voltage at the respective channel ; on the PC console in Serial mode or on the LCD in stand ; alone mode of operation. ; To increment channel value, the user has to enter ','. ; To decrement channel value, the user has to enter '-'.

OUTPUT 2500AD ORG 2000H MOV AX,0000H MOV ES,AX MOV DX,FFE6H MOV AL,8BH OUT DX,AL JMP SHORT MAIN ; Display Message string CHA: DIG: MAIN: NEXT:

;Initialise Segment ;Registers ;Initialise ;8255 Port A ;as O/p, Port B ;Port C as I/P

DB 0DH,'CHANNEL NO: ', 0H DB 0AH, 0DH,'DIGITAL VALUE:',0H MOV CX,00H CALL CONVERT CALL DISP CALL UPDT JMP SHORT NEXT MOV AL,00H OR AL,CL MOV DX,0FFE0H OUT DX,AL MOV AL,20H OR AL,CL OUT DX,AL NOP NOP NOP MOV AL,00H

;Call A/D Conv. routine ;Call Display routine ;Call Ch. update routine ;Repeat continuously ;Initialize ;Add channel ;Load channel Value ;Assert Start ;signal to ADC

CONVERT:

;Start pulse over Page 71

SKEC ECE DEPT

MPI LAB
OR AL,CL OUT DX,AL MOV DX,FFE4H IN AL,DX AND AL,01H JNZ EOC IN AL,DX AND AL,01 JE CHECK MOV AL,40H OR AL,CL MOV DX,0FFE0H OUT DX,AL MOV DX,0FFE2H IN AL,DX PUSH AX MOV AL,00H OR AL,CL MOV DX,FFE0H OUT DX,AL POP AX RET

EOC:

;Wait for End ;of Conversion

CHECK:

;Check for End of Conversion ;signal from ADC ;Assert Read ;Signal ;Read Converted

;Deassert Read signal

DISP:

CALL FAR 0FE00:0031H

VIVA QUESTIONS:
1). What is meant by LATCH?

A:Latch is a D- type flip-flop used as a temporary storage device controlled by a timing signal, which can store 0 or 1. The primary function of a Latch is data storage. It is used in output devices such as LED, to hold the data for display. 2). What is cache memory? A:Cache memory is a small high-speed memory. It is used for temporary storage of data & information between the main memory and the CPU (center processing unit). The cache memory is only in RAM. 3 What is called .Scratch pad of computer.? A:Cache Memory is scratch pad of computer.

SKEC ECE DEPT Page 72

MPI LAB
13).WRITE ALP FOR INTERFACING DAC FOR ADC INTERFACE WITH 8086 MICROPROCESSOR.
; DAC FOR ADC INTERFACE ; Connect the interface over J4 of the trainer ; This program illustrates the use of counter method for A/D conversion ; The program can be executed in Standalone or Serial Mode ; Execute the program from 2000H OUTPUT 2500AD ORG 2000H MOV AX,00H MOV CS,AX MOV ES,AX

;INITIALISE SEGMENT REGISTERS

TEST: MES:

MOV SP,3000H ;INITIALISE STACK POINTER CALL FAR 0FE00:0031H ;NEWLINE MOV DX,0FFE6H ;INITIALISE 8255 AS FOLLOWS MOV AL,81H ;PORT A = OUTPUT OUT DX,AL ;PORT C = INPUT JMP SHORT START DB 0DH,20H,'CONVERTING... ', 00H DB 0AH,0DH,20H, 'DIGITAL VALUE = ',00H ;wait for start of conversion(SOC)

START: MOV DX,0FFE4H IN AL,DX CALL DELAY CALL DELAY AND AL,02H JZ START MOV AX,0FFH PUSH AX CONT: MOV DX,0FFE4H IN AL,DX CALL DELAY AND AL,02H JNZ START POP AX MOV DX,0FFE0H INC AL OUT DX,AL PUSH AX PUSH DX LEA DX,TEST MOV AX,DX POP DX SKEC ECE DEPT

;check for SOC

;If true start again ;else continue ;increment count and ;output to port

;display 'converting...'

Page 73

MPI LAB
CALL FAR 0FE00:0013H CALL DELAY MOV DX,0FFE4H IN AL,DX AND AL,00000001B JNZ CONT LEA DX,MES MOV AX,DX CALL FAR 0FE00:0013H POP AX CALL FAR 0FE00:0052H CALL FAR 0FE00:0031H JMP SHORT START DELAY: MOV CX,8000H HERE: LOOP HERE RET END

;read comparator output

;if PC0=1,continue else ;conversion is over ;display message ;DISPLAY OUTPUT

;delay routine

VIVA QUESTIONS:
1). What is BHE A: BHE (Bus High Enable): During T1 this signal is used to enable data onto the most significant half of the data bus, pins D15-D8. 2).What is delay? 3).Why we use delay sub routine in our program?

SKEC ECE DEPT Page 74

MPI LAB
14). WRITE ALP FOR INTERFACING ELEVATOR INTERFACE WITH 8086 MICROPROCESSOR.
; ELEVATOR INTERFACE ; Assumes the interface is connected over J4 of trainer ; The elevator will work in both Upward and Downward directions ; This program starts at 2000H location OUTPUT 2500AD ORG 2000H MOV DX,0FFE6H MOV AL,82H OUT DX,AL XOR AX,AX LOOP1: MOV AL,AH OR AL,0F0H MOV DX,0FFE0H OUT DX,AL MOV DX,0FFE2H LOOP2: IN AL,DX AND AL,0FH CMP AL,0FH JZ LOOP2 MOV SI,00H FINDF: ROR AL,01H JNC FOUND INC SI JMP SHORT FINDF FOUND: MOV AL,[SI]2100H CMP AL,AH JA GOUP JB GODN CLEAR: MOV AL,[SI]2104H MOV DX,0FFE0H OUT DX,AL JMP SHORT LOOP1 GOUP: CALL DELAY INC AH XCHG AL,AH OR AL,0F0H MOV DX,0FFE0H OUT DX,AL AND AL,0FH XCHG AH,AL SKEC ECE DEPT Page 75

; Configure 8255 ; Port A as o/p, Port B as i/p ; Initial stage is ground floor ; AH is the floor position

; Get request

;If requested floor found ; Otherwise, continue search ; Get requesting floor code ; Compare with current floor ; If it need to go UP ; If it need to g DOWN

; Elevator goes UP by one LED

MPI LAB
CMP AL,AH JNZ GOUP JMP SHORT CLEAR GODN: CALL DELAY DEC AH ; Elevator goes DOWN by one LED XCHG AH,AL OR AL,0F0H MOV DX,0FFE0H OUT DX,AL AND AL,0FH XCHG AL,AH CMP AL,AH JNZ GODN JMP SHORT CLEAR DELAY: MOV CX,0800H ; Delay between glow of successive LEDs HR1: LOOP HR1 HR2: LOOP HR2 RET ; Assumes the interface is connected over J4 of trainer ; The elvator will work in both Upward and Downward directions ; This program starts at 2000H location OUTPUT 2500AD ORG 2000H MOV DX,0FFE6H MOV AL,82H OUT DX,AL XOR AX,AX LOOP1: MOV AL,AH OR AL,0F0H MOV DX,0FFE0H OUT DX,AL MOV DX,0FFE2H LOOP2: IN AL,DX AND AL,0FH CMP AL,0FH JZ LOOP2 MOV SI,00H FINDF: ROR AL,01H JNC FOUND INC SI JMP SHORT FINDF FOUND: MOV AL,[SI]2100H CMP AL,AH SKEC ECE DEPT Page 76

; Configure 8255 ; Port A as o/p, Port B as i/p ; Initial stage is ground floor ; AH is the floor position

; Get request

;If requested floor found ; Otherwise, continue search ; Get requesting floor code ; Compare with current floor

MPI LAB
JA GOUP JB GODN CLEAR: MOV AL,[SI]2104H MOV DX,0FFE0H OUT DX,AL JMP SHORT LOOP1 GOUP: CALL DELAY INC AH XCHG AL,AH OR AL,0F0H MOV DX,0FFE0H OUT DX,AL AND AL,0FH XCHG AH,AL CMP AL,AH JNZ GOUP JMP SHORT CLEAR GODN: CALL DELAY DEC AH XCHG AH,AL OR AL,0F0H MOV DX,0FFE0H OUT DX,AL AND AL,0FH XCHG AL,AH CMP AL,AH JNZ GODN JMP SHORT CLEAR DELAY: MOV CX,0800H HR1: LOOP HR1 HR2: LOOP HR2 RET ; If it need to go UP ; If it need to g DOWN

; Elevator goes UP by one LED

; Elevator goes DOWN by one LED

; Delay between glow of successive LEDs

VIVA QUESTIONS: 1). Differentiate between RAM and ROM? A: RAM: Read / Write memory, High Speed, Volatile Memory. ROM: Read only memory, Low Speed, Non Voliate Memory. 2). What is a compiler? A: Compiler is used to translate the high-level language program into machine code at a time. It doesn.t require special instruction to store in a memory, it stores automatically. The Execution time is less compared to Interpreter.
SKEC ECE DEPT Page 77

MPI LAB
15). WRITE ALP FOR INTERFACING TRAFFIC LIGHT CONTROLLER INTERFACE WITH 8086 MICROPROCESSOR.
; The interface is connected over J4 of of trainer .Traffic system moves from one state to other after a fixed delay. This program starts at 2000H location OUTPUT 2500AD ORG 2000H START: MOV AL,80H ; Initialization of 8255 Mode 0 MOV DX,0FFE6H OUT DX,AL ; All ports as o/p ports AGAIN: MOV SI,2038H ; Table of port values NEXTST: MOV AL,[SI] MOV DX,0FFE0H OUT DX,AL ; Port A value INC SI ADD DX,2 MOV AL,[SI] OUT DX,AL ; Port B value INC SI ADD DX,2 MOV AL,[SI] OUT DX,AL ; Port C value INC SI CALL DELAY ; Calling Delay routine CMP SI,2056H ; Checking for the end of the data values JNZ NEXTST JMP AGAIN DELAY: MOV CX,0FFH ; Delay routine DLY5: PUSH CX MOV CX,03FFH DLY10: NOP LOOP DLY10 POP CX LOOP DLY5 RET ORG 2038H PORTVALUES: DB 10H,81H,7AH ; State 1 DB 44H,44H,0F0H ; All ambers ON DB 08H,11H,0E5H ; State 2 DB 44H,44H,0F0H ; All ambers ON DB 81H,10H,0DAH ; State 3 DB 44H,44H,0F0H ; All ambers ON DB 11H,08H,0B5H ; State 4 DB 44H,44H,0F0H ; All ambers ON DB 88H,88H,00H ; State 5 SKEC ECE DEPT Page 78

MPI LAB
DB DB 44H,44H,0F0H 00H ; All ambers ON ; Dummy

1).What are the instructions are used for accessing I/O devices? A:IN, OUT instructions.

2).What is difference between direct port addressing and indirect port Addressing technique? A: Direct port addressing IN AL, 90h

90h: address of I/O device Indirect port addressing MOV DX, 9000h,IN AL, DX, 9000h is the address of the I/O.

3). Why 8085 processor is called an 8 bit processor? A:Because 8085 processor has 8 bit ALU (Arithmetic Logic Review). Similarly 8086 processor has 16 bit ALU.

SKEC ECE DEPT Page 79

MPI LAB

MICROCONTROLLER PROGRAMS
1) PROGRAMS ON DATA TRANSFER INSTRUCTIONS FOR 8051 MICROCONTROLLER: Aim: Write a 8051 ALP to copy a block of 10 bytes from RAM location starting at 37h to RAM location starting at 59h. Program: ORG 00H MOV R0,#37h MOV R1,#59h MOV R2,#10 L1: MOV A,@R0 MOV @R1,A INC R0 INC R1 DJNZ R2,L1 END Output:

; source pointer ; dest pointer ; counter

SKEC ECE DEPT Page 80

MPI LAB
VIVA QUESTIONS: 1) What is the meaning of ORG 00H? 2) What is use of DJNZ R2,L1?

2) Programs on Arithmetic and Logical Operations:


a) ADDITION OF FIRST 10 NATURAL NUMBERS
Aim: Write an 8051 ALP for addition of first 10 natural numbers Program: ORG 00H MOV R0,#0AH LOOP:ADDC A,R0 DJNZ R0,LOOP MOV R1,A END Output: R1: 37h

VIVA QUESTIONS:
1).What is the meaning of ADDC A,R0?

b) ADDITION OF TWO 16BIT NUMBERS:


Aim: Write an 8051 ALP for addition of two 16-bit numbers Program:

MOV A,R7 ADD A,R5 MOV R3,A MOV A,R6 ADDC A,R4 MOV R2,A MOV A,#00h ADDC A,#00h MOV R1,A Output:

;Move the lowbyte into the accumulator ;Add the second lowbyte to the accumulator ;Move the answer to the lowbyte of the result ;Move the highbyte into the accumulator ;Add the second highbyte to the accumulator, plus carry. ;Move the answer to the highbyte of the result ;By default, the highest byte will be zero. ;Add zero, plus carry from step 2. ;Move the answer to the highest byte of the result

answer now resides in R1, R2, and R3. RET

VIVA QUESTIONS:
1). What is the difference between ADD and ADDC instruction? 2).What is the main purpose of A register>

SKEC ECE DEPT Page 81

MPI LAB
c). 8051 - SUM OF ELEMENTS IN AN ARRAY
AIM: PROGRAM: MOV DPTR, #4200 MOVX A, @DPTR MOV R0, A MOV B, #00 MOV R1, B INC DPTR LOOP2: CLR C MOVX A, @DPTR ADD A, B MOV B, A JNC LOOP INC R1 LOOP: INC DPTR DJNZ R0, LOOP2 MOV DPTR, #4500 MOV A, R1 MOVX @DPTR, A INC DPTR MOV A, B MOVX @DPTR, A SJMP HLT OUTPUT: 04 05 06 03 02 4500 4501 0F 00 To find the sum of elements in an array.

HLT:

INPUT 4200 4201 4201 4202 4203

VIVA QUESTIONS:
1). What is purpose of DPTR register? 2).What is the difference between MOV and MOVX instruction?

SKEC ECE DEPT Page 82

MPI LAB
d). 8051 - HEXADECIMAL TO DECIMAL CONVERSION
AIM: PROGRAM: To perform hexadecimal to decimal conversion. MOV DPTR, #4500 MOVX A, @DPTR MOV B, #64 DIV A, B MOV DPTR, #4501 MOVX @DPTR, A MOV A, B MOV B, #0A DIV A, B INC DPTR MOVX @DPTR, A INC DPTR MOV A, B MOVX @DPTR, A SJMP HLT OUTPUT: D7 4501 4502 15 02

HLT: INPUT 4500

VIVA QUESTIONS:
1).What is the difference between DIV BX and DIV A,B? 2).How many banks available in 8051 MC? 3).Write the structure of Program Status word register?

SKEC ECE DEPT Page 83

MPI LAB

e). 8051 - DECIMAL TO HEXADECIMAL CONVERSION


AIM: To perform decimal to hexadecimal conversion PROGRAM: MOV DPTR, #4500 MOVX A, @DPTR MOV B, #0A MUL A, B MOV B, A INC DPTR MOVX A, @DPTR ADD A, B INC DPTR MOVX @DPTR, A SJMP HLT OUTPUT 23 4501 17

HLT: INPUT 4500

VIVA QUESTIONS:
1).How many 8 bit register is available in 8051MC? 2).Which bank is referred as Stack pointer register? 3).How many parallel ports in 8051MC? 4).What Is SFR?

SKEC ECE DEPT Page 84

MPI LAB

3) Programs on 8051 Applications:


Aim: Write a 8051 ALP using Timer0 to create a 10khz square wave on P1.0 Program: ORG 00H MOV TMOD,#02H MOV TH0,#50 SETB TR0 LOOP: JNB TF0, LOOP CLR TF0 CPL P1.0 SJMP LOOP END

;8bit autoreload mode ;50 reload value in TH0 ;start timer0 ;wait for overflow ;clear timer0 overflow flag ;toggle port bit ;repeat

VIVA QUESTIONS:

1).What is the structure of TMOD register? 2).What is bit wise? 3).What is the difference between Bit wise and Byte wise ? 4).What is the default bank?

SKEC ECE DEPT Page 85

You might also like