mplabmanual_prsolutions

80
Lab incharge HOD MICROPROCESSORS LABORATORY MANUAL www.prsolutions.in www.prsolutions.in nd st

Upload: stalin-babu

Post on 18-Nov-2014

118 views

Category:

Documents


1 download

DESCRIPTION

if u any dotes keep write send mail id [email protected]

TRANSCRIPT

www.prsolutions.innd st

www.prsolutions.in

MICROPROCESSORS LABORATORY MANUAL

Lab incharge

HOD

Exercise No:M.1.1

Page No: 2

MICROPCROCESSORS LABORATORY MANUAL

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 3

TABLE OF CONTENTS

S.NO

NAME OF THE EXERCISE

PAGE NO

I. MICROPROCESSOR 8086 M.1 1. Introduction 2. Using Turbo Assembler-Linker-Debugger (TASM,TLINK,TD) 3. Introduction to the trainer & Instructions to user M.2 1.a). b). 2.a). b). 3.a). b). 4.a). b). 5. 6. 7. 8. 9. 10. 11. 12. M.3 1. 2.

5 8 10

8bit addition 16bit addition 8bit subtraction 16bit subtraction 8bit multiplication 16bit multiplication 8bit division 16bit division Multi byte addition Multi byte subtraction Signed multiplication Signed division ASCII addition ASCII subtraction ASCII multiplication ASCII division

18 20 22 23 24 25 26 28 29 31 33 34 35 36 37 38

Packed to unpacked BCD BCD to ASCII conversion

39 41

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 4

S.NO M.4 1. 2. 3. 4. 5. 6. M.5 1. M.6 1.

NAME OF THE EXERCISE

PAGE NO

Block Transfer String Reversal String insertion String deletion Length of string String comparison

42 43 44 45 46 47

Program design example (calculator)

48

DOS interrupts

56

II. INTERFACING 1. 2. i8279 Keyboard/Display Interface i8086 LEDs & switch interface 58 67

III. MICROCONTROLLER 8051 1. 2. i8051 LEDs & switch interface Transferring a block of data from internal ROM to internal RAM Internal ROM to external RAM Internal ROM to external RAM Understanding the three memory areas of 00-FF 73 77

3. a) b) 4.

78 79 80

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 5

INTRODUCTIONEDITOR An editor is a program, which allows you to create a file containing the assembly language statements for your program. As you type in your program, the editor stores the ASCII codes for the letters and numbers in successive RAM locations. When you have typed in all of your programs, you then save the file on a floppy of hard disk. This file is called source file. The next step is to process the source file with an assembler. In the TASM assembler, you should give your source file name the extension, .ASM ASSEMBLER An assembler program is used to translate the assembly language mnemonics for instructions to the corresponding binary codes. When you run the assembler, it reads the source file of your program the disk, where you saved it after editing on the first pass through the source program the assembler determines the displacement of named data items, the offset of labels and pails this information in a symbol table. On the second pass through the source program, the assembler produces the binary code for each instruction and inserts the offset etc that is calculated during the first pass. The assembler generates two files on floppy or hard disk. The first file called the object file is given the extension. OBJ. The object file contains the binary codes for the instructions and information about the addresses of the instructions. The second file generated by the assembler is called assembler list file. The list file contains your assembly language statements, the binary codes for each instructions and the offset for each instruction. In TASM assembler, TASM source file name ASM is used to assemble the file. Edit source file name LST is used to view the list file, which is generated, when you assemble the file. LINKER A linker is a program used to join several object files into one large object file and convert to an exe file. The linker produces a link file, which contains the binary codes for all the combined modules. The linker however doesnt assign absolute addresses to the program, it assigns is said to be relocatable because it can be put anywhere in memory to be run. In TASM, TLINK source filename is used to link the file.

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

www.prsolutions.inExercise No:M.1.1 Page No: 6

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 to set breakpoints at any point with the program. 4. The debugger will run the program upto the instruction where the breakpoint is set and then stop execution of program. At this point, we can examine registry and memory contents at that point. 5. With the help of dump we can view register contents. 6. we can trace the program step by step with the help of F7. 7. We can execute the program completely at a time using F8.

DEBUGGER COMMANDSASSEMBLE: To write assembly language program from the given address. A starting address Eg: a 100 Starts program at an offset of 100.

DUMP: To see the specified memory contents D memory location first address last address (While displays the set of values stored in the specified range, which is given above) Eg: d 0100 0105 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 Eg: e 1200 10 20 30 40 . Enters the above values starting from memory locations 1200 to 1203, by loading 10 into 1200,20 into 1201 and soon.

GO: To execute the program G: one instruction executes (address specified by IP) G address : executes from current IP to the address specified G first address last addresses : executes a set of instructions specified between the given addresses.

MOVE: Moves a set of data from source location to destination location M first address last address destination address Eg: m100 104 200 Transfers block of data (from 100 to 104) to destination address 200.

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 7

QUIT: To exit from the debugger. Q

REGISTER: Shows the contents of Registers R register name Eg: r ax Shows the contents of register.

TRACE: To trace the program instruction by instruction. T = 0100 : traces only the current instruction. (Instruction specified by IP) T = 0100 02 : 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 : unassembled 32 instructions starting from 100th location. U 0100 0109 : unassebles the lines from 100 to 104

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 8

Using Turbo Assembler Linker Debugger (TASM, TLINK, TD)1. Open an MSDOS window. 2. Set the PATH so that the TASM programs are available The TASM programs are on the C drive; set the path so that DOS can find them. This only needs to be done once each time you open an MSDOS prompt. set PATH=%PATH%;C:\TASM\BIN 3. Use a Text Editor to Edit the .ASM File

Create your file using one of the following programs: notepad proj.asm wordpad proj.asm edit proj.asm

4. Compile the source code to create an object module. tasm/z/zi proj.asm The /z switch causes TASM to display the lines that generate compilation errors. The /zi switch enables information needed by the debugger to be included in the .OBJ file. Note that you should use "real mode" assembler, TASM.EXE. Do not use the "protected mode" assembler TASM32.EXE for the assignments that will be given in class

5. Run Linker TLINK.EXE- generate .EXE file from the .OBJ file tlink/v proj

6. Run the Program Your final program (if there were no errors in the previous step) will have an .EXE ending. To just run it, type: proj If you want to use the debugger to examine the instructions, registers, etc., type: td proj This brings up the regular full-screen version of the Turbo debugger.

1. Tracing the Program's Execution The Turbo debugger first starts, a Module Window which displays the . Executable lines of program code, marked with a bullet in the left column of the window. You can set breakpoints or step to any of these lines of code. An arrow in the first column of the window indicates the location of the instruction pointer. This always points to the next statement to be executed. To execute just that instruction use one of the two methods listed under the Run menu item: o Trace into (can use F7 key): executes one instruction; traces "into" procedures. o Step over (can use F8 key): executes one instruction; skips (does not trace into) procedures. Hitting either of these executes the instruction, and moves the arrow to the next instruction. As each instruction executes, the effects might be visible in the Registers Window and Watches Window Lab incharge HOD

www.prsolutions.inExercise No:M.1.1 Page No: 9

