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

Mpiprogram Manual

Embed Size (px)

DESCRIPTION

program

Citation preview

Page 1: Mpiprogram Manual

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 DEPTPage 1

Page 2: Mpiprogram Manual

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 DEPTPage 2

Page 3: Mpiprogram Manual

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 inassembly.

2. It's powerful – You are given unlimited power over your assembly programs.Sometimes, higher level languages have restrictions that make implementingcertain things difficult.

3. It's small – Assembly programs are often much smaller than programswritten 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 DEPTPage 3

Page 4: Mpiprogram Manual

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 DEPTPage 4

Page 5: Mpiprogram Manual

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 DEPTPage 5

Page 6: Mpiprogram Manual

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, 9one 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, 00hb 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 squarebrackets, for example:

SKEC ECE DEPTPage 6

Page 7: Mpiprogram Manual

MPI LAB

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

MOV SI, 3MOV AL, a[SI]

Getting the Address of a VariableThere 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.

IP register always works together with CS segment register and it points to currently executing instruction.

SKEC ECE DEPTPage 7

Page 8: Mpiprogram Manual

MPI LAB

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. Debugger allows to look at the contents of registers and memory locations.

2. We can extend 8-bit register to 16-bit register which the help of extended register option.

3. Debugger allows to set breakpoints at any point with the program.

4. 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.

5. With the help of dump we can view register contents.

6. We can trace the program step by step with the help of F7.

7. We can execute the program completely at a time using F8.

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.

SKEC ECE DEPTPage 8

Page 9: Mpiprogram Manual

MPI LAB

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 contentsD 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 programG: one instruction executes (address specified by IP)G address <cr>: executes from current IP to the address specifiedG 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 RegistersR register nameEg: r axShows the contents of register.

TRACE: To trace the program instruction by instruction.T = 2000 <cr>: traces only the current instruction. (Instruction specified by IP)

SKEC ECE DEPTPage 9

Page 10: Mpiprogram Manual

MPI LAB

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 A [address] compare C range address dump D [range] enter E address [list]

fill F range list go G [=address] [addresses] hex H value1 value2 input I port load L [address] [drive] [firstsector] [number] move M range address name N [pathname] [arglist] output O port byte proceed P [=address] [number] quit Q register R [register] search S range list trace T [=address] [value] unassemble U [range] write 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 DEPTPage 10

Page 11: Mpiprogram Manual

MPI LAB

ARITHMETIC OPERATIONS

1A). ALP FOR ADDITION OF TWO 16 BIT NUMBERS USING INDIRECT ADDRESSING MODE

ASSUME CS:CODE,DS:DATADATA SEGMENTNO1 DW 6644HNO2 DW 3322HRESULT DW 01H DUP(?)DATA ENDSCODE SEGMENTSTART: 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 ENDSEND 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 DEPTPage 11

Page 12: Mpiprogram Manual

MPI LAB

1B). ALP FOR SUBTRACTION OF TWO 16 BIT NUMBERS USING INDIRECT

ADDRESSING MODE

ASSUME CS:CODE,DS:DATADATA SEGMENTNO1 DW 6644HNO2 DW 3322HRESULT DW 01H DUP(?)DATA ENDSCODE SEGMENTSTART: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 DEPTPage 12

Page 13: Mpiprogram Manual

MPI LAB

1C). ALP FOR MULTIPLICATION OF TWO 16 BIT NUMBERS USING INDIRECT ADDRESSING MODE

ASSUME CS:CODE,DS:DATA

DATA SEGMENTA 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 RESULTDATA ENDSCODE SEGMENTSTART: 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 HA = 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?

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

1050 moved to DL register,1,1051 contents moved to DH register

SKEC ECE DEPTPage 13

Page 14: Mpiprogram Manual

MPI LAB

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:DATADATA SEGMENTNUM1 DW 4567H,2345HNUM2 DW 4111HQUO DW 2 DUP(0)REM DW 1 DUP(0)DATA ENDSCODE SEGMENTSTART: 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

LOGICAL OPERATIONS

SKEC ECE DEPTPage 14

Page 15: Mpiprogram Manual

MPI LAB

2A). ALP FOR LOGICAL AND OF TWO 16 BIT NUMBERS USING INDIRECT ADDRESSING MODE.

ASSUME CS: CODE,DS:DATADATA SEGMENTNO1 DW 8585HNO2 DW 9999HRES 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: 8585H9999H

OUTPUT: 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.

2B). ALP FOR LOGICAL OR OF TWO 16 BIT NUMBERS USING INDIRECT ADDRESSING MODE.

SKEC ECE DEPTPage 15

Page 16: Mpiprogram Manual

MPI LAB

ASSUME CS: CODE,DS:DATADATA SEGMENTNO1 DW 8585HNO2 DW 9999HRES 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: 8585H9999H

OUTPUT: 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 DEPTPage 16

Page 17: Mpiprogram Manual

MPI LAB

2C). ALP FOR LOGICAL XOR OF TWO 16 BIT NUMBERS USING INDIRECT ADDRESSING MODE.

ASSUME CS: CODE,DS:DATADATA SEGMENTNO1 DW 8585HNO2 DW 9999HRES 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: 8585H9999H

OUTPUT: 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 DEPTPage 17

Page 18: Mpiprogram Manual

MPI LAB

2D). ALP FOR LOGICAL NOT OF TWO 16 BIT NUMBERS USING INDIRECT ADDRESSING MODE.

ASSUME CS: CODE,DS:DATADATA SEGMENTNO1 DW 8585HRES 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: 8585H

OUTPUT: 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 DEPTPage 18

Page 19: Mpiprogram Manual

MPI LAB

2E). ALP FOR LOGICAL SHIFT RIGHT OPERATION USING INDIRECT ADDRESSING MODE.

