Post on 22-Nov-2014
transcript
1
1. Students are required to attend all labs.
2. Students will work in a group of two in hardware laboratories and individually in computer laboratories.
3. While coming to the lab bring the lab manual cum observation book, record etc.
4. Take only the lab manual, calculator (if needed) and a pen or pencil to the work area.
5. Before coming to the lab, prepare the prelab questions. Read through the lab experiment to familiarize yourself with the components and assembly sequence.
6. Utilize 3 hours time properly to perform the experiment and noting down the readings. Do the calculations, draw the graph and take signature from the instructor.
7. If the experiment is not completed in the prescribed time, the pending work has to be done in the leisure hour or extended hours.
8. You will be expected to submit the completed record book according to the deadlines set up by your instructor.
9. For practical subjects there shall be a continuous evaluation during the semester for 25 sessional marks and 50 end examination marks.
10. Of the 25 marks for internal, 15 marks shall be awarded for day-to-day work and 10 marks to be awarded by conducting an internal laboratory test.
INSTRUCTIONS TO THE STUDENTS
1. INTRODUCTION TO 8086, MASM/TASM
2
This chapter is intended to serve as an introduction to the programming and some features of 8086 microprocessor. The users are requested to read 8086 architecture and organization of 8086 for better understanding.
The 8086 programming model includes general purpose registers, segment registers, flag register, base and pointer registers whose functions are briefly given below
SEGMENT REGISTERS:
Code segment register – CS – stores the base address of code segment.Stack segment register – SS – stores the base address of the stack.Data segment register – DS – stores the base address of the data.Extra segment register – ES – stores the base address of the extra segment.
INDEX REGISTERS:
Source index register – SI – stores the base address of the source data.Destination index register – DI – stores the base address of the destination data.
POINTER REGISTERS:
Instruction pointer – IP – stores the address of next instruction.Stack pointer – SP – stores the address at the top of the stack.Base pointer – BP – stores the base address.
GENERAL PURPOSE REGISTERS:
Accumulator – AX – used in all arithmetic instructions.Base register – BX – used to store base addresses while programming.Counter register – CX – used as counter during programming.Destination register – DX - used to store base addresses while programming.Extended accumulator – DX: AX – used in some arithmetic instructions.All these 16 bit registers can also be used as a pair of 2 8-bit registers.
FLAG REGISTER:
The flag register in 8086 is of 16 bit wide in which only 9 bits are used as flags and the other bits are in don’t care condition. For complete flag format the users are requested to refer to the books, here only the functions of each flags are briefly given in order to be helpful while programming.
A flag is a flip-flop, which is set or reset after an operation according to the data conditions of the result in the accumulator and other registers.
1. Zero flag – Z: The flag is set to 1 when the result is zero, otherwise it is reset.2. Carry flag (barrow) – CY: If an arithmetic operation results in a carry, the CY
flag is set, otherwise it is reset.3. Sign flag – S: The sign flag is set if the MSB bit of the result is one, otherwise
it is reset.4. Parity flag – P : If the result has an even number of 1s, the flag is set, for odd
number of 1s the flag is reset.5. Direction flag – D: This flag selects increment or decrement mode for the DI
and/or SI registers during string instructions. If D=1, the registers are
3
automatically decremented; if D=0, the registers are automatically incremented.
6. Overflow flag – O: Overflow occurs when signed numbers are added or subtracted. An overflow indicates that the result has exceeded the capacity of the machine.
7. Trap flag – T: The trap flag enables trapping through an on chip debugging feature.
8. Interrupt flag – I: The interrupt flag controls the operation of INTR input pin. If I=1 INTR is enabled otherwise it is disabled.
9. Auxiliary carry flag – AC: The auxiliary carry holds the carry( half carry) after addition or barrow after subtraction between bit positions 3 and 4 of the result. This bit is tested in special instructions like DAA and DAS.
INSTRUCTION SET OF 8086
An instruction is a command to the microprocessor to perform a given task on specified data. Each instruction has two parts: one is task to be performed, called the operation code (opcode) and the second is the data to be operated on, called the operand. The entire group of instructions, called the instruction set, determines what function the microprocessor can perform.
The 8086 instructions can be classified into following categories depending on their functions.
DATA TRANSFER INSTRUCTIONS:This group of instructions copies the data from a location called source to
another location called destination, without modifying the contents of the source. The one more specialty of this group is they will not effect any of the flags in the flag register. The data transfer may be between registers, memory location and a register, immediate data and memory or register and between I/O device and the accumulator.
ARITHMETIC INSTRUCTIONS:These instructions perform arithmetic operations such as addition,
subtraction, increment and decrement. The flags are affected by this group of instructions depending on the results they produce but some special instructions will not effect flags.
LOGICAL, SHIFTOR ROTATE INSTRUCTIONS:These instructions perform various logical operations such as AND, OR, NOT,
compare etc. These instructions will also effect flags.
BRANCHING INSTRUCTIONS:This group of instructions alters the sequence of program execution either
conditionally or unconditionally. Flags are generally used to generate conditions in case of 1st type of branch instructions.MACHINE CONTROL INSTRUCTIONS:
These instructions control machine functions such as halt, interrupt and do nothing etc.
STRING INSTRUCTIONS:These instructions special and serve the purpose of operations on strings.
4
MASM/TASM
EDITORAn editor is a program, which allows you to create a file containing the assembly language statements for your program. As you type in your program, the editor stores the ASCII codes for the letters and numbers in successive RAM locations. When you have typed in all of your programs, you then save the file on a floppy of hard disk. This file is called source file. The next step is to process the source file with an assembler. In the MASM assembler, you should give your source file name the extension, .ASM
ASSEMBLERAn assembler program is used to translate the assembly language mnemonics for instructions to the corresponding binary codes. When you run the assembler, it reads the source file of your program the disk, where you saved it after editing on the first pass through the source program the assembler determines the displacement of named data items, the offset of labels and 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 offset etc that is calculated during the first pass. The assembler generates two files on floppy or hard disk. The first file called the object file is given the extension. OBJ. The object file contains the binary codes for the instructions and information about the addresses of the instructions. The second file generated by the assembler is called assembler list file. The list file contains your assembly language statements, the binary codes for each instructions and the offset for each instruction. In MASM assembler, MASM source file name ASM is used to assemble the file. Edit source file name LST is used to view the list file, which is generated, when you assemble the file.
LINKERA linker is a program used to join several object files into one large object file and convert to an exe file. The linker produces a link file, which contains the binary codes for all the combined modules. The linker however doesn’t assign absolute addresses to the program, it assigns is said to be relocatable because it can be put anywhere in memory to be run. In MASM, MLINK source filename is used to link the file.
DEBUGGERA debugger is a program which allows you to load your object code program into system memory, execute the program and troubleshoot are debug it the debugger allows you to look at the contents of registers and memory locations after your program runs. It allows you to change the contents of register and memory locations after your program runs. It allows you to change the contents of register and memory locations and return the program. A debugger also allows you to set a break point at any point in the program. If you inset a breakpoint the debugger will run the program up to the instruction where the breakpoint is set and stop execution. You can then examine register and memory contents to see whether the results are correct at that point. In MASM, the filename is used to debug the file.
DEBUGGER FUNCTIONS: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 setting breakpoints at any point with the program.
5
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.
COMMANDS TO EXECUTE A GIVEN ALP.
1. ASSMEBLINIG : masm <file name.asm> <Enter>2. LINKING : link <file name.obj> <Enter>3. DEBUGGING : debug <file name.exe> <Enter>
DEBUGGER COMMANDS
DUMP: To see the specified memory contents D memory location first address last address (While displays the set of values stored in the specified range, which is given above)Eg: d 0100 0105 <cr>Display the contents of memory locations from 100 to 105(including).
ENTER: To enter data into the specified memory locations(s). E memory location data data data data data …<cr>Eg: e 1200 10 20 30 40 ….Enters the above values starting from memory locations 1200 to 1203, by loading 10 into 1200,20 into 1201 and soon.
GO: To execute the programG 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 ax Shows the contents of register.
TRACE: To trace the program instruction by instruction.T = 0100 <cr>: traces only the current instruction. (Instruction specified by IP)T = 0100 02 <cr>: Traces instructions from 100 to 101, here the second argument specifies the number of instructions to be traced.
UNASSEMBLE: To unassembled the program.Shows the opcodes along with the assembly language program.U 100 <cr>: unassembled 32 instructions starting from 100th location.U 0100 0109 <cr>: unassebles the lines from 100 to 104
2.1 MULTI BYTE ADDITION
AIM: To write a program to add two multi byte numbers.
APPARATUS: Computer system installed with MASM
PROGRAM:
6
DATA SEGMENTNUM1 DD 11223344HNUM2 DD 55667788HRES DD 00000000H
DATA ENDSCODE SEGMENT
ASSUME CS:CODE,DS:DATASTART:
MOV AX,DATAMOV DS,AXMOV SI,OFFSET NUM1MOV DI,OFFSET NUM2MOV BX,OFFSET RESMOV CX,03SUB AX,AXMOV AL,[SI]MOV DL,[DI]ADD AL,DLMOV [BX],AL
BACK: INC SIINC DIINC BXMOV AL,[SI]MOV DL,[DI]ADC AL,DLMOV [BX],ALLOOP BACKINT 3
CODE ENDSEND START
OBSERVATIONS:
INPUT: NUM1=
NUM2=
OUTPUT: RES=
RESULT:Multi byte addition is performed and results are observed using MASM.
EXERCISE:
1. Why is add with carry instruction adc is used in the loop?2. What is the purpose served by BX register?3. Why addition is done with AL register why not with AX?4. What is the other instruction which can be used instead of MOV SI,offset num1?
7
2.2 MULTI BYTE SUBTRACTION
AIM: To write a program to subtract two multi byte numbers.
APPARATUS: Computer system installed with MASM
PROGRAM:
DATA SEGMENTNUM2 DD 55667788HNUM1 DD 11223344HRES DD 00000000H
DATA ENDSCODE SEGMENT
8
ASSUME CS:CODE,DS:DATASTART:
MOV AX,DATAMOV DS,AXMOV SI,OFFSET NUM2MOV DI,OFFSET NUM1MOV BX,OFFSET RESMOV CX,03SUB AX,AXMOV AL,[SI]MOV DL,[DI]SUB AL,DLMOV [BX],AL
BACK: INC SIINC DIINC BXMOV AL,[SI]MOV DL,[DI]SBB AL,DLMOV [BX],ALLOOP BACKINT 3
CODE ENDSEND START
OBSERVATIONS:
INPUT: NUM1=
NUM2=
OUTPUT: RES=
RESULT:
Multi byte subtraction is performed and results are observed using MASM
EXERCISE:
1. Why is 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 NUM2?
9
2.3 8 BIT MULTIPLICATION (UNSIGNED)
AIM: To write a program to multiply two 8-bit unsigned numbers.
APPARATUS: Computer system installed with MASM
PROGRAM:
DATA SEGMENTNUM1 DB 0FFHNUM2 DB 0AAHRESULT DB 00RESULT1 DB 00
DATA ENDSCODE SEGMENTASSUME CS: CODE, DS: DATASTART:
MOV AX, DATAMOV DS, AX
10
MOV AL, NUM1MOV BL, NUM2MUL BLMOV RESULT, ALMOV RESULT1, AHINT 3
CODE ENDSEND START
OBSERVATIONS:
INPUT: NUM1=
NUM2=OUTPUT: RES=
RES1=
RESULT:
8-bit unsigned multiplication is performed and results are observed using MASM.
EXERCISE:
1. AL and BL are used for multiplying why not AX & BX?2. Instead of using MOV BL is it not possible to MUL num2?3. What is the instruction used for signed multiplication?
11
2.4 16 BIT MULTIPLICATION (UNSIGNED)
AIM: To write a program to multiply two 16-bit unsigned numbers.
APPARATUS: Computer system installed with MASM
PROGRAM:
DATA SEGMENTNUM1 DW 0FFFFHNUM2 DW 0FFFFHRESULT DW 00RESULT1 DW 00
DATA ENDSCODE SEGMENTASSUME CS: CODE, DS: DATASTART:
MOV AX,DATAMOV DS,AXMOV AX,NUM1MOV BX,NUM2MUL BX
12
MOV RESULT,AXMOV RESULT1,DXINT 3
CODE ENDSEND START
OBSERVATIONS:
INPUT: NUM1=
NUM2=OUTPUT: RESULT=
RESULT1=RESULT:
16-bit Multiplication is performed and results are observed using MASM.
EXERCISE:
1. Why AL & BL are not used in this program?2. If result exceeds 32 bit, where is it stored?
13
2.5 8 BIT DIVISION(UNSIGNED)
AIM: To write a program to perform division on two 8-bit unsigned numbers.
APPARATUS: Computer system installed with MASM
PROGRAM:
DATA SEGMENTNUM1 DB 0FFHNUM2 DB 0AAHQUOTIENT DB 00REMAINDER DB 00
DATA ENDSCODE SEGMENTASSUME CS: CODE, DS: DATASTART:
MOV AX,DATAMOV DS,AXMOV AX,0MOV DX,0MOV AL,NUM1MOV BL,NUM2DIV BLMOV QUOTIENT,ALMOV REMAINDER,AHINT 3
CODE ENDSEND START
14
OBSERVATIONS:
INPUT: NUM1=
NUM2=
OUTPUT: QUOTIENT=
REMAINDER=
RESULT:
Division of two 8-bit numbers is performed and results are observed using MASM.
EXERCISE:
1. Why is the registers DX & AX made zero in the above program?2. Where is the remainder in 8 bit division?3. Where is the quotient in 8 bit division?4. Which interrupt is used when a divide overflow error occurs?
15
2.6 16 BIT DIVISION(UNSIGNED)
AIM: To write a program to perform division on two 16-bit unsigned numbers.
APPARATUS: Computer system installed with MASM
PROGRAM:
DATA SEGMENTNUM1 DW 0FFFFHNUM2 DW 0AAAAHQUOTIENT DW 00REMAINDER DW 00
DATA ENDSCODE SEGMENTASSUME CS: CODE, DS: DATASTART:
MOV AX,DATAMOV DS,AXMOV AX,0MOV DX,0MOV AX,NUM1MOV BX,NUM2DIV BXMOV QUOTIENT,AXMOV REMAINDER,DXINT 3
CODE ENDSEND START
OBSERVATIONS:
INPUT: NUM1=
16
NUM2=
OUTPUT: QUOTIENT=
REMAINDER=
RESULT:
16-bit division is performed and results are observed using MASM.
EXERCISE:
1. What happens if DX register contains a nonzero value before DIV instruction?2. What is the instruction used for signed division?3. In the above program instead of DIV BX is it possible to use DIV num2?
17
2.7 8-BIT MULTIPLICATION (SIGNED)
AIM: To write a program to multiply two 8-bit signed numbers.
APPARATUS: Computer system installed with MASM
PROGRAM:
DATA SEGMENTNUM1 DB 0A5HNUM2 DB 20HRES DW 00H
DATA ENDS
CODE SEGMENTASSUME CS:CODE,DS:DATASTART:
MOV AX,DATAMOV DS,AXSUB AX,AXMOV AL,NUM1MOV BL,NUM2IMUL BLMOV RES,AXINT 3
CODE ENDSEND START
OBSERVATIONS:
INPUT: NUM1=
NUM2=
OUTPUT: RES=
RESULT:
18
8-bit signed multiplication is performed and results are observed using MASM.
EXERCISE:
1. What is the difference between IMUL and MUL?2. What is the use of instruction CBW?3. What is the use of instruction CWD?
19
2.8 8-BIT DIVISION (SIGNED)
AIM: To write a program to perform division on two 8-bit signed numbers.
APPARATUS: Computer system installed with MASM
PROGRAM:
DATA SEGMENTNUM1 DB 0D5HNUM2 DB 20HQUO DB 0HREM DB 0H
DATA ENDSCODE SEGMENTASSUME CS:CODE,DS:DATASTART:
MOV AX,DATAMOV DS,AXXOR AX,AXMOV AL,NUM1CBWMOV BL,NUM2IDIV BLMOV QUO,ALMOV REM,AHINT 3
CODE ENDSEND START
OBSERVATIONS:
INPUT: NUM1=
NUM2=
OUTPUT: QUO=
REM=RESULT:
8-bit signed division is performed and results are observed using MASM.
20
EXERCISE:
1. What is the purpose of XOR AX,AX?2. What is the difference between IDIV and DIV?3. What is the use of instruction CBW & CWD?
21
2.9 ASCII ADDITION
AIM: To write a program to perform ASCII addition.
APPARATUS: Computer system installed with MASM
PROGRAM:
DATA SEGMENTIP1 DB '9',0DH,0AHIP2 DB '6',0DH,0AHRES DB 0
DATA ENDSCODE SEGMENTASSUME CS:CODE,DS:DATASTART:
MOV AX,DATAMOV DS,AXXOR AX,AXMOV AL,IP1ADD AL,IP2AAAMOV RES,ALMOV AH,4CHINT 21H
CODE ENDSEND START
OBSERVATIONS:
INPUT: IP1=
IP2=
OUTPUT: RES=
RESULT:
ASCII addition is performed and results are observed using MASM.
22
EXERCISE:
1. What is the purpose of ASCII addition?2. What is the instruction used for ASCII addition?3. Why do we make use of instruction ORL AX,3030H ?4. Why is aaa after addition?
23
2.10 ASCII SUBTRACTION
AIM: To write a program to perform ASCII subtraction.
APPARATUS: Computer system installed with MASM
PROGRAM:
DATA SEGMENTIP1 DB '9',0DH,0AHIP2 DB '6',0DH,0AHRES DB 0
DATA ENDSCODE SEGMENTASSUME CS:CODE,DS:DATASTART:
MOV AX,DATAMOV DS,AXXOR AX,AXMOV AL,IP1SUB AL,IP2AASMOV RES,ALMOV AH,4CHINT 21H
CODE ENDSEND START
OBSERVATIONS:
INPUT: IP1=
IP2=
OUTPUT: RES=
RESULT:
ASCII subtraction is performed and results are observed using MASM.
EXERCISE:
24
1. What is the purpose of ASCII subtraction?2. What is the instruction used for ASCII subtraction?3. Why do we make use of instruction ORL AX,3030H ?4. Why is aas after addition?
EXERCISE PROGRAMS
25
3.1.1 SUM OF DIGITS OF A GIVEN 16-BIT NUMBER
AIM: To write a program to find the sum of digits of a given 16-bit number 16-Bit number should be given at ds:2000, and result will be available at ds:3000h.
APPARATUS: Computer system installed with MASM
PROGRAM:
26
CODE SEGMENT
ASSUME CS:CODE
START:MOV AX,DS:2000H
MOV SI,0010H MOV DX,0000H MOV BX,0 MOV CX,0004H NEXT:DIV SI ADD BX,DX MOV DX,0000H LOOP NEXT MOV DS:3000H,BX INT 3
CODE ENDSEND START
OBSERVATIONS:
INPUT: DS:2000H =
OUTPUT: DS:3000H =
RESULT:
Sum of digits of a given 16-bit number is performed and results are observed using MASM.
EXERCISE:1. What is the logic used to find sum of digits of a given number?2. What a LOOP instruction would do in the above program?
27
3.1.2 CHECK WHETHER A GIVEN 16-BIT NUMBER IS EVEN OR ODD
AIM: To write a program to check whether a given 16-bit number is even or odd.
Note: 16-Bit number should be given at ds:2000, and result will be availableat ds:3000h. If the number is even, store ffffh at ds:3000h, and if it is odd, store1111h at ds:3000H
APPARATUS: Computer system installed with MASM
28
PROGRAM:
CODE SEGMENT
ASSUME CS:CODE
START:MOV AX,DS:2000H
MOV BX,0002H MOV CX,0000H DIV BX CMP DX,CX JE EVEN_NUM MOV DS:3000H,1111H JMP EXITEVEN_ NUM:MOV DS:3000H,0FFFFH EXIT:INT 3
CODE ENDSEND START
OBSERVATIONS:
INPUT: DS:2000H =
OUTPUT: DS:3000H =
RESULT:
Checking whether a given 16-bit number is even or odd is performed and results are observed using MASM.
EXERCISE:1. How can we differentiate between an even number and an odd number?
29
3.1.3 CHECK WHETHER A GIVEN 16-BIT NUMBER IS POSITIVE OR NEGATIVE
AIM: To write a program to check whether a given 16-bit number is positive or negative.Note: 16-Bit number should be given at ds:2000, and result will be availableat ds:3000h. If the number is positive, store ffffh at ds:3000h, and if it is negative,store 1111h at ds:3000h
APPARATUS: Computer system installed with MASM
PROGRAM:
CODE SEGMENT
ASSUME CS:CODE
30
START:MOV AX,DS:2000H
ROL AX,1 JC NEG_NUM MOV DS:3000H,0FFFFH JMP EXITNEG_NUM:MOV DS:3000H,1111H EXIT:INT 3
CODE ENDSEND START
OBSERVATIONS:
INPUT: DS:2000H =
OUTPUT: DS:3000H =
RESULT:
Checking whether a given 16-bit number is positive or negative is performed and results are observed using MASM.
EXERCISE:1. How can we differentiate between a positive number and a negative number?
31
3.2 PACKED TO UNPACKED BCD
AIM: To write a program to convert a packed BCD number to unpacked BCD number.
APPARATUS: Computer system installed with MASM
PROGRAM:
DATA SEGMENTBCDIP DB 56HUBCDOP DW 0
DATA ENDSCODE SEGMENT
ASSUME CS:CODE,DS:DATASTART:
MOV AX,DATA
32
MOV DS,AXXOR AX,AXMOV AL, BCDIPMOV DL,ALAND AL,0F0HMOV CL,4ROR AL,CLMOV BH,ALAND DL,0FHMOV BL,DLMOV UBCDOP,BXINT 3
CODE ENDSEND START
OBSERVATIONS:
INPUT: BCDIP=
OUTPUT: UBCDOP=
RESULT:Conversion of packed BCD to unpacked BCD is performed and results are
observed using MASM.
EXERCISE:
1. What is the purpose of the instruction ROR AL, CL?2. What is the purpose of the instruction AND AL, 0FH & AND AL,0F0H in the program.?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?
33
3.3 BCD to ASCII CONVERSION
AIM: To write a program to convert a BCD number to its equivalent ASCII number.
APPARATUS: Computer system installed with MASM
PROGRAM:
DATA SEGMENTBCDIP DB 56HASCOP DW 0
DATA ENDSCODE SEGMENT
ASSUME CS:CODE,DS:DATASTART:
MOV AX,DATAMOV DS,AXXOR AX,AXMOV AL, BCDIPMOV DL,ALAND AL,0F0H
34
MOV CL,4ROR AL,CLMOV BH,ALAND DL,0FHMOV BL,DLADD BX,3030HMOV ASCOP,BXINT 3
CODE ENDSEND START
OBSERVATIONS:
INPUT: BCDIP=
OUTPUT: ASCOP=
RESULT:
Conversion of BCD to ASCII is performed and results are observed using MASM.
EXERCISE:1. What is the difference between adding 30h and OR 30H to a BCD number to conversion to ASCII?2. Why unpacking is necessary during the conversion?3. What is the ASCII character for symbol A?4. What is the ASCII character for symbol zero ‘0’?
35
EXERCISE PROGRAMS:
36
4.1 BLOCK TRANSFER
AIM: To write a program to transfer a block of characters from one place to another place using string instructions.
APPARATUS: Computer system installed with MASM
PROGRAM:
DATA SEGMENTSRC DB 'EMPTY VESSELS MAKE MUCH NOISE',24H
DATA ENDSEXTRA SEGMENT
DST DB 12 DUP(0)EXTRA ENDSCODE SEGMENT
ASSUME CS:CODE,DS:DATA,ES:EXTRASTART:
MOV AX,DATAMOV DS,AXMOV AX,EXTRAMOV ES,AXMOV SI,OFFSET SRCMOV DI,OFFSET DSTCLDMOV CX,29REP MOVSBNOPMOV AH,4CHINT 21H
37
CODE ENDSEND STARTOBSERVATIONS:
INPUT: SRC=
OUTPUT: DST=
RESULT:
Block transfer is performed and results are observed using MASM.
EXERCISE: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?
38
4.2 STRING REVERSAL
AIM: To write a program to reverse a given string.
APPARATUS: Computer system installed with MASM
PROGRAM:
DATA SEGMENTSTRING1 DB 'EMPTY'STRLEN EQU ($-STRING1)STRING2 DB 5 DUP(0)
DATA ENDSCODE SEGMENT
ASSUME CS:CODE,DS:DATA,ES:DATASTART:
MOV AX,DATAMOV DS,AXMOV ES,AXMOV BX,OFFSET STRING1MOV SI,BXMOV DI,OFFSET STRING2ADD DI,STRLENCLDMOV CX,STRLEN
A1: MOV AL,[SI]MOV ES:[DI],ALINC SIDEC DILOOP A1;REP MOVSB;NOPMOV AH,4CHINT 21H
39
CODE ENDSEND START
OBSERVATIONS:
INPUT: STRING1=
OUTPUT: STRLEN=
STRING2=
RESULT:
String reversal is performed and results are observed using MASM.
EXERCISE:
1. Why BX register is added with ‘5’?2. Why MOVS instruction is not used?3. What is the function of LODS and STOS instructions?
40
4.3 SORTING(ASCENDING)
AIM: To write a program to sort a given list of numbers in ascending order.
APPARATUS: Computer system installed with MASM
PROGRAM:
DATA SEGMENTLIST DB 12H, 34H, 21H, 56H, 32HCOUNT EQU 5
DATA ENDSCODE SEGMENT
ASSUME CS:CODE, DS:DATASTART:
MOV AX, DATAMOV DS, AXMOV DI, OFFSET LISTMOV CL, COUNTDEC CL INC DI
LOOP1:MOV DL,CLLOOP2:MOV AL,[DI]
CMP AL,[DI +1]JNC ProceedXCHG AL,[DI+1]MOV [DI],AL
PROCEED: INC DI LOOP LOOP2NOP MOV CL,DLLOOP LOOP1INT 3
CODE ENDSEND START
OBSERVATIONS:
INPUT: LIST:
41
OUTPUT: LIST(SORTED):
RESULT:Sorting of a given list of numbers is performed and results are observed using
MASM.
EXERCISE:1. What is the sorting technique used in above program?2. Are there any other ways to sort a list?
42
4.4 SORTING(DESCENDING)
AIM: To write a program to sort a given list of numbers in descending order.
APPARATUS: Computer system installed with MASM
PROGRAM:
DATA SEGMENTLIST DB 12H, 34H, 21H, 56H, 32HCOUNT EQU 5
DATA ENDSCODE SEGMENT
ASSUME CS:CODE, DS:DATASTART:
MOV AX, DATAMOV DS, AXMOV DI, OFFSET LISTMOV CL, COUNTDEC CL INC DI
LOOP1:MOV DL,CLLOOP2:MOV AL,[DI]
CMP AL,[DI +1]JC ProceedXCHG AL,[DI+1]MOV [DI],AL
PROCEED: INC DI LOOP LOOP2NOP MOV CL,DLLOOP LOOP1INT 3
CODE ENDSEND START
OBSERVATIONS:
INPUT: LIST:
OUTPUT: LIST(SORTED):
RESULT:Sorting of a given list of numbers is performed and results are observed using
MASM.
43
EXERCISE:1. What is the sorting technique used in above program?2. Are there any other ways to sort a list?
44
4.5 STRING INSERTION
AIM: To write a program to insert a word in the given sentence.
APPARATUS: Computer system installed with MASM
PROGRAM:
DATA SEGMENTSTRING1 DB 'EMPTY VESSELS MORE NOISE$'STRLEN EQU ($-STRING1)
DATA ENDSEXTRA SEGMENT
STRING2 DB STRLEN+5 DUP(0)EXTRA ENDSCODE SEGMENT
ASSUME CS:CODE,DS:DATA,ES:EXTRASTART:
MOV AX,DATAMOV DS,AXMOV SI,OFFSET STRING1MOV DI,OFFSET STRING2CLDMOV CX,14REP MOVSBMOV DL,5BACK: MOV AH,01INT 21HSTOS STRING2DEC DLJNZ BACKMOV CX,11REP MOVSBNOPMOV AH,4CHINT 21H
CODE ENDSEND START
OBSERVATIONS:
INPUT: NUM1=
NUM2=
OUTPUT: RES=
RESULT:String insertion is performed and results are observed using MASM.
EXERCISE:1. Why register ‘DI’ is loaded with 5?
45
2. What is the function of rep movsb?3. What is the purpose of mov ah,01h / int 21h?
4.6 STRING DELETION
AIM: To delete a word from the given sentence.
APPARATUS: Computer system installed with MASM
46
PROGRAM:
DATA SEGMENTSTRING1 DB 'EMPTY VESSELS MAKE MORE NOISE$'STRLEN EQU ($-STRING1)
DATA ENDS
EXTRA SEGMENTSTRING2 DB STRLEN-5 DUP(0)
EXTRA ENDS
CODE SEGMENTASSUME CS:CODE,DS:DATA,ES:EXTRA
START: MOV AX,DATAMOV DS,AXMOV AX,EXTRAMOV ES,AXMOV SI,OFFSET STRING1MOV DI,OFFSET STRING2CLDMOV CX,13REP MOVSBCLDMOV SI,18MOV CX,12REP MOVSBMOV AH,4CHINT 21H
CODE ENDSEND START
OBSERVATIONS:
INPUT: STRING1=
STRLEN=
OUTPUT: STRING2=
RESULT:String deletion is performed and results are observed using MASM.
EXERCISE:1. What is the purpose of string length?2. What does ‘equ’ stands for?3. What is the purpose of label start after the end directive?
47
4.7 LENGTH OF THE STRING
AIM: To write a program to find the length of the given string.
APPARATUS: Computer system installed with MASM
PROGRAM:
DATA SEGMENTSTRING1 DB 'EMPTY VESSELS MAKE MORE NOISE$'
48
STRLEN EQU ($-STRING1)RES DB 0CORT DB 'STRLENGTH FOUND CORRECT$'INCORT DB 'STRLENGTH FOUND INCORRECT$'
DATA ENDSCODE SEGMENT
ASSUME CS:CODE,DS:DATASTART:
MOV AX,DATAMOV 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 21HCORRECT:MOV DX,OFFSET CORTMOV AH,09INT 21HMOV AH,4CHINT 21H
CODE ENDSEND START
OBSERVATIONS:
INPUT: STRING1=
STRLEN=
OUTPUT: RES=RESULT:
Length of a string is performed and results are observed using MASM.
EXERCISE:1. What is the operation performed by the instruction cmp al,$ ?2. What is function 09h / int 21h performed?3. Why SI is not been incremented is the program?
49
4.8 STRING COMPARISIONAIM: To write a program to compare two strings.
APPARATUS: Computer system installed with MASM
PROGRAM:
DATA SEGMENTSTRING1 DB 'EMPTY'STRLEN EQU ($-STRING1)NOTSFUL DB 'STRINGS ARE UNEQUAL$'SFUL DB 'STRINGS ARE EQUAL$'
DATA ENDSEXTRA SEGMENT
50
STRING2 DB 'EMPTY'EXTRA ENDSCODE SEGMENT
ASSUME CS:CODE,DS:DATA,ES:EXTRASTART:
MOV AX,DATAMOV DS,AXMOV AX,EXTRAMOV ES,AXMOV SI,OFFSET STRING1MOV DI,OFFSET STRING2CLD;MOV CX,LENGTH STRING1MOV CX,STRLENREP CMPSBJZ FORWMOV AH,09HMOV DX,OFFSET NOTSFULINT 21HJMP EXITP
FORW: MOV AH,09HMOV DX,OFFSET SFULINT 21H
EXITP: NOPMOV AH,4CHINT 21H
CODE ENDSEND START
OBSERVATIONS:
INPUT: STRING1 =STRING2 =STRLEN =
OUTPUT:RESULT:
String comparison is performed and results are observed using MASM.
EXERCISE:
1. What is the significance of CLD?2. How does CMPSB perform the comparison?
51
EXERCISE PROGRAMS:
52
5.1 READING KEYBOARD WITH ECHO
AIM: To write a program to read the keyboard with echo.
APPARATUS: Computer system installed with MASM
PROGRAM:
DATA SEGMENTCHAR DB 0
DATA ENDSCODE SEGMENT
ASSUME CS:CODE, DS:DATASTART:
MOV AX,DATAMOV DS,AXMOV AH,01HINT 21H
53
MOV CHAR, ALINT 3
CODE ENDSEND START
OBSERVATIONS:
INPUT:
OUTPUT:
RESULT:
Reading a keyboard is performed and results are observed using MASM.
EXERCISE:
1. Write a brief note on DOS interrupts.2. What does AH register hold when INT 21H is called?
54
5.2 READING KEYBOARD WITHOUT ECHO
AIM: To write a program to read the keyboard without echo.
APPARATUS: Computer system installed with MASM
PROGRAM:
DATA SEGMENTCHAR DB 0
DATA ENDSCODE SEGMENT
ASSUME CS:CODE, DS:DATASTART:
MOV AX,DATAMOV DS,AXMOV AH,08HINT 21HMOV CHAR, ALINT 3
CODE ENDSEND START
55
OBSERVATIONS:
INPUT:
OUTPUT:
RESULT:
Reading a keyboard is performed and results are observed using MASM.
EXERCISE:
1. Write a brief note on DOS interrupts.2. What does AH register hold when INT 21H is called?
56
5.3 DISPLAYING A CHARACTER
AIM: To write a program to displaying a given string.
APPARATUS: Computer system installed with MASM
PROGRAM:
DATA SEGMENTCHAR DB ‘*’
DATA ENDS
CODE SEGMENTASSUME CS: CODE, DS: DATA
START: MOV AX, DATAMOV DS, AXMOV AH, 02HMOV DL,CHARINT 21HMOV AX, 4C00HINT 21H
CODE ENDSEND START
OBSERVATIONS:
INPUT:
57
OUTPUT:
RESULT:
Displaying a character on screen is performed and results are observed using MASM.
EXERCISE:
1. Write a brief note on DOS interrupts.2. What does AH register hold when INT 21H is called?
58
5.4 DISPLAYING A STRING
AIM: To write a program to displaying a given string.
APPARATUS: Computer system installed with MASM
PROGRAM:
DATA SEGMENTMESSAGE DB 10, 13,’HAPPY NEW YEAR’, 10, 13,’$’
DATA ENDSCODE SEGMENT
ASSUME CS: CODE, DS: DATASTART:
MOV AX, DATAMOV DS, AXMOV DX, OFFSET MESSAGEMOV AH, 09HINT 21HMOV AX, 4C00HINT 21H
CODE ENDSEND START
OBSERVATIONS:
INPUT:
OUTPUT:
RESULT:
59
Displaying a string on screen is performed and results are observed using MASM.
EXERCISE:1. Write a brief note on DOS interrupts.2. What does AH register hold when INT 21H is called?
60
EXERCISE PROGRAMS:
61
62
1. 8255 – PPI INTERFACING -1
AIM: configure 8255A such that port A and port B as an output ports .Execute the program at 0000:2000h
APPARATUS:
1. 8086 TRAINER KIT2. 8255 STUDY CARD3. ADAPTER, KEYBOARD, CABLES, ETC…
PROGRAM:
ADDRESS OP-CODES LABELS MNEMONICS COMMENTS
0000:2000 BA 46 FF MOVW DX, 0FF46 ; INITIALIZE 82550000:2003 B0 80 MOVB AL, 80 ; PORTS AS O/P0000:2005 EE OUTB DX, AL0000:2006 B0 55 MOVB AL, 55 ; OUTPUT DATA AT0000:2008 BA 40 FF RPT: MOVW DX, 0FF40 ; PORT A0000:200B EE OUTB DX, AL0000:200C F6 D0 NOTB AL ; INVERT THE DATA AND0000:200E BA 42 FF MOVW DX, 0FF42 ; OUTPUT THIS0000:2011 EE OUTB DX, AL ; VALUE AT PORT B0000:2012 B9 00 00 MOVW CX, 00000:2015 E2 FE LOOP 2015 ; INTRODUCE DELAY0000:2017 E2 FE LOOP 2017 ; AND REPEAT0000:2019 E9 EC FF JMP RPT (2008)
OBSERVATIONS:
INPUT:
63
OUTPUT:
RESULT:8086 Interfacing with 8255 is done and results are observed.
EXERCISE:
64
8255 – PPI INTERFACING -2
AIM: Configure 8255A such that port A as an output and port B as an input. Execute the program at 0000:2000h.
APPARATUS:
1. 8086 TRAINER KIT2. 8255 STUDY CARD3. ADAPTER, KEYBOARD, CABLES, ETC…
PROGRAM:
ADDRESS OP-CODES LABELS MNEMONICS COMMENTS
0000:2000 BA 46 FF MOVW DX, 0FF46 ; INITIALIZE 82550000:2003 B0 82 MOVB AL, 82 ; PORT A AS OUTPUT0000:2005 EE OUTB DX, AL ; PORT B AS INPUT0000:2006 BA 42 FF RPT: MOVW DX, 0FF42 ; READ VALUE FROM0000:2009 EC INB AL, DX ; PORT B0000:200A F6 D0 NOTB AL ; INVERT THE DATA0000:200C BA 40 FF MOVW DX, 0FF40 ; AND OUTPUT THIS0000:200F EE OUTB DX, AL ; VALUE AT PORT A0000:2010 E9 F5 FF JMP RPT(2006) ; REPEAT PROCESS
OBSERVATIONS:
INPUT:
OUTPUT:
RESULT:
8086 Interfacing with 8255 is done and results are observed.
65
EXERCISE:
66
8255 – PPI INTERFACING -3
AIM: Configure 8255A such that port A as an input and port B as an output. Execute the program at 0000:2000H.
APPARATUS:
1. 8086 TRAINER KIT2. 8255 STUDY CARD3. ADAPTER, KEYBOARD, CABLES, ETC…
PROGRAM:
ADDRESS OP-CODES LABELS MNEMONICS COMMENTS
0000:2000 BA 46 FF MOVW DX, 0FF46 ; INITIALIZE 82550000:2003 B0 90 MOVB AL, 90 ; PORT B AS OUTPUT0000:2005 EE OUTB DX, AL ; PORT A AS INPUT0000:2006 BA 40 FF RPT: MOVW DX, 0FF40 ; READ VALUE FROM0000:2009 EC INB AL, DX ; PORT A0000:200A BA 42 FF MOVW DX, 0FF42 ; OUTPUT THE SAME0000:200D EE OUTB DX, AL ; VALUE AT PORT B0000:200E E9 F5 FF JMP RPT (2006) ; REPEAT PROCESS
OBSERVATIONS:
INPUT:
OUTPUT:
RESULT:
8086 Interfacing with 8255 is done and results are observed.
67
EXERCISE:
68
2. 8279 – KEYBOARD/DISPLAY INTERFACING -1AIM: To interface keyboard/display with 8086 microprocessor and display a given sentence on the display board.(Left Entry)
APPARATUS:1. 8086 TRAINER KIT2. 8279 STUDY CARD3. ADAPTER, KEYBOARD, CABLES, ETC…
PROGRAM:
CMDREG EQU 0FFEBHDATAREG EQU 0FFE9H
.8086
.MODEL TINY
.STACK 32
.DATA
.CODE
ORG 2000HSTART:
MOV AX,CSMOV DS,AXMOV AL,10H ; ENCODED SCAN-8CHAR 8 BIT LEFT ENTRYMOV DX,CMDREGOUT DX,ALMOV AL,090H ;WRITE RAM AUTO INCREMENTOUT DX,ALMOV CX,08
CLEAR:MOV AL,00MOV DX,DATAREGOUT DX,ALLOOP CLEAR
BACK: MOV DX,CMDREGIN AL,DX ; READ THE COMMAND R4EGISTER TO GET THE 8279 STATUSAND AL,07 ; NUMBER OF KEYS PRESSED IS IN THE LOWER 3 BITS
MASK ;THESE AND CHECK IF NOT ZERO. IF ZERO NO KEY PRESSED
JZ BACKMOV BX,OFFSET SSCHARLUTMOV AL,040H ; READ THE FIRST RAM ADDRESS OF FIFOOUT DX,ALMOV DX,DATAREG ;IN AL, DXAND AL,01FHXLAT ; CONVERT THE KEY READ TO THE SS CODEMOV DX,DATAREGOUT DX,AL ; DISPLAY AT THE CURRENT DIGIT POSITIONJMP BACK
69
SSCHARLUT:SS0 DB 3FH ;0SS1 DB 6H ;1SS2 DB 5BH ;2SS3 DB 4FH ;3SS4 DB 66H ;4SS5 DB 6DH ;5SS6 DB 7DH ;6SS7 DB 07H ;7SS8 DB 7FHSS9 DB 6FHSSA DB 77HSSB DB 7CHSSC DB 39HSSD DB 5EHSSE DB 79HSSF DB 71H
END START
OBSERVATIONS:
INPUT:
OUTPUT:
RESULT:8086 Interfacing with 8279 is done and results are observed.
EXERCISE:
70
1. How many pins does 8279 IC have?2. How many scan lines are available on 8279?3. How many row-sense pins are there on 8279?4. How many registers are there in 8279?5. What is the purpose of command & data registers?
71
8279 – KEYBOARD/DISPLAY INTERFACING -2AIM: To interface keyboard/display with 8086 microprocessor and display a given sentence on the display board.(Right Entry)
APPARATUS:4. 8086 TRAINER KIT5. 8279 STUDY CARD6. ADAPTER, KEYBOARD, CABLES, ETC…
PROGRAM:
CMDREG EQU 0FFEBHDATAREG EQU 0FFE9H
.8086
.MODEL TINY
.STACK 32
.DATA
.CODE
ORG 2000HSTART:
MOV AX,CSMOV DS,AXMOV AL,0H ; ENCODED SCAN-8CHAR 8 BIT LEFT ENTRYMOV DX,CMDREGOUT DX,ALMOV AL,090H ;WRITE RAM AUTO INCREMENTOUT DX,ALMOV CX,08
CLEAR: MOV AL,00MOV DX,DATAREGOUT DX,ALLOOP CLEAR
BACK: MOV DX,CMDREGIN AL,DX ; READ THE COMMAND R4EGISTER TO GET THE 8279 STATUSAND AL,07 ; NUMBER OF KEYS PRESSED IS IN THE LOWER 3 BITS
MASK ;THESE AND CHECK IF NOT ZERO. IF ZERO NO KEY PRESSED
JZ BACKMOV BX,OFFSET SSCHARLUTMOV AL,040H ; READ THE FIRST RAM ADDRESS OF FIFOOUT DX,ALMOV DX,DATAREGIN AL, DXAND AL,01FHXLAT ; CONVERT THE KEY READ TO THE SS CODEMOV DX,DATAREGOUT DX,AL ; DISPLAY AT THE CURRENT DIGIT POSITIONJMP BACK
SSCHARLUT:SS0 DB 3FH ;0SS1 DB 6H ;1SS2 DB 5BH ;2
72
SS3 DB 4FH ;3SS4 DB 66H ;4SS5 DB 6DH ;5SS6 DB 7DH ;6SS7 DB 07H ;7SS8 DB 7FHSS9 DB 6FHSSA DB 77HSSB DB 7CHSSC DB 39HSSD DB 5EHSSE DB 79HSSF DB 71H
END START
OBSERVATIONS:
INPUT:
OUTPUT:
RESULT:8086 Interfacing with 8279 is done and results are observed.
EXERCISE:
1.
73
3. 8259 – PROGRAMMABLE INTERUPT CONTROLLERAIM: To interface Programmable Interrupt Controller with 8086 microprocessor.
APPARATUS:1. 8086 TRAINER KIT2. 8259 STUDY CARD
74
3. ADAPTER, KEYBOARD, CABLES, ETC…
PROGRAM:
ORG 1000HMOV AL,17HOUT 0C0H, ALMOV AL,08HOUT 0C2H, ALMOV AL,01HOUT 0C2H, ALMOV AL,FEHOUT 0C2H, ALSTI
HERE: JMP HEREMOV AL,20HLOOP 0C0H,ALINT 02H
Interrupt Vector:-0000:0200 00h0000:0021 12h0000:0022 00h0000:0023 00h
OBSERVATIONS:
INPUT:
OUTPUT:
RESULT:8086 Interfacing with 8279 is done and results are observed.
EXERCISE:1.
75
4. 8251 – USARTAIM: To interface USART (Universal Synchronous Asynchronous Receiver Transmitter) with 8086 microprocessor.
APPARATUS:1 8086 TRAINER KIT2 8251 STUDY CARD3 ADAPTER, KEYBOARD, CABLES, ETC…
PROGRAM:
76
TRANSMITTER END:
ORG 1000HMOV AL,36HOUT 0CEH, ALMOV AL,10HOUT 0C8H, ALMOV AL,00HOUT 0C8H, ALMOV AL,4EHOUT 0C2H, ALMOV AL,37HOUT 0C2H, AL
LOOP1:IN AL,0C2HAND AL,04HJZ LOOP1MOV AL,41HOUT 0C0H,ALINT 02H
RECEIVER END:
ORG 1200HMOV AL,36HOUT 0CEH, ALMOV AL,10HOUT 0C8H, ALMOV AL,00HOUT 0C8H, ALMOV AL,4EHOUT 0C2H, ALMOV AL,37HOUT 0C2H, AL
LOOP2:IN AL,0C2HAND AL,04HJZ LOOP2IN AL,0C0HMOV BX,I500HMOV [BX],ALINT 02H
OBSERVATIONS:
INPUT:
OUTPUT:
RESULT:8086 Interfacing with 8279 is done and results are observed.
EXERCISE:
77
EXERCISE PROGRAMS:
78
79
1.1 8-BIT ADDITION
AIM: To perform addition of two 8-bit hex numbers stored in consecutivememory locations and store the result in the next memory location.
APPARATUS: 1 8051 Microcontroller Kit2 ADAPTER, KEYBOARD, CABLES, ETC…
PROGRAM:
CLC C ;Clear carry flagMOV DPTR,#9000MOVX A,@DPTRMOV B,A ;First data in BINC DPTRMOVX A,@DPTR ;Second data in AADD A,B ;sum in AINC DPTRMOVX @DPTR,A ;Result in [9002h]END: SJMP END ;Halt
80
OBSERVATIONS: Input: [9000h] =
[9001h] =Output: [9002h] =
RESULT: Addition of two 8-bit numbers stored at consecutive memory locations is performed on 8051 microcontroller and the result is stored at the next memory location.
EXERCISE:
16-BIT ADDITION
AIM: To perform addition of two 16-bit hex numbers using immediate addressing and store the result in memory location.
APPARATUS: 1 8051 Microcontroller Kit2 ADAPTER, KEYBOARD, CABLES, ETC…
PROGRAM:
CLC C ;Clear carry flagMOV A,#LSB1ADDC A,#LSB2MOV DPTR,#9001 ;First data in BMOVX @DPTR,AMOV A,#MSB1 ;Second data in AADDC A,#MSB2 ;sum in AINC DPTRMOVX @DPTR,A ;Result in [9002h]
END: SJMP END ;Halt
OBSERVATIONS:
Example: DATA1 = 1234hDATA2 = 5678h
Output: [9000h] =[9001h] =
81
RESULT: Addition of two 16-bit numbers is performed on 8051 microcontroller and the result is stored in memory.
EXERCISE:
1.2 SUBTRACTION
AIM: To perform subtraction of two 8-bit hex numbers stored in consecutive memory locations and store the result in the next memory location.
APPARATUS: 1 8051 Microcontroller Kit2 ADAPTER, KEYBOARD, CABLES, ETC…
PROGRAM:
CLC C ;Clear carry flagMOV DPTR,#9001MOVX A,@DPTRMOV B,A ;Second data in BDEC DPTRMOVX A,@DPTR ;First data in ASUBB A,B ;Difference in AINC DPTRINC DPTRMOVX @DPTR,A ;Result in [9002h]
END: SJMP END ;Halt
OBSERVATIONS:
Input: [9000h] =[9001h] =
Output: [9002h] =
82
RESULT: Subtraction of two 8-bit numbers stored at consecutive memory locations is performed on 8051 microcontroller and the result is stored at the next memory location.
EXERCISE:
1.3 MULTIPLICATION
AIM: To perform multiplication of two 8-bit hex numbers stored in consecutive memory locations and store the result in the next memory location.
APPARATUS: 1 8051 Microcontroller Kit2 ADAPTER, KEYBOARD, CABLES, ETC…
PROGRAM:
CLC C ;Clear carry flagMOV DPTR,#9001MOVX A,@DPTRMOV B,A ;Second data in BDEC DPTRMOVX A,@DPTR ;First data in AMUL AB ;Difference in AINC DPTRINC DPTRMOVX @DPTR,A ;Result in [9002h]MOV B,A ; and [9003h]MOVX @DPTR,A
END: SJMP END ;Halt
OBSERVATIONS:
Input: [9000h] =[9001h] =
Output: [9002h] =
83
[9003h] =
RESULT: Multiplication of two 8-bit numbers stored at consecutive memorylocations is performed on 8051 microcontroller and the result isstored at the next memory location.
EXERCISE:
1.4 DIVISION
AIM: To perform multiplication of two 8-bit hex numbers stored in consecutive memory locations and store the result in the next memory location.
APPARATUS: 1 8051 Microcontroller Kit2 ADAPTER, KEYBOARD, CABLES, ETC…
PROGRAM:
CLC C ;Clear carry flagMOV DPTR,#9001MOVX A,@DPTRMOV B,A ;Second data in BDEC DPTRMOVX A,@DPTR ;First data in ADIV AB ;Difference in AINC DPTRINC DPTR ;Quotient inMOVX @DPTR,A ; [9002h] andMOV B,A ;Remainder inMOVX @DPTR,A ; [9003h]
END: SJMP END ;Halt
OBSERVATIONS:
Input: [9000h] =[9001h] =
Output: [9002h] =[9003h] =
84
RESULT: Division of two 8-bit numbers stored at consecutive memory locations is performed on 8051 microcontroller and the result is stored at the next memory location.
EXERCISE:
2. DATA TRANSFERAIM: To Transfer a block of data from internal ROM to external RAM
APPARATUS:1 8051 TRAINER KIT2 ADAPTER, KEYBOARD, CABLES, ETC…
PROGRAM:
ORG 0000HSTART: MOV A,#00
MOV SP,#07HMOV R3,#11MOV DPTR,#200HPUSH DPLPUSH DPH
REP: MOV DPTR,#MESSAGEMOV R2,AMOVC A,@A+DPTRPOP DPHPOP DPLMOVX @DPTR,AINC DPTRPUSH DPLPUSH DPHINC R2MOV A,R2DJNZ R3,REP
MESSAGE: DB "HELLO WORD"END
OBSERVATIONS:
INPUT:
85
OUTPUT:
RESULT:Block of data is transferred from ROM to RAM.
EXERCISE:
3. UNDERSTANDING ADDRESING MODES
AIM: To copy the value 55H into RAM memory locations 40H to 41H using(a) Direct addressing mode, (b) Register indirect addressing mode without a loop, and (c) with a loop
APPARATUS:1 8051 TRAINER KIT2 ADAPTER, KEYBOARD, CABLES, ETC…
PROGRAM:
(a)
MOV A,#55H ;load A with value 55HMOV 40H,A ;copy A to RAM location 40HMOV 41H.A ;copy A to RAM location 41H
(b)
MOV A,#55H ;load A with value 55HMOV R0,#40H ;load the pointer. R0=40HMOV @R0,A ;copy A to RAM R0 points toINC R0 ;increment pointer. Now R0=41hMOV @R0,A ;copy A to RAM R0 points to
(c)
MOV A,#55H ;A=55H
86
MOV R0,#40H ;load pointer.R0=40H,MOV R2,#02 ;load counter, R2=3
AGAIN: MOV @R0,A ;copy 55 to RAM R0 points toINC R0 ;increment R0 pointerDJNZ R2,AGAIN ;loop until counter = zero
OBSERVATIONS:
(a)
(b)
(c)
RESULT:A value is copied into RAM locations using various addressing modes and
observed the differences.
EXERCISE
87
4. UNDERSTANDING THE USAGE OF LCALL INSTRUCTION
AIM: To demonstrate the usage of LCALL instruction
APPARATUS:1 8051 TRAINER KIT2 ADAPTER, KEYBOARD, CABLES, ETC…
PROGRAM:
ORG 0BACK: MOV A,#55H ;load A with 55H
MOV P1,A ;send 55H to port 1LCALL DELAY ;time delayMOV A,#0AAH ;load A with AA (in hex)MOV P1,A ;send AAH to port 1LCALL DELAYSJMP BACK ;keep doing this indefinitely
ORG 300H ;put DELAY at address 300HDELAY: MOV R5,#0FFH ;R5=255 (FF in hex), counterAGAIN: DJNZ R5,AGAIN ;stay here until R5 become 0
RET ;return to caller (when R5 =0)END;
OBSERVATIONS:
INPUT:
OUTPUT:
RESULT:
Used LCALL instruction and observed the values of memory pointers
88
EXERCISE:
5. UNDERSTANDING THE USAGE OF ACALL INSTRUCTION
AIM: To demonstrate the usage of ACALL instruction
APPARATUS:1 8051 TRAINER KIT2 ADAPTER, KEYBOARD, CABLES, ETC…
PROGRAM:
ORG 0MOV A,#55H ;load A with 55H
BACK: MOV P1,A ;send 55H to port 1ACALL DELAY ;time delayCPL A ;complement reg ASJMP BACK ;keep doing this indefinitely
ORG 300H ;put DELAY at address 300HDELAY: MOV R5,#0FFH ;R5=255 (FF in hex), counterAGAIN: DJNZ R5,AGAIN ;stay here until R5 become 0
RETEND ;end of asm file
OBSERVATIONS:
INPUT:
OUTPUT:
RESULT:
Used ACALL instruction and observed the values of memory pointers
EXERCISE:
89
6. UNDERSTANDING THREE MEMORY AREAS OF 00-FF
AIM: To understand three memory areas of 00-FF
APPARATUS:1 8051 TRAINER KIT2 ADAPTER, KEYBOARD, CABLES, ETC…
PROGRAM:
ORG 0000H
LJMP START
ORG 200HSTART: MOV A,#41H
MOV 20H,AMOV A,#42HMOV R0,#20HMOV @R0,AMOV A,#43HMOV 80H,AMOV A,#44HMOV R0,#80HMOV @R0,AEND
OBSERVATIONS:
INPUT:
OUTPUT:
RESULT:
Used the memory areas of Controller and observed the differences.
EXERCISE:
90
EXERCISE PROGRAMS:
91
92
Expected Questions from Microprocessors:-
1. Who Invented 8086 microprocessor?2. In which year 8086 microprocessor is invented?3. How many address lines are available on 8086?4. How many data lines are available on 8086?5. Why address bus is unidirectional?6. Whether data bus is unidirectional or bidirectional?7. What is a bus?8. If AL=0FFh and ADD AL,01h instruction is executed, what is the status of
status flags?9. Under what condition bus contention occurs?10. How can you avoid bus contention?11. The segment 1234h and offset is 0022h, then the physical address is?12. If an instruction is accessed by 8086 is 20ms, the time taken by 8088 is?13. The no. of cycles required by 8086 for writing/reading to/from memory/IO
ports is?14. Whether 8086 contains internal clock generator?15. 8086 requires external clock signal with a duty cycle of?16. In 8086 the lower bank of 8086 contains?17. When ready pin of 8086 is at logic 0 then wait states are 18. The vectored interrupt in 8086 is?19. Non vectored interrupt in 8086 is?20. To restart from the initial state when ‘1’ is placed on 8086 RESET pin, the
duration for which the signal must present is?21. The rate of transmission in serial mode is?22. In serial I/O, data transmission takes place using which code?23. USART converts data from which form to which from?24. The inputs and outputs of 8251 are compatible with which logic?25. Whether RS232C is compatible with TTL Logic?26. If TxD output remains high the 8251 contains which characters?27. In RS232C, RS stands for?28. In RS 232C standard uses positive logic or negative logic?29. Which transmission is used for high speed serial data transmission?30. Expand DCE and DTE?
93
31. Which type of ADC is the fastest one?32. Which type of ADC is the most expensive one?33. Which type of ADC used DAC inside?34. How many comparators are required by an 8-bit flash type ADC?35. In 8259 if IR3, IR6, IR7 are activated, which interrupt has the highest priority?36. Which register in 8259 is used to disable interrupt requests?37. Which ports are used in BSR mode of 8255?38. Which port provides hand shaking signals in Mode1 & Mode2 of 8255?39. What is the IC used for DMA transfer?40. How many peripherals can be connected to 8237 at any point of time?41. For bidirectional data transfer, 8255 is operated in which mode?42. DMA will send a request signal to which pin of 8086?43. Which instruction is used to return from the interrupt service procedure?44. What are the ICs MC 1488 and MC 1489? 45. When accessing a memory location shared with a coprocessor, the signal that prevents the coprocessor from accessing that location is?46. There are two no. of 2Kx8 memory chips. How to obtain 4Kx8 memory?47. When the processor has 32 address lines, how much memory can be interfaced to that processor? 48. Whether Stepper Motor is an AC Motor or DC Motor?49. Give any application of Stepper Motor in our real life?50. What do you mean by interfacing?Expected Questions from Microcontrollers:-1. Who has introduced MCS-51 family of microcontrollers?2. MCS-51 family of microcontrollers contains which ICs?3. What is the difference between MP and MC?4. Give any Example of Microcontrollers?5. Is 8051 an 8-bit controller?6. Why 8051 is an 8-bit controller?7. What is the on chip ROM capacity of 8051?8. What is the on chip RAM capacity of 8051?9. How many IO ports are available on 8051 on chip?10. How many timers are available on 8051 on chip?11. Which version of 8051 doesn’t have on chip ROM?12. Which version of 8051 contains EPROM on chip?13. 8051 contains which type of ROM?
94
14. What is the purpose of ROM in 8051?15. What is the purpose of RAM in 8051?16. Whether ROM is accessible randomly or not?17. What is the capacity of on chip EPROM on 8751?18. Can you connect external program memory to 8051?19. Can you connect external data memory to 8051?20. What is the capacity of external program memory that can be connected to 8051?21. What is the capacity of external data memory that can be connected to 8051?22. How can you access internal program memory?23. How can you access external program memory?24. How is it possible to access both internal & external ROM using PC?25. How can you access internal data memory?26. How can you access external data memory?27. Do you require any signal to access external data memory?28. Do you require any signal to access external program memory?
29. What is the reason behind connecting only 64KB of external program memory?30. What is the reason behind connecting only 64KB of external data memory?31. Expand DPTR?32. Is a DPTR an 8-bit register?33. Can we access PC as two 8-bit registers?34. Is there any register in 8086 similar to PC in 8051?35. Expand SFR?36. Is PC a special function register?37. Whether external interrupts are edge triggered or level triggered type?38. Expand ALE?39. Expand PSEN?40. What is the function of PSEN pin?41. For serial communication the pins of which IO port is used?42. Which register is used to operate 8051 in different modes?43. What are the modes of operation of 8051?44. Whether PCON is a bit addressable SFR?45. Which port will hold the higher order address information during memory access?46. Which Io port of 8051 doesn’t have dual function?47. What is the Architecture of 8051?48. What is stack?49. What is the function of SP register?
95
50. The number of clock cycles in one machine cycle of 8051 is?Key to the Questions on Microprocessors:-1. Intel Corporation2. 19743. 20 address lines4. 16 data lines5. The address bus is unidirectional because the information on the address
bus is always provided by the microprocessor.6. Data bus is bidirectional.7. Bus is a collection of signal lines. Generally they carry address, data and
control signals.8. CF=1, PF=1, AF=1, ZF=1, SF=0 and OF=09. Bus contention occurs when two outputs trying to drive the same line.10. Bus contention can be avoided by using tri-state condition which isolates one
of the outputs.11. 12362h.12. 40ms.13. 4 clock cycles.14. No15. 33% duty cycle for its optimal functioning.16. Even address locations.17. Between T3 and T4 states.18. NMI.19. INTR.20. 4 clock cycles.21. Baud.22. ASCII.23. Parallel form to Serial.24. TTL Logic.25. No.26. No data (Stop bits).27. Recommended Standard.28. Negative logic.29. Synchronous transmission.30. DCE stands for Data Communications Equipment and DTE stands for Data
Terminal Equipment.31. Flash type ADC.
96
32. Successive Approximation ADC.33. Successive Approximation ADC.34. 8 Comparators.35. IR3.36. Interrupt Mask Register.37. Only Port C bits.38. Port C provides hand shaking signals.39. 8237 or 825740. Four41. Mode 242. HOLD pin.43. IRET.44. Voltage translators.45. LOCK46. By connecting address lines in serial and data lines parallel47. 232 = 4GB48. DC Motor49. Printers, X-Y plotters, Hard disk/Floppy Disk Drives, etc.,50. Interfacing means not only connecting the devices but also communicating
between them.
Key to the Questions on Microcontrollers:-
1. Intel Corporation2. 8031, 8051, 8052, 8751 and 8752 Microcontrollers. 3. MP contains ALU, Control Unit and On chip memory where as
Microcontroller contains MP, ROM, RAM, IO Ports, Counters/Timers on chip.
4. 80515. Yes6. Because all the internal registers and accumulator are of 8-bit wide and they
can process 8-bit data.7. 4KB8. 128 bytes9. 4 no. of 8-bit IO Ports10. 2 no. of 16-bit Timers/Counters
97
11. 803112. 875113. Simple Read Only Memory14. ROM is used for storing Programs hence it is called as Program Memory.15. RAM is nothing but Data Memory and is used to store data16. Yes17. 4KB18. Yes19. Yes20. 64KB21. 64KB22. Program Counter23. Program Counter24. Whenever we access external program memory, we use MOVX instruction
which distinguish the internal & external ROM.25. By means of its address in the program instructions.26. Data Pointer.27. Yes. We require Logic ‘0’ on External Access pin.28. No signal is required to access external program memory.29. Because PC is a 16-bit register, the maximum memory that can be interfaced externally is 216 = 64KB only.30. DPTR is a 16-bit register; the maximum memory that can be interfaced
externally is 216 = 64KB only.31. Data Pointer32. DPTR is a 16-bit register, but we can access it as two 8-bit registers DPH &
DPL.33. No, we can’t access PC as two 8-bit registers.34. PC is very similar to IP register in 8086.35. SFR stands for Special Function register.36. No, PC is the only register which doesn’t come under SFR.37. They can be programmed as either edge triggered or level triggered.38. Address Latch Enable39. PSEN stands for Program Store ENable.40. PSEN is used to store program in external memory.41. Port 3 pins are used for serial communication.42. PCON(Power CONtrol) SFR is used.43. Power Down Mode and Idle Mode.
98
44. No. PCON is not bit addressable.45. Port 2 will hold the higher order address information during memory access.46. Port 1 pins have no dual functions.47. The Architecture of 8051is called Harvard Architecture.48. Stack is an area in internal RAM that is used in conjunction with certain
opcodes to store and retrieve data quickly.49. SP holds an internal RAM address that is called top of the stack.50. 12 clock cycles.
99