o Trace into (can use F7 key): executes one instruction; traces "into" procedures. o Step over (can use F8 key): executes one instruction; skips (does not trace into) procedures. Hitting either of these executes the instruction, and moves the arrow to the next instruction. As each instruction executes, the effects might be visible in the Registers Window and Watches Window 2. Setting and Removing Breakpoints To set a breakpoint, position the cursor on the desired line of source code and press F2. The line containing the breakpoint will turn red. Pressing F2 again removes the breakpoint. To execute all instructions from the current instruction pointer up to the next encountered breakpoint, choose Run (can use F9 key) from the Run menu item. 3. Examining Registers Another window, the Registers Window, can be opened to examine the current value of the CPU registers and flags. The View menu can be used to open this Registers Window. The registers and flags might change as each instruction is executed. 4. Examining Memory To examine memory, you will need to open an Inspector window. An Inspector window shows the contents of a data structure (or simple variable) in the program you are debugging. It also allows you to modify the contents of the data structure or variable. To open an Inspector window, place the cursor on what you want to inspect and press CTRL-I. After you've examined the data item, press the ESC key to remove the Inspector window. 5. Viewing the Program's Output Output written to the screen by a program is not immediately visible, since the main purpose of using a debugger is to examine the internal operation of the program. To observe what the user would see, press ALT-F5. The entire screen will change to a user-view showing the program's input and output (and possibly that of previous programs as well). Press any key to return to the debugger screen.

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 10

Introduction to the trainer & Instructions to user INTRODUCTIONESA 86/88 2 is a powerful, general-purpose microcomputer system, which can be operated either with 8086 CPU or with 8086CPU. It is generally supplied with 8086 CPU. To change it to 8088, user has to just remove the 8086, insert 8088 into that socket and set a DIP switch. The 8086 and 8088 are third generation CPU is from INTEL that differ primarily in their external data paths. 8088 uses and 8-bit wide data bus while 8086 uses a 16-bit wide bus. ESA86/88-2 can be operated with either CPU and the only possible difference would be in the speed of execution (with 8088 CPU, a small speed degradation occurs because of the 8-bit wide data bus). In either case, the CPU is operated in the maximum mode. Following are the system capabilities Examine and optionally modify the contents of memory (byte or word format) Examine and optionally modify the processor registers. Assemble and Disassemble 8086/8088 instructions (via line assembler, disassembler). Perform fast numerical computations using the optional 8087 Numeric data processor. Execute the user program at full speed. Debug user program through single step and Breakpoint facilities. Write or read data to or from I/O ports (byte or word format). Move a block of data or program within the memory Download user programs into ESA 86/88-2 from a host computer system.

SPECIFICATIONS: Central processor8086 CPU, operating at 8MHz in maximum mode. (Supplied with 8086 CPU). (Memory cycles have zero wait states and I/O cycles have one wait state).

Co-ProcessorOn-board 8087 Numeric Data processor (optional)

MemoryEPROM: 4 JEDEC compatible slots offer the following options: 64K bytes using 27128s or, 128K bytes using 27256s or, 256K bytes using 27512s (System firmware is supplied in 2x27256s. The other two sockets are for user

expansion).

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 11

RAM: 4 JEDEC Compatible offer the following: 128K bytes using 6255s (64K bytes supplied using 2x62556s. The other two sockets are for user expansion). RAM has battery backup facility.

Peripherals and Controllers8251A: Programmable Communication Interface for serial communication supporting all standard from 110-19,200 (Baud is selected through on-board Dipswitch). 8253-5: (2 Nos.) programmable peripheral Interface devices provide 48 Programmable I/O lines. 8259A: Programmable interrupt Controller provides interrupt vectors for 8 sources 8288: Bus controller used for generating control signals. Interrupts External: NMI for INTR Keyboard. INTER controlled through 8259A, on-board Interrupt Controller: provides interrupt vectors for eight sources. Complete flexibility in selecting off-board or on-board interrupt sources. On-board interrupt sources # 8251 (TxRDY and RxRDY) # 8253-5 (OUT1 and OUT2) # 8255A (PC0 and PC3 in handshake mode) # 8087 (NDP INT) Internal: Interrupt vectors 1(single step) and 3 (breakpoint) reserved for monitor. Interface Signals CPU Bus: Demultiplexed and fully buffered, TTL compatible, Address, Data & Control signals are available on two 50-pin ribbon cable connectors. Parallel I/O: 48 Programmable parallel I/O lines (TTL compatible) through two 26 pin ribbon cable connectors. (Connector details compatible to our other microcomputer trainers). Serial I/O: RS 232 C through on-board 9pin D-type female connector. Power supply (optional): +5V @ 3.0Amp

CONFIGURATION AND INSTALLATIONConfiguration ESA 86/88-2 ESA 86/88-2-microcomputer trainer is versatile and can be configured in a number of ways, as determined by the setting of a DIPswitch and other jumpers. (Refer to the component layout diagram in appendix C to locate the DIPswitch and the jumpers). This chapter describes all the configuration options and the installation procedures. Operational mode selection ESA 86/88-2 can be operated either in the serial mode or in Hexadecimal keypad mode. In the serial mode, the trainer is connected to a CRT terminal or to a host computer system (like PC compatible) through an RS 232 C interface. In the keypad mode, the trainer is operated through Hexadecimal keypad. Lab incharge HOD

www.prsolutions.inExercise No:M.1.1 Page No: 12

SW4 of the DIP switch Operational mode OFF Serial mode ON Hexadecimal keypad mode* (*Factory installed Option) Printer Enable/Disable ESA 86/88-2 firmware includes the driver program fro centronics compatible parallel printer interface. This driver can be enabled/disabled as shown below: SW5 of the DIP Switch OFF ON (*Factory installed Option) Baud rate selection In the serial mode of operation, ESA 86/88-2 configures an 8251A USART as follows: Asynchronous mode 8-bit character length 2 stop bits No parity Baud rate factor of 16X Timers 0 of an 8253 provide the Transmit and receive baud clocks for the USART. (Refer to chapter 5 for a detailed discussion of the Hardware).This timer is initialized by the system firmware to provide proper baud clock based on the settings of the DIP Switch as shown below. Printer Driver Disabled* Enabled

SW3 OFF

DIP SWITCH SW2 OFF

SW1 ON

Baud rate 9,600*

Memory selection: ESA 86/88-2 has four sockets, labeled U9, U8, U7, U6 for RAM. These sockets are configured for 62256(32X 4) devices. Two of these sockets are populated (providing 64K Bytes of RAM) and two are for user expansion. DEVICE 27256 DIP SWITCH SW7 SW6 ON OFF JUMPER JP10 1-2

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 13

Hexadecimal keypad Legend InterpretationHexadecimal 0 EB/AX 1 ER/BX 2 GO/CX 3 ST/DX 4 IB/SP 5 OB/BP 6 MV/SI 7 EW/DI 8 IW/CS 9 OW/DS A /SS Acronym EB Name Examine Byte Acronym AX Name Accumulator

ER

Examine Register

BX

Base Register

GO

Go

CX

Count Register

ST

Single Step

DX

Data Register

IB

Input Byte

SP

Stack Pointer

OB

Output Byte

BP

Base Pointer

MV

Move

SI

Source Index

EW

Examine Word

DI

Destination index Code Segment

IW

Input word

CS Data Segment

OW

Output Word

DS Stack Segment

None

N/A

SS

B /ES C /IP D /FL E F Lab incharge

Extra Segment None N/A ES Instruction Pointer None N/A IP Flag Register None None None N/A N/A N/A FL none none HOD N/A N/A

www.prsolutions.inExercise No:M.1.1 Page No: 14

Function Key OperationFunction Key RESET Operation The RESET key allows you to terminate any present activity and to return your ESA 86/88-2 to an initialize state. When pressed, the sign-on message appears in the display and the monitor is ready for command entry.

KB INT

The INTR (interrupt) key is used to generate an immediate non-maskable type 2 interrupt (NM). The NMI interrupt vector is initialized on power up or system reset to point to a routine within the monitor which causes all of the 8086/8088s registers to be saved. Control is returned to the monitor for subsequent command entry. The + (plus) key allows you to add two hexadecimal values. This function simplifies relative addressing by allowing you to readily calculate an address location relative to a base address. The (minus) key allows you to subtract one hexadecimal value from another. The : (colon) key is used to separate an address to be entered into two parts; a segment value and an offset value.

+

-

:

REG