ASSUME CS: CODE,DS:DATADATA SEGMENTNO1 DB 46HRES 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 DEPTPage 19

Page 20: Mpiprogram Manual

MPI LAB

2F). ALP FOR LOGICAL SHIFT LEFT OPERATION USING INDIRECT ADDRESSING MODE.

ASSUME CS: CODE,DS:DATADATA SEGMENTNO1 DB 46HRES 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 DEPTPage 20

Page 21: Mpiprogram Manual

MPI LAB

2G). ALP FOR LOGICAL ROTATE RIGHT WITHOUT CARRY OPERATION USING INDIRECT ADDRESSING MODE.

ASSUME CS: CODE,DS:DATADATA SEGMENTNO1 DB 68HRES 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 DEPTPage 21

Page 22: Mpiprogram Manual

MPI LAB

2H). ALP FOR LOGICAL ROTATE LEFT WITHOUT CARRY OPERATION USING INDIRECT ADDRESSING MODE.

ASSUME CS: CODE,DS:DATADATA SEGMENTNO1 DB 60HRES 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 DEPTPage 22

Page 23: Mpiprogram Manual

MPI LAB

2I). ALP FOR LOGICAL ROTATE RIGHT WITH CARRY OPERATION USING INDIRECT ADDRESSING MODE.

ASSUME CS: CODE,DS:DATADATA SEGMENTNO1 DB 56HRES 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 DEPTPage 23

Page 24: Mpiprogram Manual

MPI LAB

2J). ALP FOR LOGICAL ROTATE LEFT WITH CARRY OPERATION USING INDIRECT ADDRESSING MODE.

ASSUME CS: CODE,DS:DATADATA SEGMENTNO1 DB 56HRES 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 DEPTPage 24

Page 25: Mpiprogram Manual

MPI LAB

3A). ALP FOR PACKED TO UNPACKED BCD OPERATION USING INDIRECT ADDRESSING MODE.

ASSUME CS:CODE, DS:DATADATA SEGMENTN1 DB 56H, 49H, 33HN2 DB 06H DUP(00)DATA ENDSCODE SEGMENTSTART: MOV AX, DATA

MOV DS, AXXOR AX, AXMOV SI, OFFSET N1MOV DI, OFFSET N2MOV DX, 0003H

BACK: MOV AL, [SI]MOV BL, ALAND AL, 0F0HMOV CL,04HROR AL,CLAND BL, 0FHMOV [DI], ALINC DIMOV [DI], BLINC SIINC DIDEC DXJNZ BACKINT 21HCODE ENDS

END START

RESULT:I/P : 56H 49H 33HO/P : 05H,06H, 04H,09H, 03H,03HVIVA 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 mode3). What is meant by Maskable interrupts?

A: An interrupt that can be turned off by the programmer is known as Maskable interrupt.

SKEC ECE DEPTPage 25

Page 26: Mpiprogram Manual

MPI LAB

3B). ALP FOR UNPACKED TO PACKED BCD OPERATION USING INDIRECT ADDRESSING MODE.

ASSUME CS:CODE, DS:DATADATA SEGMENTN1 DB 05H, 06HRES DB 01H DUP(0)DATA ENDSCODE SEGMENTSTART: MOV AX, DATA

MOV DS, AXXOR AX, AXMOV AL, N1MOV BL, ALMOV CL, 04HROR BL, CLOR AL, BLMOV DI OFFSET RESMOV [DI],ALINT 21HCODE ENDS

END START

RESULT:I/P : 05H 06HO/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 DEPTPage 26

Page 27: Mpiprogram Manual

MPI LAB

3C). ALP FOR BCD TO ASCII CONVERSION USING INDIRECT ADDRESSING MODE.

ASSUME CS:CODE, DS:DATADATA SEGMENTN1 DB 05H, 06HRES DB 01H DUP(0)DATA ENDSCODE SEGMENTSTART: MOV AX, DATA

MOV DS, AXXOR AX, AXMOV AL, N1MOV BL, ALMOV CL, 04HROR BL, CLOR AL, BLMOV DI OFFSET RESMOV [DI],ALINT 21HCODE ENDS

END START

RESULT:I/P : 05H 06HO/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 DEPTPage 27

Page 28: Mpiprogram Manual

MPI LAB

3D).WRITE ASSEMBLY LANGUAGE PROGRAM TO CONVERT BINARY TO ASCII (OR) HEXDECIMAL TO ASCII

ASSUME CS:CODE,DS:DATADATA SEGMENTNO1 DB 7AHRES DB 02H DUP(0)DATA ENDSCODE SEGMENTSTART: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 21HSUBROUT PROC NEAR CMP AL,09H JBE DIGIT ADD AL,07H DIGIT:ADD AL,30H RET SUBROUT ENDP CODE ENDSEND START

RESULT: INPUT: 7AHOUTPUT: 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 DEPTPage 28

Page 29: Mpiprogram Manual

MPI LAB

3E). WRITE ASSEMBLY LANGUAGE PROGRAM TO CONVERT ASCII TO BCD

CONVERSION.

ASSUME CS: CODE, DS: DATADATA SEGMENTN1 DB 35HN2 DB 02H DUP (00)DATA ENDSCODE SEGMENTSTART: 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 : 35HO/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?

4(A) ALP FOR MULTY BYTE ADDITION USING INDIRECT ADDRESSING MODE.

SKEC ECE DEPTPage 29

Page 30: Mpiprogram Manual

MPI LAB

ASSUME CS: CODE, DS: DATADATA SEGMENTN1 DB 55H, 66H, 77HN2 DB 11H, 22H, 33HRESULT DB 3H DUP (00)DATA ENDSCODE SEGMENTSTART: 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 DEPTPage 30

Page 31: Mpiprogram Manual

MPI LAB

4(B ).ALP FOR MULTY BYTE SUBTRACTION USING INDIRECT ADDRESSING MODE.

ASSUME CS: CODE, DS: DATADATA SEGMENTN1 DB 55H, 66H, 77H, 88HN2 DB 11H, 22H, 33H, 44HRESULT DB 4H DUP(00)DATA ENDSCODE SEGMENTSTART: 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 DEPTPage 31

Page 32: Mpiprogram Manual

MPI LAB

4(C) ALP FOR MULTY BYTE MULTIPLICATION USING INDIRECT ADDRESSING MODE.

ASSUME CS: CODE, DS: DATADATA SEGMENTN1 DB 05H, 04H, 02HN2 DB 01H, 02H, 03HRESULT DB 4H DUP (00)DATA ENDSCODE SEGMENTSTART: 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 ENDSEND 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 DEPTPage 32

Page 33: Mpiprogram Manual

MPI LAB

4(D) ALP FOR MULTY BYTE DIVISION USING INDIRECT ADDRESSING MODE.

ASSUME CS:CODE, DS:DATADATA SEGMENTN1 DB 55H, 66H, 99HN2 DB 11H, 22H, 33HRESULT DB 3H DUP(00)DATA ENDSCODE SEGMENTSTART: MOV AX, DATA

MOV DS, AXMOV SI, OFFSET N1MOV DI, OFFSET N2MOV BX, OFFSET RESULTMOV CL, 03HMOV AX, 0000HMOV DX, 0000H

BACK: MOV AL, [SI]MOV DH, [DI]DIV DHMOV [BX], ALINC SIINC DIINC BXLOOP BACKINT 21HCODE 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 DEPTPage 33

Page 34: Mpiprogram Manual

MPI LAB

ASCII ARITHMETIC OPERATION

5(A)ALP FOR ASCII ADDITION USING INDIRECT ADDRESSING MODE.

ASSUME CS:CODE, DS:DATADATA SEGMENTN1 DB 14HN2 DB 04HN3 DB 2H DUP (00)DATA ENDSCODE SEGMENTSTART: 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 38 30

VIVA QUESTIONS:

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 DEPTPage 34

Page 35: Mpiprogram Manual

MPI LAB

5(B). ALP FOR ASCII SUBTRACTION USING INDIRECT ADDRESSING MODE.

ASSUME CS:CODE, DS:DATADATA SEGMENTN1 DB 04HN2 DB 02HN3 DB 02H DUP (00)DATA ENDSCODE SEGMENTSTART: MOV AX, DATA

MOV DS, AXXOR AX, AXMOV AL, N1MOV BX, OFFSET N3SUB AL, N2AASOR AX,3030HMOV [BX], AXINT 21HCODE 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 No’s?

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 DEPTPage 35

Page 36: Mpiprogram Manual

MPI LAB

5(C). ALP FOR ASCII MULTIPLICATION USING INDIRECT ADDRESSING MODE.

ASSUME CS:CODE, DS:DATADATA SEGMENTN1 DB 04HN2 DB 03HN3 DB 02H DUP(00)DATA ENDSCODE SEGMENTSTART: MOV AX, DATA

MOV DS, AXXOR AX, AXMOV AL, N1MOV BX, OFFSET N3MUL N2AAMOR AX,3030HMOV [BX], AXINT 21HCODE 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 DEPTPage 36

Page 37: Mpiprogram Manual

MPI LAB

5(D). ALP FOR ASCII DIVISION USING INDIRECT ADDRESSING MODE.

ASSUME CS:CODE, DS:DATADATA SEGMENTN1 DB 06HN2 DB 04HN3 DB 02H DUP (00)DATA ENDSCODE SEGMENTSTART: MOV AX, DATA

MOV DS, AXXOR AX, AXMOV AL, N1MOV BX, OFFSET N3DIV N2AADOR AX,3030HMOV [BX], AXINT 21HCODE 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 DEPTPage 37

Page 38: Mpiprogram Manual

MPI LAB

6(A).TO WRITE ALP FOR ASCENDING ORDER OF GIVEN SERIES

ASSUME CS:CODE, DS:DATADATA SEGMENTN1 DB 56H, 49H, 33H,05H,12H,17H,08HCOUNT EQU 7DATA ENDSCODE SEGMENTSTART: MOV AX, DATA

MOV DS, AXXOR 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 21HCODE ENDS

END START

RESULT:I/P : 56H, 49H, 33H,05H,12H,17H,08HO/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 DEPTPage 38

Page 39: Mpiprogram Manual

MPI LAB

6(B).TO WRITE ALP FOR DESCENDING ORDER OF GIVEN SERIES

ASSUME CS:CODE, DS:DATADATA SEGMENTN1 DB 56H, 49H, 33H,05H,12H,17H,08HCOUNT EQU 7DATA ENDSCODE SEGMENTSTART: MOV AX, DATA

MOV DS, AXXOR 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 21HCODE ENDS

END START

RESULT:I/P : 56H, 49H, 33H,05H,12H,17H,08HO/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 DEPTPage 39

Page 40: Mpiprogram Manual

MPI LAB

6(C).TO WRITE ALP FOR LARGEST NUMBER IN AN ARRRAY

ASSUME CS:CODE, DS:DATADATA SEGMENTARRAY DB 56H,49H,33H,05H,12H,17H,08HCOUNT EQU 6RES DB 01H DUP(?)DATA ENDSCODE SEGMENTSTART: MOV AX, DATA

MOV DS, AXXOR 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 ENDSEND START

RESULT:INPUT: 56H,49H,33H,05H,12H,17H,08HOUTPUT: 56H,49H,33H,05H,12H,17H,08H,56H

VIVA QUESTIONS:

1. What is the function of JNL?

2. What is the function of LEA?

3. What is the function of JNZ?

4. What is the function of XOR?

SKEC ECE DEPTPage 40

Page 41: Mpiprogram Manual