The REG (register) key allows you to use the contents of any of the 8086/8088s registers as an address or data value. The NEXT key is used to separate keypad entries and To increment the address field to the next consecutive memory location. The PREV key is used to decrement the address field to previous memory location. The dot key is the command terminator. When Pressed, the current command is executed.

NEXT (,)

PREV

EXEC (.)

NOTE:

1) NEXT or, means the same operation 2) EXEC or, means the same operation

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 15

Summary of Monitor commandsCommand Group Examine/modify Command Function/Format Examine Byte Displays/modifies memory byte locations EB ,[[] NEXT or PREV]. Examine word Displays/modifies memory word locations EW ,[[],]NEXT of PREV]. Examine Register Displays/modifies processor register contents ER[[] NEXT] [.]

Input/Output

Input Byter Displays the data byte at the input port. IB NEXT [NEXT]. Input word Displays the data word at the input port. IW NEXT [NEXT]. Output byte outputs the data byte to the output port. OB NEXT [NEXT ] Output word outputs the data word to the output port. OW NEXT [NEXT].

Execution

Step

Executes one single instruction. ST [NEXT [[] NEXT]

Go Transfers control from monitor to user program GO [] [NEXT]. Block Move Move Moves block of data within memory MV NEXT NEXT .

EXAMINE BYTE AND EXAMINE WORD COMMANDSFunction: The Examine byte (EB) and Examine Word (EW) commands are used to examine the contents of selected memory locations. If the memory location can be modified (e.g. a location in RAM), the contents optionally be modified.

FormatEB NEXT [[] PREV/NEXT]. EW NEXT [[] PREV/NEXT].

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 16

Operation1. Both the commands operate in a similar fashion. To use these commands, press the EB key or EW key when prompted for a command. 2. When either key is pressed, a dot appears at the right edge of the address field indicating that an address entry is required. 3. Enter the memory address of the byte (for EB) of word (for EW) to be examined. (The entry of address values is discussed in detail in section 3.2) 4. After entering the address value, press the , key. (i.e. the NEXT key). 5. The data byte of word contents of the addressed memory location will be displayed in the data field and a decimal point (a dot) appears at the right edge of data field indicating that the data can be updated. Note that when using the Examine word command, the byte contents of the displayed updated memory location appear in the two least-significant digits of the field and the byte contents of the next consecutive memory location (i.e. entered memory address + 1) appear in the two most significant digits of the data field. 6. If the contents of the memory location addressed are only to be examined, press the . Key to terminate the command, of press the , (NEXT) key to examine the next consecutive memory location (Examine Byte Command) or the next two consecutive memory locations (Examine Word Command) or press the PREV key to examine previous byte or word location. 7. To modify the contents of an addressed memory location, enter the new data from the hexadecimal keyboard (entering the data values is discussed in detail in section 3.2). 8. The data displayed is not updated in memory until either the , or . Key is pressed.

EXAMINE BYTE AND EXAMINE WORD COMMANDSFunction: The Examine Byte (EB) and Examine Word (EW) commands are used to examine the contents of selected memory locations. If the memory location can be modified (e.g. a location in RAM), the contents optionally be modified. Format EB NEXT [[] PREV/NEXT]. EW NEXT [[] PREV/NEXT]. EXAMINE REGISTER COMMAND Function The Examine Register (ER) command is used to examine and optionally modify the contends of nay of the 8086/8088s registers. Format ER [[],] [.]

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 17

INPUT/OUTPUT COMMANDSThere are 4 commands available for Input/Output of Byte/Word data form/to a specified port. In entering the port address (in any of these four commands), it should be noted that 8086/8088 I/O addressing is limited to 64K (maximum address is FFFFH). Thus no segment value is permitted with the port address.

INPUT BYTE AND INPUT WORD COMMANDSFunction The Input Byte (IB) and Input Word (IW) commands are used to input (accept) an 8-bit byte or 16bit word from an input port. Format IB , [,]. IW , [,].

STEP COMMANDFunction This command is used for single step execution of a program. In other words, this step (ST) command permits program instructions in memory to be executed individually. With each instruction executed, control is returned to the monitor from the program being executed, Format ST [< start address>], [[,.

GO COMMANDFunction The GO command is used to transfer control of the 8086/8088 from the keyboard monitor program to users program. Format GO [] [, ]

MOVE COMMANDFunction This command (MV) can be used to move a block of data from one portion of the memory to another potion of the memory. Format MV NEXT NEXT .

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 18

PROGRAM: 8BIT ADDITION.model tiny .stack 32h .code org 2000h start: mov ax,cs mov ds,ax mov ax,00 mov al,num1 mov bl,num2 add al,bl mov result,al int 3 mov ah,4ch int 21h org 20f0h num1 db 03 num2 db 08 result db 00 end start

Result: 03h 08h 0Bh

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 19

Exercise:1. What is the significance of model tiny? 2. How many model assignment are the name them? 3. What is a directive? 4. What is a pseudo operation? 5. ORG 2000H implies what? 6. At register is used why not AX? 7. What is the purpose of INT3 in the program? 8. What is the purpose of MOV AH, 4CH, INT 21H in the program?.

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 20

PROGRAM: 16BIT ADDITION

.model tiny .stack 32h .code org 2000h start: mov ax,cs mov ds,ax mov ax,00 mov ax,num1 mov bx,num2 add ax,bx mov result,ax int 3 mov ah,4ch int 21h org 20f0h num1 dw 0ffffh num2 dw 0ffffh result dw 00 end start

Result: 0FFFFh 0FFFFh 1FFFEhCarry

1111 1111 1111 1111 1111 1111 1111 1111 1111 1111 1,1111 1111 1111 1111 1110

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 21

Exercise:1. Stack 32 implies what? 2. Can ORG have other numbers instead of 2000h? 3. What is the purpose of MOV AX,CS? MOV DS,AX? 4. Why AX register is used and not AL? 5. What is the purpose of DW? 6. What happens if the result is greater than 16bit when result is declared an DW.?

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 22

PROGRAM: 8BIT SUBTRACTION.model tiny .stack 32h .code org 2000h start: mov ax,cs mov ds,ax mov ax,00 mov al,num1 mov bl,num2 sub al,bl mov result,al int 3 mov ah,4ch int 21h org 20f0h num1 db 0ffh num2 db 0aah result db 00 end start Result: 0ffh 0aah 055h

Exercise: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?

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 23

PROGRAM: 16BIT SUBTRACTION.model tiny .stack 32h .code org 2000h start: mov ax,cs mov ds,ax mov ax,00 mov ax,num1 mov bx,num2 sub ax,bx mov result,ax int 3 mov ah,4ch int 21h org 20f0h num1 dw 0ffffh num2 dw 0eabch result dw 00 end start

Result:

0ffffh 0eabch 01543h

Exercise:1. Why should AX be used not AL. ? 2. What happens if num1 and num2 values are interchanged? 3. If carry is set to 1 before subtraction what is the instruction to be used?Lab incharge HOD

www.prsolutions.inExercise No:M.1.1 Page No: 24

PROGRAM: 8BIT MULTIPLICATION.model tiny .stack 32h .code org 2000h start: mov ax,cs mov ds,ax mov ax,00 mov al,num1 mov bl,num2 mul bl mov result,al mov result1,ah int 3 mov ah,4ch Org 20f0h num1 db 0ffh num2 db 0aah result db 00 result1 db 00 end start Result: 0ffh 0aah a956h

Exercise:1. What is an extended accumulator? 2. AL and BL are used for multiplying why not AX & BX? 3. Instead of using MOV BL is it not possible to MUL num2? 4. What is the instruction used for signed multiplication?

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 25

PROGRAM: 16BIT MULTIPLICATION.model tiny .stack 32h .code org 2000h start: mov ax,cs mov ds,ax mov ax,00 mov ax,num1 mov bx,num2 mul bx mov result,ax mov result1,dx int 3 mov ah,4ch int 21h org 20f0h num1 dw 0ffffh num2 dw 0ffffh result dw 00 result1 dw 00 end start Result: 0ffffh 0ffffh fffe0001h

Exercise:1. Why AL & BL are not used in this? 2. If result exceeds 32 bit where is it stored? 3. What is the name given to the register combination DX:AX?

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 26

PROGRAM: 8BIT DIVISIONtiny .stack 32h .code org 2000h start: mov ax,cs mov ds,ax mov ax,00 mov dx,00 mov al,num1 mov bl,num2 div bl mov Quotient,al mov remainder,ah int 3 mov ah,4ch int 21h org 20f0h num1 db 0ffh num2 db 0aah Quotient db 00 remainder db 00 end start Result: 0ffh 0aah 5501h.model

Quotient: 01h Remainder r: 55h

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 27

Exercise:1. Why is the registers DX & AX made zero in the above program? 2. The above program? 3. Where is the remainder in 8 bit division? 4. Where is the quotient in 8 bit division? 5. If AH contains a non-zero value, what will be the result of the division? 6. Which interrupt is used when a divide overflow error occurs?

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 28

PROGRAM: 16BIT DIVISION.model tiny .stack 32h .code org 2000h start: mov ax,cs mov ds,ax mov ax,00 mov dx,00 mov ax,num1 mov bx,num2 div bx mov Quotient,ax mov remainder,dx int 3 mov ah,4ch int 21h org 20f0h num1 dw 0ffffh num2 dw 0aaaah Quotient dw 00 remainder dw 00 end start Result: 0ffffh 0aaaah 55550001h

Quotient: 0001h Remainder: 5555h

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?Lab incharge HOD

www.prsolutions.inExercise No:M.1.1 Page No: 29

PROGRAM: MULTY BYTE ADDITION.model tiny data segment dp1 dd dp2 dd res dd data ends

11223344h 55667788h 00000000h

code segment assume cs:code,ds:data start: mov ax,data mov ds,ax mov si,offset dp1 mov di,offset dp2 mov bx,offset res mov cx,03 sub ax,ax mov al,[si] mov dl,[di] add al,dl mov [bx],al back: inc si inc di inc bx mov al,[si] mov dl,[di] adc al,dl mov [bx],al loop back nop mov ah,4ch int 21h code ends end start

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 30

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 dp1.?

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 31

PROGRAM: MULTY BYTE SUBTRACTION.model tiny data segment dp2 dd dp1 dd res dd data ends

55667788h 11223344h 00000000h

code segment assume cs:code,ds:data start: mov ax,data mov ds,ax mov si,offset dp2 mov di,offset dp1 mov bx,offset res mov cx,03 sub ax,ax mov al,[si] mov dl,[di] sub al,dl mov [bx],al back: inc si inc di inc bx mov al,[si] mov dl,[di] sbb al,dl mov [bx],al loop back nop mov ah,4ch int 21h code ends end start

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 32

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 ofMOV DI, offset dp2. ?

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 33

PROGRAM: SIGNED MULTIPLICATION

.model tiny data segment dp1 db 0a5h dp2 db 20h res dw 00h data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax sub ax,ax mov al,dp1 mov bl,dp2 imul bl mov res,ax nop mov ah,4ch int 21h code ends end start

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?

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 34

PROGRAM: SIGNED DIVISION

.model tiny data segment dp1 db 0d5h dp2 db 20h quo db 0h rem db 0h data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax xor ax,ax mov al,dp1 cbw mov bl,dp2 idiv bl mov quo,al mov rem,ah nop mov ah,4ch int 21h code ends end start

EXERCISE:1. What is the purpose of SUB AX,AX? 2. What is the difference between IDIV and DIV? 3. What is the use of instruction CBW & CWD?

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 35

PROGRAM: ASCII ADDITION

.model tiny data segment ip1 db '9',0dh,0ah ip2 db '6',0dh,0ah res db 0 data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax xor ax,ax mov al,ip1 add al,ip2 aaa mov res,al mov ah,4ch int 21h code ends end start

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?

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 36

PROGRAM: ASCII SUBTRACTION.model tiny data segment ip1 db '9',0dh,0ah ip2 db '6',0dh,0ah res db 0 data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax xor ax,ax mov al,ip1 sub al,ip2 aas mov res,al mov ah,4ch int 21h code ends end start

EXERCISE:1. What is the purpose of ASCII subtraction?

2. What is the instruction used for ASCII subtraction?

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 37

PROGRAM: ASCII MULTIPLICATION

.model tiny data segment ip1 db 4 ip2 db 6 res db 0 data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax xor ax,ax mov al,ip1 mul ip2 aam mov res,al mov ah,4ch int 21h code ends end start

EXERCISE: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?

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 38

PROGRAM: ASCII DIVISION.model tiny data segment ip1 db 6 ip2 db 4 res db 0 data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax xor ax,ax mov al,ip1 aad div ip2 mov res,al mov ah,4ch int 21h code ends end start

EXERCISE: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?

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 39

PROGRAM: PACKED TO UNPACKED BCD.model tiny data segment bcdip db 56h ubcdop dw 0 data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax xor ax,ax mov al, bcdip mov dl,al and al,0f0h mov cl,4 ror al,cl mov bh,al and dl,0fh mov bl,dl mov ubcdop,bx mov ah,4ch int 21h code ends end start

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 40

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?

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 41

PROGRAM: BCD to ASCII CONVERSION.model tiny data segment bcdip db 56h ubcdop dw 0 data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax xor ax,ax mov al, bcdip mov dl,al and al,0f0h mov cl,4 ror al,cl mov bh,al and dl,0fh mov bl,dl mov ubcdop,bx add bx,3030h mov ah,4ch int 21h code ends end start

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?Lab incharge HOD

www.prsolutions.inExercise No:M.1.1 Page No: 42

PROGRAM: BLOCK TRANSFER;.model tiny data segment srcdata db 'Empty vessels make much noise',24h data ends extra segment dstdata db 12 dup(0) extra ends code segment assume cs:code,ds:data,es:extra start: mov ax,data mov ds,ax mov ax,extra mov es,ax mov si,offset srcdata mov di,offset dstdata cld mov cx,29 rep movsb nop mov ah,4ch int 21h code ends end start

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?

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 43

PROGRAM: STRING REVERSAL.model tiny data segment string1 db 'Empty' strlen equ ($-string1) string2 db 5 dup(0) data ends code segment assume cs:code,ds:data,es:data start: mov ax,data mov ds,ax mov es,ax mov bx,offset string1 mov si,bx mov di,offset string2 add di,5 cld mov cx,strlen a1: mov al,[si] mov es:[di],al inc si dec di loop a1 ;rep movsb ;nop mov ah,4ch int 21h code ends end start

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?Lab incharge HOD

www.prsolutions.inExercise No:M.1.1 Page No: 44

PROGRAM: STRING INSERTION.model tiny data segment string1 db 'Empty vessels more noise$' strlen equ ($-string1) data ends extra segment string2 db strlen+5 dup(0) extra ends code segment assume cs:code,ds:data,es:extra start: mov ax,data mov ds,ax mov si,offset string1 mov di,offset string2 cld mov cx,14 rep movsb mov dl,5 back: mov ah,01 int 21h stos string2 dec dl jnz back mov cx,11 rep movsb nop mov ah,4ch int 21h code ends end start

EXERCISE:1. Why register DI is loaded with 5? 2. What is the function of rep movsb? 3. What is the purpose of mov ah,01h / int 21h?Lab incharge HOD

www.prsolutions.inExercise No:M.1.1 Page No: 45

PROGRAM: STRING DELETION

.model tiny data segment string1 db 'Empty vessels make more noise$' strlen equ ($-string1) data ends extra segment string2 db strlen-5 dup(0) extra ends code segment assume cs:code,ds:data,es:extra start: mov ax,data mov ds,ax mov ax,extra mov es,ax mov si,offset string1 mov di,offset string2 cld mov cx,13 rep movsb cld mov si,18 mov cx,12 rep movsb mov ah,4ch int 21h code ends end start

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?

Lab incharge

HOD

Exercise No:M.1.1

Page No: 46

PROGRAM: LENGTH OF THE STRING.model tiny data segment string1 db 'Empty vessels make more noise$' strlen equ ($-string1) res db 0 cort db 'strlength found correct$' incort db 'strlength found incorrect$' data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax sub cl,cl mov bl,strlen mov si,offset string1 back:lodsb inc cl cmp al,'$' jnz back mov res,cl cmp cl,bl jz correct mov dx,offset incort mov ah,09 int 21h correct:mov dx,offset cort mov ah,09 int 21h mov ah,4ch int 21h code ends end start

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?

Lab incharge

HOD

Exercise No:M.1.1

G.N.I.T.S-ECE DEPARTMENT:MPI LAB Page No: 47

PROGRAM: STRING COMPARISION.model tiny data segment string1 db 'Empty' strlen equ ($-string1) notsful db 'strings are unequal$' sful db 'strings are equal$' data ends extra segment string2 db 'Empty' extra ends code segment assume cs:code,ds:data,es:extra start: mov ax,data mov ds,ax mov ax,extra mov es,ax mov si,offset string1 mov di,offset string2 cld ;mov cx,length string1 mov cx,strlen rep cmpsb jz forw mov ah,09h mov dx,offset notsful int 21h jmp exitp forw:mov ah,09h mov dx,offset sful int 21h exitp: nop mov ah,4ch int 21h code ends end start

EXERCISE:1. What is the significance of CLD? 2. How does CMPSB perform the comparison?Lab incharge HOD

www.prsolutions.inExercise No:M.1.1 Page No: 48

Program design example (calculator)EXTRN ADDER:near, MULT:near, DIVD:near, SUBB:near .model tiny

printf

macro string mov ah,09h mov dx, offset string int 21h endm getch macro mov ah,01 int 21h endm .stack 160 .data menu db 0ah,0dh,' A Simple Calculator' db 0ah,0dh,' 1. addition' db 0ah,0dh,' 2. subtraction' db 0ah,0dh,' 3. multiplication' db 0ah,0dh,' 4. division' db 0ah,0dh,' X. exit the program' db 0ah,0dh,' input your choice ?$' addproc db 0ah,0dh,' addition procedure?$' subproc db 0ah,0dh,' subtraction procedure?$' divproc db 0ah,0dh,' division procedure?$' mulproc db 0ah,0dh,' multiplication procedure?$' num1 dw 0 num2 dw 0 PRESSANYKEY DB 0AH,0DH,'PRESS ANY KEY $'

binnum dw 0 ;accessed by asc2bin overflowdmsg db 0dh,0ah, 'overflow error $'; invalidmsg db 0dh,0ah, 'invalid error $'; enternum db 0dh,0ah, 'please type a number less than 32000 $';from asciinum db '00000$';getnum binout dw 0ffffh RESULT DB 0AH,0DH,0DH,0AH,0AH,0DH,0DH,0AH,0AH,0DH,0DH,0AH,'THE RESULT IS ' ascout db '00000',0AH,0DH,0DH,0AH,0AH,0DH,0DH,0AH,0AH,0DH,0DH,0AH,'$'

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 49

.code .startup

begin: mov ax,@data mov ds,ax menuagain: printf menu getch cmp al,'1' jne nxt1 call addition jmp menuagain nxt1: cmp al,'2' jne nxt2 call subtract jmp menuagain nxt2: cmp al,'3' jne nxt3 call multiply jmp menuagain nxt3: cmp al,'4' jne nxt4 call divide jmp menuagain nxt4: cmp al,'X' jne menuagain .exit

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 50

asc2bin

proc

mov cx,5 ;put number of digits in cx mov di,10 ;put base 10 in di to multiply acc with mov bh,'9' ;bh to check if number greater than 9 mov bl,'0' ;bl checks lower limit of number mov si,offset asciinum xor ax,ax ; make accumulator zero A2Bagain:mul di jc overflow mov dx,ax ; save multiply accumulate reister AX mov al,[si] cmp al,bl jl invalid cmp al,bh jg invalid sub al,30h cbw add ax,dx jc overflow inc si loop A2Bagain over: mov binnum,ax ret invalid: PRINTF invalidmsg PRINTF PRESSANYKEY GETCH jmp BEGIN overflow: PRINTF overflowdmsg PRINTF PRESSANYKEY GETCH jmp BEGIN asc2bin endp

bin2asc proc xor mov add mov mov mov mov ba: div add mov dec xor loop ret bin2asc endp Lab incharge

si,si di,offset ascout di,4 ax,binOUT dx,0 bx,10 cx,5 bx dl,30h [di],dl di dx,dx ba

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 51

getnum proc mov ah,9 mov dx,offset enternum int 21h mov si,offset asciinum mov cx,5 GNagain: mov ah,01 int 21h mov [si],al inc si loop GNagain ret getnum endp multiply proc call getnum call asc2bin mov ax,binnum push ax call getnum call asc2bin mov ax,binnum push ax call mult pop ax pop bx add ax,bx mov binout,ax call bin2asc PRINTF RESULT ret multiply endp subtract proc call getnum call asc2bin mov ax,binnum push ax call getnum call asc2bin mov ax,binnum push ax call subb pop ax pop bx add ax,bx mov binout,ax call bin2asc PRINTF RESULT ret subtract endp Lab incharge HOD

www.prsolutions.inExercise No:M.1.1 Page No: 52

divide proc call getnum call asc2bin mov ax,binnum push ax call getnum call asc2bin mov ax,binnum push ax call divd pop ax pop bx add ax,bx mov binout,ax call bin2asc PRINTF RESULT ret divide endp

addition

proc call getnum call asc2bin push binnum call getnum call asc2bin push BINNUM CALL ADDER pop ax pop bx mov binout,ax call bin2asc PRINTF RESULT ret addition endp END

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 53

public

adder .model tiny .code proc near push bp mov bp,sp add bp,6 mov ax,[bp] dec bp dec bp mov bx,[bp] add ax,bx mov [bp],ax inc bp inc bp mov ax,0 mov [bp],ax pop bp ret endp end mult .model tiny .code proc near push bp mov bp,sp add bp,6 mov ax,[bp] dec bp dec bp mov bx,[bp] mul bx mov [bp],ax inc bp inc bp mov ax,0 mov [bp],ax pop bp ret endp end

adder

adder

public

mult

mult

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 54

public

subb .model tiny .code proc near push bp mov bp,sp add bp,6 mov ax,[bp] dec bp dec bp mov bx,[bp] sub ax,bx mov [bp],ax inc bp inc bp mov ax,0 mov [bp],ax pop bp ret endp end

subb

subb

public

divd .model tiny .code divd proc near push bp mov bp,sp add bp,6 mov ax,[bp] dec bp dec bp mov bx,[bp] mov dx,00 div bx mov [bp],ax inc bp inc bp mov ax,0 mov [bp],ax pop bp ret divd endp end

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 55

EXERCISE:1. What is the difference between a macro and a procedure? 2. What is the purpose of having 0ah & 0dh in message statement? 3. What is the associated directive to the EXTRN directive? 4. The menu in the instruction printf menu represents what? 5. What is performed by the directive startup? 6. Convert one of the procedure into near procedure? 7. Convert another procedure into far procedure in ASCII to binary procedure, a famous algorithm is used. What is the name of the algorithm [refer Gibbsons book] ? 8. What is the significance of public in the file named adder? 9. What is BP used for in the adder procedure?

10. If the variables are RXCD and passed by the adder is it been by done by the value or reference?

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 56

PROGRAM: DOS INTERRUPTS.model tiny data segment msg1 db 0ah,0dh,'Enter the first number: $' msg2 db 0ah,0dh,'Enter the second number: $' msg3 db 0ah,0dh,'Result: $' res db 00 data ends code segment assume cs:code,ds:data start: mov ax,data mov ds,ax lea dx,msg1 mov ah,09h int 21h mov ah,01h int 21h sub al,30h mov bl,al lea dx,msg2 mov ah,09h int 21h mov ah,01h int 21h sub al,30h add al,bl add al,30h mov res,al lea dx,msg3 mov ah,09h int 21h mov dl,res mov ah,02h int 21h mov ah,4ch int 21h code ends end start

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 57

EXERCISE:1. After executing the instructions mov ah,01h / int 21h, what are contents of AL ? 2. What are the contents of AH for displaying a sting in the screen? 3. What are the contents of AH for accepting a number from keyboard? 4. Which register contains the address of the string to be displayed on screen?

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 58

Programmable Keyboard/Display Interface 8279 A programmable keyboard and display interfacing chip. o Scans and encodes up to a 64-key keyboard. o Controls up to a 16-digit numerical display.

Keyboard has a built-in FIFO 8 character buffer. display information.

The display is controlled from an internal 16x8 RAM that stores the coded

Pinout Definition 8279

A0: Selects data (0) or control/status (1) for reads and writes between micro and 8279. BD: Output that blanks the displays. CLK: Used internally for timing. Max is 3 MHz. CN/ST: Control/strobe, connected to the control key on the keyboard. CS: Chip select that enables programming, reading the keyboard, etc. DB7-DB0: Consists of bidirectional pins that connect to data bus on micro. IRQ: Interrupt request, becomes 1 when a key is pressed, data is available. OUT A3-A0/B3-B0: Outputs that sends data to the most significant/least significant nibble of display. RD(WR): Connects to micro's IORC or RD signal, reads data/status registers. RESET: Connects to system RESET. RL7-RL0: Return lines are inputs used to sense key depression in the keyboard matrix. Shift: Shift connects to Shift key on keyboard. SL3-SL0: Scan line outputs scan both the keyboard and displays. The keyboard matrix can be any size from 2x2 to 8x8. Pins SL2-SL0 sequentially scan each column through a counting operation. o The 74LS138 drives 0's on one line at a time. o The 8279 scans RL pins synchronously with the scan. o RL pins incorporate internal pull-ups, no need for

Keyboard Interface of 8279

external resistor pull-ups.

Unlike the 82C55, the 8279 must be programmed first. D7 D6 D5 0 0 0 Lab incharge 0 0 1 0 1 0 Function Mode set Clock Read FIFO Purpose Selects the number of display positions, type of key scan... Programs internal clk, sets scan and debounce times. Selects type of FIFO read and address of HOD

www.prsolutions.inExercise No:M.1.1 Page No: 59

0 1 1 1

1 0 0 1

1 0 1 0

Read Display Write Display Display write inhibit Clear

the read. Selects type of display read and address of the read. Selects type of write and the address of the write. Allows half-bytes to be blanked.

Clears the display or FIFO Clears the IRQ signal to the 1 1 1 End interrupt microprocessor. The first 3 bits of # sent to control port selects one of 8 control words. First three bits given below select one of 8 control registers (opcode).

000DDMMMo Mode set: Opcode 000.

DD sets displays mode. MMM sets keyboard mode.o DD field selects either:

8- or 16-digit display Whether new data are entered to the rightmost or leftmost display position. DD 00 01 10 11 Function 8-digit display with left entry 16-digit display with left entry 8-digit display with right entry 16-digit display with right entry

Keyboard Interface of 8279 MMM field: MMM 000 001 010 011 100 101 110 111 Function Encoded keyboard with 2-key lockout Decoded keyboard with 2-key lockout Encoded keyboard with N-key rollover Decoded keyboard with N-key rollover Encoded sensor matrix Decoded sensor matrix Strobed keyboard, encoded display scan Strobed keyboard, decoded display scan Encoded: Sl outputs are active-high, follow binary bit pattern 0-7 or 0-15. Decoded: SL outputs are active-low (only one low at any time). Lab incharge HOD

www.prsolutions.inExercise No:M.1.1 Page No: 60

Pattern output: 1110, 1101, 1011, 0111. Strobed: An active high pulse on the CN/ST input pin strobes data from the RL pins into an internal FIFO for reading by micro later.o 2-key lockout/N-key rollover: Prevents 2 keys from being recognized

if pressed simultaneously/Accepts all keys pressed from 1st to last.

001PPPPPo The clock command word programs the internal clock driver. o The code PPPPP divides the clock input pin (CLK) to achieve the

desired operating frequency, e.g. 100KHz requires 01010 for a 1 MHz CLK input.

010Z0AAAo The read FIFO control word selects the address (AAA) of a keystroke

from the FIFO buffer (000 to 111).o Z selects auto-increment for the address.

011ZAAAAo The display read control word selects the read address of one of the

display RAM positions for reading through the data port.

100ZAAAAo Selects write address -- Z selects auto-increment so subsequent writes

go to subsequent display positions.

1010WWBBo The display write inhibit control word inhibits writing to either the

leftmost 4 bits of the display (left W) or rightmost 4 bits.o BB works similarly except that they blank (turn off) half of the output

pins.

1100CCFAo The clear control word clears the display, FIFO or both o Bit F clears FIFO and the display RAM status, and sets address

pointer to 000. If CC are 00 or 01, all display RAM locations become 00000000. If CC is 10, --> 00100000, if CC is 11, -> 11111111.

1110E000o End of Interrupt control word is issued to clear IRQ pin in sensor

matrix mode. 1) Clock must be programmed first. If 3.0 MHz drives CLK input, PPPPP is

programmed to 30 or 11110. Lab incharge HOD

www.prsolutions.inExercise No:M.1.1 Page No: 61

2) Keyboard type is programmed next. o The previous example illustrates an encoded keyboard,

external decoder used to drive matrix. 3) Program the FIFO. Once done, a procedure is needed to read data from the keyboard. o To determine if a character has been typed, the FIFO status