MPI LAB

6(D).TO WRITE ALP FOR SMALLEST NUMBER IN AN ARRRAY

ASSUME CS:CODE, DS:DATADATA SEGMENTARRAY DB 56H,49H,33H,05H,12H,17H,08HCOUNT EQU 6RES DB 01H DUP(?)DATA ENDSCODE SEGMENTSTART: MOV AX, DATA

MOV DS, AXXOR 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 ENDSEND START

RESULT:INPUT: 56H,49H,33H,05H,12H,17H,08HOUTPUT: 56H,49H,33H,05H,12H,17H,08H 05h

VIVA QUESTIONS:

1. What is the function of JNG?

2. What is the function of LEA?

3. What is the function of JNZ?

4. What is the function of XOR?

SKEC ECE DEPTPage 41

Page 42: Mpiprogram Manual

MPI LAB

APPLICATION PROGRAMS

7A). ALP FOR FINDING SUM OF NATURAL NUMBERS

ASSUME CS:CODE, DS:DATADATA SEGMENTN1 DB 1H,2H,3H,4H,5H,6HCOUNT EQU 6HRES DB 01H DUP(0)DATA ENDSCODE SEGMENTSTART: MOV AX, DATA

MOV DS, AXMOV CL,COUNTXOR AX, AXXOR BX,BXMOV SI, OFFSET N1

BACK: MOV BL, [SI] ADD AL,BL

INC SIDEC CLJNZ BACKMOV DI, OFFSET RESMOV [DI],ALINT 21HCODE ENDS

END START

RESULT:

INPUT:1H,2H,3H,4H,5H,6H

OUTPUT:AL=15H

VIVA QUESTIONS:

1. What is the equivalent instruction of MOV SI,OFFSET N1?

2. What is the use of LOOP instruction?

3. What is the difference between MOV BL,[SI] and MOV [BL],SI?

4. What is the purpose of DEC CL?

SKEC ECE DEPTPage 42

Page 43: Mpiprogram Manual

MPI LAB

7B). ALP FOR FINDING SQURES OF NATURAL NUMBERS

ASSUME CS:CODE, DS:DATADATA SEGMENTN1 DB 1H,2H,3H,4H,5HCOUNT EQU 5HRES DB 01H DUP(0)DATA ENDS

CODE SEGMENTSTART: MOV AX, DATA MOV DS, AX MOV CX,COUNT XOR AX, AX MOV BX,00 LEA SI,N1BACK: 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. What is the equivalent instruction of LEA SI,N1?

2. Where is the output stored for the instruction MUL AL?

3. What is the difference between MOV instruction and LEA instruction?

4. What is the purpose of INC SI?

SKEC ECE DEPTPage 43

Page 44: Mpiprogram Manual

MPI LAB

7C). ALP FOR FINDING QUBES OF NATURAL NUMBERS

ASSUME CS:CODE, DS:DATA

DATA SEGMENTN1 DB 1H,2H,3H,4H,5HCOUNT EQU 5HRES DB 01H DUP(0)DATA ENDSCODE SEGMENTSTART: MOV AX, DATA MOV DS, AX MOV CX,COUNT XOR AX, AX MOV BX,00 LEA SI,N1BACK: 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. What is the equivalent instruction of LEA SI,N1?

2. Where is the output for the instruction XOR AX,AX?

3. What is the difference between ADD AL,BL and ADD BL,AL?

4. What is the difference between MOV BX,00 and XOR BX. BX?

SKEC ECE DEPTPage 44

Page 45: Mpiprogram Manual

MPI LAB

7D). ALP TO FIND A FACTORIAL OF A GIVEN NUMBER.

ASSUME CS:CODE,DS:DATADATA SEGMENTNUM1 DW 01HNUM2 DW 06HRESULT DW 01H DUP(?)DATA ENDSCODE SEGMENTSTART : 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 ENDSEND START

RESULT: INPUT: 7OUTPUT: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 DEPTPage 45

Page 46: Mpiprogram Manual

MPI LAB

7E).WRITE ALP FOR FINDING PERFECT SQURE ROOT OF A GIVEN NUMBER.

ASSUME CS:CODE,DS:DATADATA SEGMENTNUM EQU 36RESULT DB 01H DUP(?)DATA ENDSCODE SEGMENTSTART : 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 UPZRESULT: MOV RESULT,AL INT 21H CODE ENDSEND 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 DEPTPage 46

Page 47: Mpiprogram Manual

MPI LAB

8 (A). WRITE ALP FOR COUNTING OF EVEN AND ODD NUMBERS IN GIVEN SERIES.

ASSUME CS:CODE, DS:DATADATA SEGMENTN1 DB 56H, 49H, 33HRES DB 01H DUP(0)DATA ENDSCODE SEGMENTSTART: MOV AX, DATA

MOV DS, AXXOR AX, AXMOV SI, OFFSET N1MOV DX, 0000HMOV BX, 0000HMOV CX, 0003H

BACK: MOV AL, [SI]ROR AL, 01HJC XINC BXJMP Y

X: INC DX Y: INC SI

DEC CXJNZ BACKMOV DI, OFFSET RESMOV [DI],BXINC DIMOV [DI],DXINT 21HCODE ENDS

END START

RESULT:I/P : 56H 49H 33HO/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 DEPTPage 47

Page 48: Mpiprogram Manual

MPI LAB

8 (B).WRITE ALP FOR COUNTING OF POSITIVE AND NEGATIVE

NUMBER’S IN GIVEN SERIES.

ASSUME CS:CODE, DS:DATADATA SEGMENTN1 DB 51H, 20H, 33H,80H,19HRES DB 01H DUP(0)DATA ENDSCODE SEGMENTSTART: MOV AX, DATA

MOV DS, AXXOR AX, AXMOV SI, OFFSET N1MOV DX, 0000HMOV BX, 0000HMOV CX, 0005HBACK: MOV AL, [SI]ROL AL, 01HJC XINC BXJMP Y

X: INC DX Y: INC SI

DEC CXJNZ BACK MOV DI,OFFSET RESMOV [DI],BXINC DIMOV [DI],DXINT 21HCODE ENDS

END START

RESULT:I/P : 56H 49H 33HO/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 DEPTPage 48

Page 49: Mpiprogram Manual

MPI LAB

8C). TO FIND NUMBER OF LOGICAL ONES AND ZEROS IN A GIVEN DATA

ASSUME CS: CODE,DS:DATADATA SEGMENT X DB 0AAH ONE DB ? ZERO DB ?DATA ENDSCODE SEGMENTSTART: 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 STARTRESULT: Input: 0AAh(1010 1010)

Output: Ones 04‐‐‐‐‐‐‐‐Zeros 04‐‐‐‐‐‐‐‐

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 DEPTPage 49

Page 50: Mpiprogram Manual

MPI LAB

8D). WRITE ALP TO GENERATE FIBONNACI SERIES.

ASSUME CS:CODE,DS:DATADATA SEGMENTNUM1 DB 00HNUM2 DB 01HCOUNT EQU 0AHM DB 09H DUP(?)DATA ENDSCODE SEGMENTSTART : 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 ENDSEND START

RESULT: INPUT: 00,01OUTPUT: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 DEPTPage 50

Page 51: Mpiprogram Manual

MPI LAB

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

ASSUME CS:CODE, DS:DATA

DATA SEGMENTN1 DB 63HN2 DB 23HAVG DB 01H DUP(0)DATA ENDSCODE SEGMENTSTART: 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 DEPTPage 51

Page 52: Mpiprogram Manual

MPI LAB

8F).ALP FOR FINDING THE 1’S COMPLEMENT OF AN GIVEN 8 BIT NUMBER

USING INDIRECT ADDRESSING MODE

ASSUME CS:CODE,DS:DATADATA SEGMENTNUMBER DB 55hCOMPLIMENT DB 1 DUP(0)DATA ENDSCODE SEGMENT

START:MOV AX,DATA MOV DS,AX XOR AX,AX MOV AL,NUMBER NOT AL MOV COMPLIMENT, AL INT 21H CODE ENDSEND 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 DEPTPage 52

Page 53: Mpiprogram Manual

MPI LAB

8G). ALP FOR FINDING THE 1’S COMPLEMENT OF AN GIVEN 8 BIT NUMBER SERIES USING INDIRECT ADDRESSING MODE

ASSUME CS:CODE,DS:DATADATA SEGMENTLIST DB 02h,03H,05H,07H,11H,13HCOUNT EQU 06COMPLIMENT DB 6 DUP(0)DATA ENDSCODE SEGMENTSTART: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 ENDSEND 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 DEPTPage 53

Page 54: Mpiprogram Manual

MPI LAB

8H).ALP FOR FINDING THE 2’S COMPLEMENT OF AN GIVEN 8 BIT NUMBER USING INDIRECT ADDRESSING MODE

ASSUME CS:CODE,DS:DATADATA SEGMENTNUMBER DB 55hCOMPLIMENT DB 1 DUP(0)DATA ENDSCODE SEGMENTSTART:MOV AX,DATA MOV DS,AX XOR AX,AX MOV AL,NUMBER NOT AL ADD AL,01H MOV COMPLIMENT, AL INT 21H CODE ENDSEND 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 DEPTPage 54

Page 55: Mpiprogram Manual

MPI LAB

8I).ALP FOR FINDING THE 2’S COMPLEMENT OF AN GIVEN 8 BIT NUMBER SERIES USING INDIRECT ADDRESSING MODE

ASSUME CS:CODE,DS:DATADATA SEGMENTLIST DB 02h,03H,05H,07H,11H,13HCOUNT EQU 06COMPLIMENT DB 6 DUP(0)DATA ENDSCODE SEGMENTSTART: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 ENDSEND 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 DEPTPage 55

Page 56: Mpiprogram Manual

MPI LAB

8J).ALP FOR ARITHMETIC MEAN OF 8-BIT NUMBER USING INDIRECT ADDRESSING MODE

ASSUME CS:CODE,DS:DATADATA SEGMENTFIRST DW 5HMEAN DW 1 DUP(0)DATA ENDSCODE SEGMENTSTART: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 ENDSEND 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 DEPTPage 56

Page 57: Mpiprogram Manual

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 GPR’s (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 DEPTPage 57

Page 58: Mpiprogram Manual

MPI LAB

8L). WRITE ALP TO CONVERT 8 BIT BINARY NUMBER INTO EQUIVALENT GRAY CODE

ASSUME CS:CODE,DS:DATADATA SEGMENTNUM EQU 34HRESULT DB 01H DUP(?)DATA ENDSCODE SEGMENTSTART: 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 ENDSEND START

RESULT: INPUT: AL=34H OUTPUT:AL=2E

VIVA QUESTIONS:

1). Direction of Data bus is ______.

2). What is Intel’s 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 DEPTPage 58

Page 59: Mpiprogram Manual

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:DATADATA SEGMENTDIM EQU 09HMAT1 DB 01,02,03,04,05,06,07,08,09MAT2 DB 01,02,03,04,05,06,07,08,09RMAT3 DW 09H DUP(?)DATA ENDSCODE SEGMENTSTART: MOV AX,DATA MOV DS,AX MOV CX,DIM MOV SI ,OFFSET MAT1 MOV DI , OFFSET MAT2 MOV BX,OFFSET RMAT3NEXT: 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 ENDSEND 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 ___________

STRING OPERATIONS

SKEC ECE DEPTPage 59

Page 60: Mpiprogram Manual

MPI LAB