register is checked.o When this control port is addressed by the IN instruction, the

contents of the FIFO status word is copied into register AL: Data returned from 8279 contains raw data that need to be translated to ASCII: o Row and column number are given the rightmost 6 bits (scan/return). o This can be converted to ASCII using the XLAT instruction with an

ASCII code lookup table.o

The CT and SH indicate whether the control or shift keys were pressed.

The Strobed Keyboard code is just the state of the RLx bits at the time a 1 was `strobed' on the strobe input pin.

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 62

PROGRAM: KEYBOARD DISPLAY RIGHT ENTRYcmdreg datareg equ equ 0ffebh 0ffe9h

.8086 .model tiny .stack 32 .data .code org 2000h start: mov ax,cs mov ds,ax mov al,0H ; ENCODED SCAN-8CHAR 8 BIT LEFT ENTRY mov dx,cmdreg out dx,al mov al,090h ;WRITE RAM AUTO INCREMENT out dx,al mov cx,08 clear: mov al,00 MOV DX,datareg out DX,al loop clear mov dx,cmdreg in al,dx ; READ THE COMMAND R4EGISTER TO GET ; THE 8279 STATUS and 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 back mov bx,offset sscharlut mov al,040h ; READ THE FIRST RAM ADDRESS OF FIFO out dx,al mov Dx,datareg in al, dx and al,01fhHOD

back:

Lab incharge

www.prsolutions.inExercise No:M.1.1 Page No: 63

xlat ; CONVERT THE KEY READ TO THE SS CODE mov dx,datareg out dx,al ; DISPLAY AT THE CURRENT DIGIT ; POSITION jmp back sscharlut: SS0 SS1 SS2 SS3 SS4 SS5 SS6 SS7 SS8 SS9 SSA SSB SSC SSD SSE SSF

DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB

3FH 6H 5BH 4FH 66H

;0 ;1 ;2 ;3 ;4

6DH ;5 7DH ;6 07H ;7 7FH 6FH 77H 7cH 39H 5eH 79H 71H

end start

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 64

PROGRAM: KEYBOARD DISPLAY LEFT ENTRYcmdreg equ datareg equ .8086 .model tiny .stack 32 .data .code org 2000h start: mov ax,cs mov ds,ax mov al,10H ; ENCODED SCAN-8CHAR 8 BIT LEFT ENTRY mov dx,cmdreg out dx,al mov al,090h ;WRITE RAM AUTO INCREMENT out dx,al mov cx,08 clear: mov al,00 MOV DX,datareg out DX,al loop clear back: mov dx,cmdreg in al,dx ; READ THE COMMAND R4EGISTER TO GET ; THE 8279 STATUS and 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 back mov bx,offset sscharlut mov al,040h ; READ THE FIRST RAM ADDRESS OF FIFO out dx,al mov Dx,datareg; in al, dx and al,01fh xlat ; CONVERT THE KEY READ TO THE SS CODE mov dx,dataregLab incharge HOD

0ffebh 0ffe9h

www.prsolutions.inExercise No:M.1.1 Page No: 65

out dx,al jmp back sscharlut: SS0 SS1 SS2 SS3 SS4 SS5 SS6 SS7 SS8 SS9 SSA SSB SSC SSD SSE SSF DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB DB 3FH 6H 5BH 4FH 66H

; DISPLAY AT THE CURRENT DIGIT ; POSITION

;0 ;1 ;2 ;3 ;4

6DH ;5 7DH ;6 07H ;7 7FH 6FH 77H 7cH 39H 5eH 79H 71H

end start

EXERCISE:1. How many puns 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? 6. What are the first 4 bits D7 D4 in the command register used for?

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 66

7. If 16 character 8 bit left entry LED display is to be programmed. What is the command code? 8. What is the use of org 2000h? can the 2000h changed to another value? 9. What are the data values of SSCHARLUT represent? 10. Explain the use of XLAT and what default registers it use? 11. Out dx,al the operand 1 is 16 bit and operand 2 is 16 bit. How does it work? 12. What is the interrupt used for inputting data from i/o port? 13. What is the states register address of 8279? 14. In 8279, if consists of lots of registers, how is it only 2 addresses are used? 15. How do you change the right entry to left entry mode is LED character display? 16. Explain the sensor mode of 8279? 17. Can the addressed RAM be automatically incremented, if so how it is done? 18. When the states register is read, the lower 32bits represents what? 19. How are the shift and ctrl keys are identified in 8279? 20. Write down the control word required for 16 characters 8bit left entry, 16 keys N-key roll over? 21. What is the meaning N-key roll over? 22. What is 2-key lock out? 23. What is the circuit which processes the clock given to 8279 and steps it down programmable to the required rate called?

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 67

LEDS & SWITCH INTERFACE(8086)This experimental board has been developed for the purpose of understanding the operation of LEDS & SWITCH. This experiment makes use of programmable i/o port called programmable peripheral interface (PPI) which is numbered as i8255 has three 8086 on the trainer kit. 8255 has three i/o ports and they are grouped as group A & groupB. Group A contains port A & port B & lower nibble of port C. The 8255 can be operated in three modes. Mode 0 is for simple I/O mode 1 is for handshake i/o. Mode 2 is for bi-directional multiprocessor interfacing. The i/o ports of 8255 have a fan in of 10 & fanout of 1 the operations of8255 are controlled by a control register which can be programmed to set the mode & i/p o/p functions of ports. All the port pins are collectively programmable & not individually programmable. For example 1 port A pins PA0 to PA7 have to be all inputs or all outputs. They cannot be programmed as PA0 in & PA0 out individually as 2 four bit ports which can be programmed as a group for i/p of o/p. PC0 to PC3 which are the lower nibble of port C can be programmed as input or output while upper nibble of port C PC4 to PC7 can be programmed as input or output. The control word format is as follows.

D7

D6

D5

D4

D3

D2

D1

D0

Active/BSR Group A PA PCH GroupB PB Mode i/p of o/p Mode

PCL

D7- When set it is in the action operation where the i/o s can be programmed. If D7 is clear it is in bit set reset mode. Which is used to set reset port C bits. This mode is not of great significance in the use of 8255. D7 is one as 8255 is used in the active mode. D6,D5 are the bits used far setting the mode of group A ports. 00 01 10 11 Mode 0 Mode 1 Mode 2 Mode 3

D4 sets the port A as input or output depending upon whether it is 1 or 0 respectively. D3 sets the port C higher as input or output depending upon whether it is 1 of 0 respectively. D2 this bit is for setting the mode of group B which has only 2 modes mode0 and mode1. D1 sets the port B as i/p or o/p depending upon whether it is 1 or 0 respectively. D0 sets the port C lower as i/p or o/p depending upon whether it is 1 or 0 respectively. To program 8255 for lighting the LED lamps it is important for us to know the LED specifications.

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 68

Green Forward voltage drop Typical operating current Max current Dimensions 1.9V 5ma 15ma 5mm

Red 1.8V 5ma 15ma 5mm

For further details refer website http:\\ crsarma.tripod.com. A current of 10ma was passed through lamp for lighting. The output voltage, used to drive it was form a TTL port. So the balance of voltage 3.4V has to be dropped across this resistor while passing 10ma of current therefore resistor value is 5V-1.6V = 340 is not available in the standard range of resistors. 10ma So in the standard range which ever is close to 340 is chosen. Port A was connected to four RED & four GREEN LEDs arranged alternately.

SWITCHES Port C was programmed for2 ports of nibble each. So the upper nibble (PCH PC4.PC7) could be used for i/p or o/p subsequently. An i/p port papers in a tri-stated condition which results in a floating voltage. So inputs have to be given a pull-up resistor which makes at logic 1 level. A toggle switch is then connected to port pin with its other end connected to ground. If the toggle switches open, the particular bit is at logic 1 otherwise logic 0. The switches are connected to PC0 & PC1.

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 69

PROGRAM: 8255(LEDS USING SWITCHES).8086 .model tiny .stack 16 .code org 2000h start: mov ax,cs mov ds,ax mov dx,0ffe7h mov al,81h out dx,al h1: mov dx,0ffe5h in al,dx test al,03 jnz nxt1 call alternet jmp h1 nxt1: test al,01 jnz nxt2 call r2l jmp h1 nxt2: test al,02 jnz h1 call l2r jmp h1 alternet proc BACK: mov dx,0ffe1h mov al,0aah out dx,al call delay mov al,055h out dx,al call delay ret

alternet endp

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 70

l2r proc mov cx,8 mov al,01h mov dx,0ffe1h out dx,al call delay rol al,01h loop back2 ret

BACK2:

l2r endp delay proc push cx mov cx,0ffffh s1: loop s1 pop cx ret

delay endp r2l proc mov cx,8 mov al,80h MOV DX,0FFE1H out dx,al call delay ror al,01h loop back3 ret end start

BACK3:

r2l endp

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 71

LEDS USING SWITCHES

Exercise:1. What is the control word format for 8255? 2. How is the choice of resistor connected to the led made? 3. What is the forward drop of green leds? 4. What is the forward drop of red leds? 5. What is the current drown by LEDs(8)?

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 72

MCS 51 DEVELOPMENT TOOLS Using Command Line1. Edit the program using EDIT editor 2. Save as name .A51 3. Assemble using A51.EXE C: A51 name .A51 Result: name .LST, name .OBJ 4. LINK & Convert to Hex format using OH51.EXE C: OH51 name .OBJ Result: name .HEX 5. Simulate Using SIM31.EXE C: SIM31

Using Integrated Design Environment (IDE) KEIL Vision (Windows)An Integrated design environment consists of all the tools needed for the development of software for the MCS 51 family. These tools are linked together in one environment. The main feature of IDE is the BUILD process. The BUILD ensures that the target file is current. In order to keep modular development the PROJECT feature is provided. 1. Select START\PROGRAMS\KEIL 2. Create New project Select PROJECT\NEW\ enter name Choose TARGET\INTEL\8051 Choose BUILD OPTIONS Check Box HEX 3. Create File name of file .ASM Edit File & Save 4. SELECT PROJECT WINDOW ADD FILE SELECT - 5. PROJECT\BUILD\ If no errors goto 7 else 3 DEBUG\START\

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 73

LEDS & SWITCH INTERFACE(8051)This experimental board has been developed for the purpose of understanding the operation of LEDS & SWITCH. This experiment makes use of programmable i/o port called programmable peripheral interface (PPI) which is numbered as i8255 has three 8086 on the trainer kit. 8255 has three i/o ports and they are grouped as group A & groupB. Group A contains port A & port B & lower nibble of port C. The 8255 can be operated in three modes. Mode 0 is for simple I/O mode 1 is for handshake i/o. Mode 2 is for bi-directional multiprocessor interfacing. The i/o ports of 8255 have a fan in of 10 & fanout of 1 the operations of8255 are controlled by a control register which can be programmed to set the mode & i/p o/p functions of ports. All the port pins are collectively programmable & not individually programmable. For example 1 port A pins PA0 to PA7 have to be all inputs or all outputs. They cannot be programmed as PA0 in & PA0 out individually as 2 four bit ports which can be programmed as a group for i/p of o/p. PC0 to PC3 which are the lower nibble of port C can be programmed as input or output while upper nibble of port C PC4 to PC7 can be programmed as input or output. The control word format is as follows.

D7

D6

D5

D4

D3

D2

D1

D0

Active/BSR Group A PA PCH GroupB PB Mode i/p of o/p Mode

PCL

D7- When set it is in the action operation where the i/o s can be programmed. If D7 is clear it is in bit set reset mode. Which is used to set reset port C bits. This mode is not of great significance in the use of 8255. D7 is one as 8255 is used in the active mode. D6,D5 are the bits used far setting the mode of group A ports. 02 03 12 13 Mode 0 Mode 1 Mode 2 Mode 3

D4 sets the port A as input or output depending upon whether it is 1 or 0 respectively. D3 sets the port C higher as input or output depending upon whether it is 1 of 0 respectively. D2 this bit is for setting the mode of group B which has only 2 modes mode0 and mode1. D1 sets the port B as i/p or o/p depending upon whether it is 1 or 0 respectively. D0 sets the port C lower as i/p or o/p depending upon whether it is 1 or 0 respectively. To program 8255 for lighting the LED lamps it is important for us to know the LED specifications.

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 74

Green Forward voltage drop Typical operating current Max current Dimensions 1.9V 5ma 15ma 5mm

Red 1.8V 5ma 15ma 5mm

For further details refer website http:\\ crsarma.tripod.com. A current of 10ma was passed through lamp for lighting. The output voltage, used to drive it was form a TTL port. So the balance of voltage 3.4V has to be dropped across this resistor while passing 10ma of current therefore resistor value is 5V-1.6V = 340 is not available in the standard range of resistors. 10ma So in the standard range which ever is close to 340 is chosen. Port A was connected to four RED & four GREEN LEDs arranged alternately. SWITCHES Port C was programmed for2 ports of nibble each. So the upper nibble (PCH PC4.PC7) could be used for i/p or o/p subsequently. An i/p port papers in a tri-stated condition which results in a floating voltage. So inputs have to be given a pull-up resistor which makes at logic 1 level. A toggle switch is then connected to port pin with its other end connected to ground. If the toggle switches open, the particular bit is at logic 1 otherwise logic 0. The switches are connected to PC0 & PC1.

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 75

LED ROTATE RIGHT AND ROTATE LEFT PROGRAMPORTA PB PORTC PCW DELAY FIRST SECOND EQU EQU EQU EQU EQU EQU EQU ORG 2808H 2809H 280AH 280BH 0114H 170 85 6500H

MOV DPTR,#PCW ; DPTR HOLDS THE CONTROL REGISTER ADDRESS MOV A,#080H MOVX @DPTR,A RIGHTLED: MOV A,#01 MOV DPTR,#PORTA RIGHTLED1: MOVX @DPTR,A MOV R2,#0FFH MOV R1,#0FFH LCALL DELAY RR A JMP RIGHTLED1 LEFTLED: MOV A,#01 MOV DPTR,#PORTA LEFTLED1: MOVX @DPTR,A MOV R2,#0FFH MOV R1,#0FFH LCALL DELAY RL A JMP LEFTLED1 AGAIN: MOV DPTR,#PORTA MOV A,#FIRST MOVX @DPTR,A MOV R2,#0FFH MOV R1,#0FFH LCALL DELAY MOV A,#SECOND MOVX @DPTR,A MOV R2,#0FFH MOV R1,#0FFH LCALL DELAY JMP AGAIN END

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 76

LEDS AND SWITCH INTERFACE

Exercise:1. What is the control word format for 8255? 2. How is the choice of resistor connected to the led made? 3. What is the forward drop of green LEDs? 4. What is the forward drop of red LEDs? 5. What is the current drown by LEDs(8)?

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 77

PROGRAM: Transferring a block of data from internal ROM to internal RAMorg 0000h ljmp start org 000bh reti org 0013h reti org 001bh reti org 0023h reti org 0023h reti org 0026h reti org 200h mov dptr,#message mov r0,#20h mov r7,#11 mov a,#00h movc a,@a+dptr mov @r0,a inc r0 inc dptr djnz r7,rep

start:

rep:

message: db "hello world" end

Exercise:1. What are the two registers in 8051, which are used for indirect addressing? 2. What are the 16 bit registers available in 8051? 3. Which register cannot be decremented? 4. 8051 is a ------- bit microcontroller?

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 78

PROGRAM: (a). Internal ROM to external RAMORG 0000H mov a,#00 mov sp,#07h mov r3,#11 mov dptr,#200h push dpl push dph rep: mov dptr,#message mov r2,a movc a,@a+dptr pop dph pop dpl movx @dptr,a inc dptr push dpl push dph inc r2 mov a,r2 djnz r3,rep message: db "hello word" end START:

Exercise:1. What does djnz instruction do? 2. What is DPTR relative addressing? 3. How many 8 bit registers are available in 8051? 4. What is the purpose of R2? 5. What is the purpose of R3?

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 79

PROGRAM: b). Internal ROM to external RAM

org 200h start: mov r0,#40h mov a,#30h mov r6,#10

rep:

mov @r0,a inc a inc r0 djnz r6,rep mov r1,#40h mov dptr,#400h mov r7,#00h mov a,@r0 movx @dptr,a inc dptr inc r1 inc r7 cjne r7,#10,rep1 end

rep1:

Exercise:6. What is DPTR relative addressing? 7. What is the purpose of R7? 8. What is the purpose of R0? 9. What does cjne instruction do? 6. The stack pointer of 8051 grows upwards or downwards

Lab incharge

HOD

www.prsolutions.inExercise No:M.1.1 Page No: 80

PROGRAM: Understanding three memory areas of 00-FFORG 0000H ljmp start org 200h start: mov a,#41h mov 20h,a mov a,#42h mov r0,#20h mov @r0,a mov a,#43h mov 80h,a mov a,#44h mov r0,#80h mov @r0,a end

Exercise:1. What is the instruction used for loading accumulator from code memory? 2. What is the purpose of register R0? 3. What are the two registers in 8051 which are used for indirect addressing?

Lab incharge

HOD