10A). WRITE ALP FOR 8086 STRING MANIPULATION – SORTING

ASSUME CS: CODE, DS: DATADATA SEGMENTLIST DW 53H, 25H, 19H, 02HCOUNT EQU 04HDATA ENDSCODE SEGMENTSTART: MOV AX, DATA

MOV DS, AX MOV DX, COUNT-1LOOP2: MOV CX, DX MOV SI, OFFSET LISTAGAIN: MOV AX, [SI] CMP AX, [SI+2] JC LOOP1 XCHG [SI +2], AX XCHG [SI], AXLOOP1: ADD SI, 02 LOOP AGAIN DEC DX JNZ LOOP2 INT 21H CODE ENDSEND 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

10B). WRITE ALP FOR SEARCHING WORD IN A GIVEN STRING.

SKEC ECE DEPTPage 60

Page 61: Mpiprogram Manual

MPI LAB

ASSUME CS: CODE, DS: DATADATA SEGMENTLIST DW 53H, 15H, 19H, 02HDEST EQU 3000HCOUNT EQU 05HDATA ENDSCODE SEGMENTSTART: 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 ENDSEND 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 DEPTPage 61

Page 62: Mpiprogram Manual

MPI LAB

10C) WRITE ALP FOR DATA TRANSFER FROM ONE SEGMENT TO ANOTHER SEGMENT

ASSUME CS:CODE, DS:DATA, ES:EXTRADATA SEGMENTN1 DB 01H,02H,03HDATA ENDSEXTRA SEGMENTN2 DB 03H DUP (00)EXTRA ENDSCODE SEGMENTSTART: MOV AX, DATA

MOV DS, AXMOV AX, EXTRAMOV ES, AXMOV SI, OFFSET N1MOV DI, OFFSET N2CLDMOV CX, 0003HREP MOVSBINT 21HCODE ENDS

END START

RESULT:I/P : 01H, 02H, 03HO/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 DEPTPage 62

Page 63: Mpiprogram Manual

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 002c13BC: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 …………….MICROP13BC: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 DEPTPage 63

Page 64: Mpiprogram Manual

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 DEPTPage 64

Page 65: Mpiprogram Manual

MPI LAB

10F).WRITE 8086 ALP FOR STRING COMPARISION.

DATA SEGMENTSTRING1 DB 'EMPTY'STRLEN EQU ($-STRING1)NOTSFUL DB 'STRINGS ARE UNEQUAL$'SFUL DB 'STRINGS ARE EQUAL$'DATA ENDSEXTRA SEGMENTSTRING2 DB 'EMPTY'EXTRA ENDSCODE SEGMENTASSUME CS:CODE, DS:DATA, ES:EXTRASTART: MOV AX, DATA

MOV DS, AXMOV AX, EXTRAMOV ES, AXMOV SI, OFFSET STRING1MOV DI, OFFSET STRING2CLDMOV CX,LENGTH STRING1MOV CX, STRLENREP CMPSBJZ FORWMOV AH, 09HMOV DX, OFFSET NOTSFULINT 21HJMP EXITP

FORW:MOV AH,09HMOV DX, OFFSET SFULINT 21HEXITP:NOPINT 21HCODE 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 DEPTPage 65

Page 66: Mpiprogram Manual

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 DEPTPage 66

Page 67: Mpiprogram Manual

MPI LAB

10H).WRITE 8086 ALP FOR FINDING THE LENGTH OF THE STRING.

DATA SEGMENTSTRING1 DB 'EMPTY VESSELS MAKE MORE NOISE$'STRLEN EQU ($-STRING1)RES DB 0CORT DB 'STRLENGTH FOUND CORRECT$'INCORT DB 'STRLENGTH FOUND INCORRECT$'DATA ENDSCODE SEGMENTASSUME CS:CODE, DS:DATASTART: MOV AX, DATA

MOV DS, AXSUB CL, CLMOV BL, STRLENMOV SI, OFFSET STRING1

BACK: LODSBINC CLCMP AL,'$'JNZ BACKMOV RES, CLCMP CL, BLJZ CORRECTMOV DX, OFFSET INCORTMOV AH, 09INT 21H

CORRECT: MOV DX, OFFSET CORTMOV AH, 09INT 21HMOV AH, 4CHINT 21HCODE 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 DEPTPage 67

Page 68: Mpiprogram Manual

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 SEGMENTLIST DW 53H, 15H, 19H, 02H REPLACE EQU 30HCOUNT EQU 05HDATA ENDSCODE SEGMENT START: MOV AX, DATA

MOV DS, AXMOV AX, 15HMOV SI, OFFSET LISTMOV CX, COUNTMOV AX, 00CLD

REP SCASWJNZ LOOPMOV DI, LABEL LISTMOV [DI], REPLACE

LOOP MOV AH, 4CHINT 21H

CODE ENDSEND START

INPUT: LIST: 53H, 15H, 19H, 02H

OUTPUT 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 DEPTPage 68

Page 69: Mpiprogram Manual

MPI LAB

11) PROGRAM TO FIND FACTORIAL OF A NUMBER USING PROCEDURE

ASSUME CS:CODE,DS:DATADATA SEGMENTNUM EQU 3MSG DB 'FACTORIAL OF ',NUM+'0',' IS:'ASCRES DB 4 DUP(?),'H',0DH,0AH,'$'RES DW ?HEXCODE DB '0123456789ABCDEF'DATA ENDS

HEX_ASC PROCMOV DL,10HMOV AH,0MOV BX,0DIV DL ;DIV AL/DL WHERE AL=CHAR & DL=10HMOV BL,AL ;AL=QUOTIENTMOV DH,HEXCODE[BX]MOV BL,AH ;AH=REMAINDERMOV DL,HEXCODE[BX]RET

HEX_ASC ENDP

FACT PROCCMP AX,01 ;IF N=1, FACT=1 ELSE FACT=N*FACT(N 1)‐JE EXITPUSH AXDEC AX ;N 1‐

CALL FACT ;FACT(N 1)‐POP AXMUL RES ;N*FACT(N 1)‐MOV RES,A X ;RES=FACTORIALRET

EXIT:MOV RES,01 RETFACT ENDP

MAIN: MOV AX,@DATAMOV DS,AXMOV AX,NUM ;AX=NCALL FACTMOV AL,BYTE PTR RES+1 ;CONVERT MSB OF RESULT TO ASCIICALL HEX_ASC

SKEC ECE DEPTPage 69

Page 70: Mpiprogram Manual

MPI LAB

MOV ASCRES,DHMOV ASCRES+1,DLMOV AL,BYTE PTR RES ;CONVERT LSB OF RESULT TO ASCIICALL HEX_ASCMOV ASCRES+2,DHMOV ASCRES+3,DLMOV AH,09HMOV DX,OFFSET MSG ;DISPLAY MSGINT 21HMOV AH,4CH ;EXITINT 21HALIGN 16

END MAIN

Output:Factorial of the number is 06

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 DEPTPage 70

Page 71: Mpiprogram Manual

MPI LAB

INTERFACE PROGRAMS12).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 ;Initialise Segment MOV ES,AX ;Registers MOV DX,FFE6H ;Initialise MOV AL,8BH ;8255 Port A OUT DX,AL ;as O/p, Port B JMP SHORT MAIN ;Port C as I/P

; Display Message string

CHA: DB 0DH,'CHANNEL NO: ', 0HDIG: DB 0AH, 0DH,'DIGITAL VALUE:',0H

MAIN: MOV CX,00HNEXT: CALL CONVERT ;Call A/D Conv. routine CALL DISP ;Call Display routine CALL UPDT ;Call Ch. update routine JMP SHORT NEXT ;Repeat continuously

CONVERT: MOV AL,00H ;Initialize OR AL,CL ;Add channel MOV DX,0FFE0H ;Load channel Value OUT DX,AL MOV AL,20H ;Assert Start OR AL,CL ;signal to ADC OUT DX,AL NOP NOP NOP MOV AL,00H ;Start pulse over

SKEC ECE DEPTPage 71

Page 72: Mpiprogram Manual

MPI LAB

OR AL,CL OUT DX,AL MOV DX,FFE4H ;Wait for EndEOC: IN AL,DX ;of Conversion AND AL,01H JNZ EOCCHECK: IN AL,DX ;Check for End of Conversion AND AL,01 JE CHECK ;signal from ADC MOV AL,40H ;Assert Read OR AL,CL ;Signal MOV DX,0FFE0H ;Read Converted OUT DX,AL MOV DX,0FFE2H IN AL,DX PUSH AX MOV AL,00H ;Deassert Read signal OR AL,CL MOV DX,FFE0H OUT DX,AL POP AX RET

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 DEPTPage 72

Page 73: Mpiprogram Manual

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 ;INITIALISE SEGMENT REGISTERS MOV CS,AX MOV ES,AX 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 TEST: DB 0DH,20H,'CONVERTING... ', 00H MES: DB 0AH,0DH,20H, 'DIGITAL VALUE = ',00H

START: MOV DX,0FFE4H ;wait for start of conversion(SOC) IN AL,DX CALL DELAY CALL DELAY AND AL,02H JZ START MOV AX,0FFH PUSH AX CONT: MOV DX,0FFE4H ;check for SOC IN AL,DX CALL DELAY AND AL,02H JNZ START ;If true start again POP AX ;else continue MOV DX,0FFE0H INC AL ;increment count and OUT DX,AL ;output to port PUSH AX PUSH DX LEA DX,TEST ;display 'converting...' MOV AX,DX POP DX

SKEC ECE DEPTPage 73

Page 74: Mpiprogram Manual

MPI LAB

CALL FAR 0FE00:0013H CALL DELAY MOV DX,0FFE4H ;read comparator output IN AL,DX AND AL,00000001B JNZ CONT ;if PC0=1,continue else LEA DX,MES ;conversion is over MOV AX,DX CALL FAR 0FE00:0013H ;display message POP AX CALL FAR 0FE00:0052H ;DISPLAY OUTPUT CALL FAR 0FE00:0031H JMP SHORT START

DELAY: MOV CX,8000H ;delay routine HERE: LOOP HERE RET END

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 DEPTPage 74

Page 75: Mpiprogram Manual

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 ; Configure 8255 MOV AL,82H ; Port A as o/p, Port B as i/p OUT DX,AL XOR AX,AX ; Initial stage is ground floor

LOOP1: MOV AL,AH ; AH is the floor position OR AL,0F0H MOV DX,0FFE0H OUT DX,AL

MOV DX,0FFE2HLOOP2: IN AL,DX ; Get request AND AL,0FH CMP AL,0FH JZ LOOP2 MOV SI,00HFINDF: ROR AL,01H JNC FOUND ;If requested floor found INC SI JMP SHORT FINDF ; Otherwise, continue searchFOUND: MOV AL,[SI]2100H ; Get requesting floor code CMP AL,AH ; Compare with current floor JA GOUP ; If it need to go UP JB GODN ; If it need to g DOWNCLEAR: MOV AL,[SI]2104H MOV DX,0FFE0H OUT DX,AL JMP SHORT LOOP1GOUP: CALL DELAY INC AH ; Elevator goes UP by one LED XCHG AL,AH OR AL,0F0H MOV DX,0FFE0H OUT DX,AL AND AL,0FH XCHG AH,AL

SKEC ECE DEPTPage 75

Page 76: Mpiprogram Manual

MPI LAB

CMP AL,AH JNZ GOUP JMP SHORT CLEARGODN: 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 CLEARDELAY: MOV CX,0800H ; Delay between glow of successive LEDsHR1: LOOP HR1HR2: 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 ; Configure 8255 MOV AL,82H ; Port A as o/p, Port B as i/p OUT DX,AL XOR AX,AX ; Initial stage is ground floor

LOOP1: MOV AL,AH ; AH is the floor position OR AL,0F0H MOV DX,0FFE0H OUT DX,AL

MOV DX,0FFE2HLOOP2: IN AL,DX ; Get request AND AL,0FH CMP AL,0FH JZ LOOP2

MOV SI,00HFINDF: ROR AL,01H JNC FOUND ;If requested floor found INC SI JMP SHORT FINDF ; Otherwise, continue searchFOUND: MOV AL,[SI]2100H ; Get requesting floor code CMP AL,AH ; Compare with current floor

SKEC ECE DEPTPage 76

Page 77: Mpiprogram Manual

MPI LAB

JA GOUP ; If it need to go UP JB GODN ; If it need to g DOWNCLEAR: MOV AL,[SI]2104H MOV DX,0FFE0H OUT DX,AL JMP SHORT LOOP1GOUP: CALL DELAY INC AH ; Elevator goes UP by one LED 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 CLEARGODN: 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 CLEARDELAY: MOV CX,0800H ; Delay between glow of successive LEDsHR1: LOOP HR1HR2: LOOP HR2 RET

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 DEPTPage 77

Page 78: Mpiprogram Manual

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 2500ADORG 2000H

START: MOV AL,80H ; Initialization of 8255 Mode 0 MOV DX,0FFE6H OUT DX,AL ; All ports as o/p portsAGAIN: MOV SI,2038H ; Table of port valuesNEXTST: 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 AGAINDELAY: MOV CX,0FFH ; Delay routine DLY5: PUSH CX MOV CX,03FFHDLY10: 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 DEPTPage 78

Page 79: Mpiprogram Manual

MPI LAB

DB 44H,44H,0F0H ; All ambers ON DB 00H ; 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 DEPTPage 79

Page 80: Mpiprogram Manual

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 toRAM location starting at 59h.

Program:ORG 00HMOV R0,#37h ; source pointerMOV R1,#59h ; dest pointerMOV R2,#10 ; counter

L1: MOV A,@R0MOV @R1,AINC R0INC R1DJNZ R2,L1END

Output:

SKEC ECE DEPTPage 80

Page 81: Mpiprogram Manual

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 00HMOV R0,#0AH

LOOP:ADDC A,R0DJNZ R0,LOOPMOV R1,AEND

Output: R1: 37h

VIVA QUESTIONS:

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

b) ADDITION OF TWO 16‐BIT NUMBERS:

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

Program:MOV A,R7 ;Move the low byte into the accumulator‐ADD A,R5 ;Add the second low byte to the accumulator‐MOV R3,A ;Move the answer to the low byte of the result‐MOV A,R6 ;Move the high byte into the accumulator‐ADDC A,R4 ;Add the second high byte to the accumulator, plus carry.‐MOV R2,A ;Move the answer to the high byte of the result‐MOV A,#00h ;By default, the highest byte will be zero.ADDC A,#00h ;Add zero, plus carry from step 2.MOV R1,A ;Move the answer to the highest byte of the result

Output: 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 DEPTPage 81

Page 82: Mpiprogram Manual

MPI LAB

c). 8051 - SUM OF ELEMENTS IN AN ARRAYAIM: To find the sum of elements in an array.

PROGRAM:MOV DPTR, #4200MOVX A, @DPTRMOV R0, AMOV B, #00MOV R1, BINC DPTR

LOOP2: CLR CMOVX A, @DPTRADD A, BMOV B, AJNC LOOPINC R1

LOOP: INC DPTRDJNZ R0, LOOP2MOV DPTR, #4500MOV A, R1MOVX @DPTR, AINC DPTRMOV A, B MOVX @DPTR, A

HLT: SJMP HLT

INPUT OUTPUT:

4200 04 4500 0F

4201 05 4501 00

4201 06

4202 03

4203 02

VIVA QUESTIONS:

1). What is purpose of DPTR register?

2).What is the difference between MOV and MOVX instruction?

SKEC ECE DEPTPage 82

Page 83: Mpiprogram Manual

MPI LAB

d). 8051 - HEXADECIMAL TO DECIMAL CONVERSION

AIM: To perform hexadecimal to decimal conversion.

PROGRAM: MOV DPTR, #4500MOVX A, @DPTRMOV B, #64DIV A, BMOV DPTR, #4501MOVX @DPTR, AMOV A, BMOV B, #0ADIV A, BINC DPTRMOVX @DPTR, AINC DPTRMOV A, BMOVX @DPTR, A

HLT: SJMP HLT

INPUT OUTPUT:

4500 D7 4501 15

4502 02

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 DEPTPage 83

Page 84: Mpiprogram Manual

MPI LAB

e). 8051 - DECIMAL TO HEXADECIMAL CONVERSION

AIM: To perform decimal to hexadecimal conversion

PROGRAM:

MOV DPTR, #4500MOVX A, @DPTRMOV B, #0AMUL A, BMOV B, AINC DPTRMOVX A, @DPTRADD A, BINC DPTRMOVX @DPTR, A

HLT: SJMP HLT

INPUT OUTPUT

4500 23 4501 17

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 DEPTPage 84

Page 85: Mpiprogram Manual

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 00HMOV TMOD,#02H ;8 bit auto reload mode‐ ‐MOV TH0,# 50 ‐ ; 50 reload value in TH0‐SETB TR0 ;start timer0

LOOP: JNB TF0, LOOP ;wait for overflowCLR TF0 ;clear timer0 overflow flagCPL P1.0 ;toggle port bitSJMP LOOP ;repeatEND

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 DEPTPage 85