EE3751 Microprocessor Laboratory Summer 2009

47
Rev. 01/09 Microprocessor Laboratory Manual EE3751 Gabriel Augusto Marques Tarquinio de Souza Department of Electrical and Computer Engineering Louisiana State University and Agricultural and Mechanical College Baton Rouge, LA 70803

Transcript of EE3751 Microprocessor Laboratory Summer 2009

Page 1: EE3751 Microprocessor Laboratory Summer 2009

Rev. 01/09

Microprocessor Laboratory Manual

EE3751

Gabriel Augusto Marques Tarquinio de Souza

Department of Electrical and Computer Engineering Louisiana State University

and Agricultural and Mechanical College

Baton Rouge, LA 70803

Page 2: EE3751 Microprocessor Laboratory Summer 2009

ii

Table of Contents

Administrative Policy of the Laboratory ................................................................. iii Conventions .................................................................................................................... v Experiment 1 - Introduction to DEBUG and the Assembly Process ................ 1 Experiment 2 – Simple Programs, and Subroutines .......................................... 10 Experiment 3 – BIOS and DOS Interrupts. ............................................................ 18 Experiment 4 – BIOS and DOS Interrupts - II ........................................................ 23 Experiment 5 – Mouse and Keyboard Programming ......................................... 25 Appendix A – DOS Commands ..................................................................................... 30 Appendix B – ASCII Table ............................................................................................ 34 Appendix C – Datasheets................................................................................................ 37 Appendix D – Parallel Port Information ...................................................................... 38 Appendix E – Serial Port Information .......................................................................... 41 

Page 3: EE3751 Microprocessor Laboratory Summer 2009

iii

Administrative Policy of the Laboratory

1) You are not allowed to smoke, eat or drink in the Laboratory. 2) You are expected to conduct yourself professionally, and to keep your

bench area clean and organized. 3) You are required to return all equipment and parts used in the experiment

to their proper places before you leave the lab. 10 points will be deducted from your lab report grade for non compliance with this rule.

4) The tools, instruments, and computer cables in each lab station are not supposed to be removed from the laboratory.

5) You are expected to work in a group, which is defined to contain at most two persons. If there are an odd number of persons in the class section you are enrolled to, then someone will work alone. You are allowed and encouraged to choose your partner.

6) You are encouraged to work on your programs outside of the lab. 7) You are also expected to build and test your circuits. They may be built in

advance. It is your responsibility to demonstrate to your lab instructor that the circuits you built do what they are supposed to do!

8) In order to be able to borrow the lab equipment used in some of the experiments, you must sign the Equipment Usage Policy.

9) The Instructors are available to guide you in debugging the software or troubleshoot the hardware, but it is not the Instructors’ responsibility to make your experiment work.

10) There will be make-up lab sessions at the end of the semester. During each session you will be allowed to make-up at most two experiments you have previously worked on and did not submit a lab report on it. Note that this is an opportunity being afforded to you so that you may work again on an experiment you previously attempted but were unsuccessful. If you did not work on an experiment during a previous lab session you will not be allowed to make it up during the make-up session.

11) Lab reports will consist of your program listing, any data you are required to collect in the execution of the experiment, and the answer to questions posed during the lab.

12) You may choose to request partial credit for a laboratory you may have had difficulty in completing. In these cases the grading will follow the procedure outlined below:

a. A 40% deduction is applied to the programs that do not assemble, then, more points will be deducted for wrong code.

b. A 20% deduction is applied to the programs that do not execute correctly (logical error), then, points will be deducted for wrong code.

c. Points will be deducted for wrong code.

Page 4: EE3751 Microprocessor Laboratory Summer 2009

iv

13) You are required to store your program in a flash drive or your network drive. This action will avoid the possibility of having your programs copied by someone else.

14) The assembler and linker will be provided for you take home.

Page 5: EE3751 Microprocessor Laboratory Summer 2009

v

Conventions The following convention will be used with all examples shown in this manual: CAPITALIZED ITALICS REPRESENTS THE INFORMATION TYPED OR ENTERED BY THE USER. CAPITALIZED BOLD REPRESENTS THE COMPUTERS RESPONSE.

Page 6: EE3751 Microprocessor Laboratory Summer 2009

1

Experiment 1 - Introduction to DEBUG and the Assembly Process

Objectives:

• to assemble assembly language programs; • to disassemble assembly language programs; • to execute assembly language programs; • to debug assembly language programs using DEBUG; • to verify and modify the computer’s memory; • to verify and modify the CPU’s registers.

Report The answers to this experiment questions, should be given to the instructor before you exit the lab, and they will be composed of:

• the printout of a file named E1GXY.TXT where X is your section number and Y your desk number. This file will contain the answers and information requested in the experiment by statements and questions colored red. Please clearly identify your answers, by including a Step x sentence with it. Also the information shown below should be placed on the top of the first page:

o Students’ names o Date o Program number o Desk number

Copying Information from the Command Prompt window To copy the information from the Command Prompt window do:

• click on the icon on the top left corner of the window, then select Edit, Mark;

• use the mouse to select information to be copied; • click on the icon on the top left corner of the window, then select Edit,

Copy Enter; • paste the information just copied into a file named Your last name

Answers which you can open using Notepad. DEBUG DEBUG is a program available with every version of WINDOWS and DOS. You will be exposed to how to use DEBUG to perform many different important tasks. The knowledge acquired in this experiment will be extremely useful when manipulating the programs you will write during the semester.

Page 7: EE3751 Microprocessor Laboratory Summer 2009

2

Even though great care was taken to provide you with the most correct information to be displayed on your screen, some of this information may be slightly different from what you may get on your computer. Information like addresses where programs are located and the drive you choose to use may be different from one computer to another. DEBUG displays all numeric values as hexadecimal numbers and it is not case sensitive. Due to this fact all numerical values given in this experiment are in hexadecimal form. Note that the usual hexadecimal formats (1AH, 0x1A) are not in use in this experiment, and this is due to my choice of using DEBUG’s format in an attempt to avoid confusion when entering values into DEBUG. Loading DEBUG Open the Command Prompt by double-clicking its icon on the desktop or select: START>ALL PROGRAMS>ACCESSORIES>COMMAND PROMPT For my examples in this experiment I will use the Z: drive. Step 1 (5 points) - Issue the following command at the DOS prompt to load DEBUG: Z:\DEBUG <ENTER> - Copy and save step 1. The small dash shown on the screen after your command is the DEBUG prompt. Exiting DEBUG Step 2 (5 points) – Issue the following command at the DEBUG prompt to exit DEBUG: -Q<ENTER> Z:\ Copy and save step 2. To clear the Command Prompt window issue the following command: Z:\CLS <ENTER> Note that the command given above is making reference to the Z: drive. In your case the drive should be either your flash or your network drive letter. Change the drive by issuing the following command:

Page 8: EE3751 Microprocessor Laboratory Summer 2009

3

CURRENT DRIVE:\ YOUR DRIVE: Note that the CURRENT DRIVE:\ is the default drive and directory used by the Command Prompt program, and YOUR DRIVE: should be the letter used to represent the drive you will be using. Examining and modifying the contents of registers Load DEBUG and perform the following series of commands. -R<ENTER> AX=0000 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000 DS=0B2C ES=0B2C SS=0B2C CS=0B2C IP=0100 NV UP EI PL NZ NA PO NC 0B2C:0100 7509 JNZ 010B After the execution of the R (display register) command, DEBUG displays all registers, flags and the next instruction to be executed. The line containing the next instruction to be executed displays the address where the instruction is located, 0B2C:0100, its opcode, 7509, and its mnemonic, JNZ 010B. To display and modify the value of a single register use the following command: -R CX<ENTER> CX 0000 :0008<ENTER> The command issued above allowed you to modify the contents of the CX register, which was originally 0000, to a new value of 0008. Confirm this change by displaying all registers again. -R<ENTER> AX=0000 BX=0000 CX=0008 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000 DS=0B2C ES=0B2C SS=0B2C CS=0B2C IP=0100 NV UP EI PL NZ NA PO NC 0B2C:0100 7509 JNZ 010B

Try the following command: -R CX<ENTER> CX 0000 :8<ENTER> Confirm the change by displaying all registers one more time. You will notice that the previous two commands performed in the same way, which should lead you to conclude that when a number smaller than 4 digits is entered DEBUG will pad it with zeroes. Step 3 (20 points) - Modify the contents of the BX register to 1D57, the contents of the DX register to 1F26 and display all registers. Now modify the contents of

Page 9: EE3751 Microprocessor Laboratory Summer 2009

4

register DL from 26 to 68 without modifying the contents of register DH which you set to 1F in the previous step. Display all registers and use the information displayed to compute the physical address of the next instruction to be executed, then copy and save step 3 and type the answer to your calculation in the format shown below. Segment address: _______________ Effective address: _______________ Physical address: _______________ Assembling, disassembling, and executing programs For this step you may need to increase the size of the Command Prompt window. Do this by left-clicking the bottom side of the window and dragging the mouse until the window size is the size you want. Below you will find a series of commands to assemble and execute a program that adds the contents of registers AX and BX. Practice the procedure by entering the same information and verifying the results displayed. -A 100<ENTER> 0B2C:0100 MOV AX,1<ENTER> 0B2C:0103 MOV BX,2<ENTER> 0B2C:0106 ADD AX,BX<ENTER> 0B2C:0108 INT 3<ENTER> 0B2C:0109<ENTER> -R<ENTER> AX=0000 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000 DS=0B2C ES=0B2C SS=0B2C CS=0B2C IP=0100 NV UP EI PL NZ NA PO NC 0B2C:0100 B80100 MOV AX,0001 -G=100<ENTER> AX=0003 BX=0002 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000 DS=0B2C ES=0B2C SS=0B2C CS=0B2C IP=0108 NV UP EI PL NZ NA PE NC 0B2C:0108 CC INT 3 -

In the series of instructions given above you were exposed to two new commands which are described below: A - used for the assembly of programs. Format: A <starting address>. The starting address have the following form: CS:EA where CS is the code segment address and EA is the effective address or the offset. The code segment address is assumed by default and it may be skipped, but the effective address has to be given. This was done in the example above with the A 100 command. G - used for the execution of programs.

Page 10: EE3751 Microprocessor Laboratory Summer 2009

5

Format: G <=starting address> <ending address>. The starting address and ending address may be provided by the user or not, therefore many variations of the command exits, and some are described below: G - execution will start at CS:IP and terminate at the end of the program. G =0 – execution will start at CS:0 and terminate at the end of the program. G 100 - execution will start at CS:IP and terminate at the address CS:100. G =10 100 - execution will start at CS:10 and terminate at the address CS:100. Note that all addresses displayed above with the G command only used the offset address but one may wish to express the full address, see examples below: Assume CS = 2A0 and the offset = 100 G =2A0:100 G =CS:10 CS:100 U – used for the disassembly of programs. Disassembly is the process of reading the machine code and creating an assembler program out of it, in other words, it is the reverse process of the assembly. Format: U <starting address> <ending address>. Shown above is the format for the disassembly command. The format uses a beginning and an ending address of the program to be disassembled. Note that the initial address does not require the = sign as in the G command. Issue the following command to disassemble the program you assembled above. -U 100 108<ENTER> 0B2C:0100 B80100 MOV AX,0001 0B2C:0103 BB0200 MOV BX,0002 0B2C:0106 01D8 ADD AX,BX 0B2C:0108 CC INT 3 - Step 4 (30 points) – Write the program described below and assemble it at address CS:200. The program should perform the following operation: AL = AL*BL/CL+DL-DH . Initialize the registers in the program to the following values: AL=0A, BL=5, CL=2, DL = 01B and DH=22, then, assemble, execute, verify that AL=12, and disassemble your program. Copy and save step 4. Tracing the execution of your program

Page 11: EE3751 Microprocessor Laboratory Summer 2009

6

The trace command T is used to trace the execution of a program by displaying register information after the execution of the each instruction in the selected range. Format: T <=starting address> <number of instructions> Like the Go command if the starting address is not specified, it starts execution at CS:IP. -T =100 4<ENTER> AX=0001 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000 DS=0B2C ES=0B2C SS=0B2C CS=0B2C IP=0103 NV UP EI PL NZ NA PO NC 0B2C:0103 BB0200 MOV BX,0002 AX=0001 BX=0002 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000 DS=0B2C ES=0B2C SS=0B2C CS=0B2C IP=0106 NV UP EI PL NZ NA PO NC 0B2C:0106 01D8 ADD AX,BX AX=0003 BX=0002 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000 DS=0B2C ES=0B2C SS=0B2C CS=0B2C IP=0108 NV UP EI PL NZ NA PE NC 0B2C:0108 CC INT 3 AX=0003 BX=0002 CX=0000 DX=0000 SP=FFE8 BP=0000 SI=0000 DI=0000 DS=0B2C ES=0B2C SS=0B2C CS=0590 IP=13B1 NV UP DI PL NZ NA PE NC 0590:13B1 55 PUSH BP - Step 5 (10 points) - Trace the execution of the program you wrote in step 4. Remember you stored it at address 200. Copy and save step 5. Accessing and modifying data in DEBUG In this section you will be exposed to the three commands: F – fill, D – dump, and E – enter. These commands addresses reference the data segment (DS). If you need to access information in another segment you need to include the segment in the address. The command’s description and usage examples are given below: F – Used to fill blocks of memory with data. Format: F <starting address> <ending address> <data> D – Used to display the memory content. Format: D <starting address> <ending address> D <starting address> <L number of bytes> The starting and ending addresses may be given as offsets in the data segment. If access to another segment is required then the segment information should be included in the address, example: D CS:100 CS:1FF

Page 12: EE3751 Microprocessor Laboratory Summer 2009

7

E – Used to enter information in memory. Format: E <address> <data list> E <address> If the E command is used without the data list, DEBUG assumes that you wish to examine that byte of memory and possibly modify it. The following options are given to you in that case: a – You may enter a new data byte which DEBUG will write to memory. b – You may press <ENTER> to signify you do not wish to modify the byte. c – You may press the space bar which will leave the displayed byte unchanged and move to the next byte where you may possibly modify it. d – You may enter the minus sign, which will leave the displayed byte unchanged and move you to the previous byte where you may possibly modify it. Command examples: -F 100 11F 20<ENTER> -F 120 13F 30<ENTER> -D 100 13F<ENTER> 0B2C:0100 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20 20 0B2C:0110 20 20 20 20 20 20 20 20-20 20 20 20 20 20 20 20 0B2C:0120 30 30 30 30 30 30 30 30-30 30 30 30 30 30 30 30 0000000000000000 0B2C:0130 30 30 30 30 30 30 30 30-30 30 30 30 30 30 30 30 0000000000000000 -F 140 15F 31<ENTER> -D 140 L20<ENTER> 0B2C:0140 31 31 31 31 31 31 31 31-31 31 31 31 31 31 31 31 1111111111111111 0B2C:0150 31 31 31 31 31 31 31 31-31 31 31 31 31 31 31 31 1111111111111111 -E 100 'Gabi'<ENTER> -D 100 10F<ENTER> 0B2C:0100 47 61 62 69 20 20 20 20-20 20 20 20 20 20 20 20 Gabi -E 100<ENTER> 0B2C:0100 47.67<ENTER> -D 100 10F<ENTER> 0B2C:0100 67 61 62 69 20 20 20 20-20 20 20 20 20 20 20 20 gabi -E 100<ENTER> 0B2C:0100 67.<SPACE BAR> 61.41<SPACE BAR>62.42<SPACE BAR>69.49<ENTER> -D 100 10F<ENTER> 0B2C:0100 67 41 42 49 20 20 20 20-20 20 20 20 20 20 20 20 gABI - Step 6 (20 points) - Perform the following operations then copy and save the results:

• Fill memory locations 100 to 12F with the ASCII character which represents the number 5, then display the modified memory locations.

• Enter EE3751 in memory location 130, and then display those memory locations.

• Issue the E 130 command, then use the space bar to move through the data string to locate the data you want to modify. Modify the 3 to a 2, and the 51 to a 30. Display addresses 130 through 135.

Page 13: EE3751 Microprocessor Laboratory Summer 2009

8

Your first assembly Now you are going to be exposed to the process of using Turbo Assembler, Turbo Linker, Debug, and Notepad to create and execute an assembly program. A small program has been provided for your use. Copy the program and edit it using Notepad. Save it as PROG1.ASM . Sometimes the single quotes, shown in red in the listing, do not translate correctly to Notepad, so make sure you delete them and rewrite them within Notepad so they do not cause any problem during assembly.

.MODEL SMALL

.STACK 64

.DATA MESS DB ‘Hello World!’,13,10,’$’ .CODE BEGIN PROC FAR MOV AX,@DATA MOV DS,AX MOV AH,9H MOV DX,OFFSET MESS INT 21H MOV AH,4CH INT 21H BEGIN ENDP END BEGIN Following you will find the commands that you should type to accomplish the task of assembling, linking and using DEBUG to execute the program given to you. Step 7 (10 points) – Perform the commands shown below then copy and save the results. Z:\>TASM PROG1.ASM /L<ENTER> Turbo Assembler Version 3.1 Copyright (c) 1988, 1992 Borland International Assembling file: PROG1.ASM Error messages: None Warning messages: None Passes: 1 Remaining memory: 435k

If there are any problems during assembly you will see several error messages displayed on a DOS window opened by the OS. At this point you may open the file PROG1.LST to check where the errors occur and then edit them in the PROG1.ASM file, before assembling it again, otherwise continue below. Z:\>TLINK PROG1.OBJ<ENTER> Turbo Link Version 5.1 Copyright (c) 1992 Borland International

Page 14: EE3751 Microprocessor Laboratory Summer 2009

9

Now you are going to use DEBUG to execute the program. Z:\>DEBUG PROG1.EXE<ENTER> -G<ENTER> Hello World! Program terminated normally -Q<ENTER> Z:\>

You can also execute the program directly by doing what is shown below: Z:\>PROG1.EXE<ENTER> Hello World! Z:\>

Page 15: EE3751 Microprocessor Laboratory Summer 2009

10

Experiment 2 – Simple Programs, and Subroutines

Objectives:

• to write small assembly language program containing subroutines, to assemble, debug and execute it;

• to be able to determine the addresses of data segment and the stack. • to retrieve information from the data segment and stack. • to list, define and use the different forms of procedure communication.

Report The answers to this experiment questions, should be given to the instructor before you exit the lab, and they will be composed of:

• the printout of a file named E2GXY.TXT where X is your section number and Y your desk number. This file will contain the answers and information requested in the experiment by statements and questions colored red. Please clearly identify your answers, by including a Step x sentence with it. Also the information shown below should be placed on the top of the first page:

o Students’ names o Date o Program number o Desk number

• The printout of your program named P2GXY.ASM where X is your section number and Y your desk number. Please include the following information at the top of the first page:

o Students’ names o Date o Program number o Desk number

To copy the information from the Command Prompt window do:

• click on the icon on the top left corner of the window, then select Edit, Mark;

• use the mouse to select information to be copied; • click on the icon on the top left corner of the window, then select Edit,

Copy Enter; • paste the information just copied into a file named E2GXY.TXT which

you can open using Notepad.

Page 16: EE3751 Microprocessor Laboratory Summer 2009

11

.MODEL SMALL

.STACK 64

.DATA N1 DB 33H N2 DB 24H SUM DB 0H .CODE BEGIN PROC FAR MOV AX,@DATA MOV DS,AX MOV AL,N1 ADD AL,N2 MOV SUM,AL MOV AH,4CH INT 21H BEGIN ENDP END BEGIN Copy the program above using Notepad, and save it as PROG2A.ASM in your network drive or the drive assigned to your flash drive. Copy the program shown below into a file called go.bat which you will create with notepad. This file is a batch file which you will use to assemble, link and execute your program. Make sure Notepad does not append the .txt to the file name by selecting the All Files from the Save as type choices provided to you by Notepad. TASM %1 /l TLINK %1 DEBUG %1.exe To use the batch file you just created to assemble, link and execute a program called PROG2A.ASM, issue the following command at the dos prompt: Z:\>GO PROG2A<ENTER> Z:\>TASM PROG2A Turbo Assembler Version 3.1 Copyright (c) 1988, 1992 Borland International Assembling file: PROG2A.ASM Error messages: None Warning messages: None Passes: 1 Remaining memory: 435k Z:\>TLINK PROG2A Turbo Link Version 5.1 Copyright (c) 1992 Borland International A:\>DEBUG PROG2A.EXE -

Page 17: EE3751 Microprocessor Laboratory Summer 2009

12

If there are any problems during assembly you will see several error messages displayed on a DOS window opened by the OS. At this point you may open the file PROG2A.LST to check where the errors occur and then edit them in the PROG2A.ASM file, before assembling it again, otherwise continue below. Now you are going to use DEBUG to execute the program. -G<ENTER> Program terminated normally -Q<ENTER> Z:\> You can also execute the program directly by issuing the following commands: Z:\>PROG2A.EXE<ENTER> Z:\> Or Z:\>PROG2A<ENTER> Z:\> Step 1 _ Execute PROG2A using DEBUG and directly from DOS by issuing PROG2A.exe command. Copy and save steps 1. The next steps allow you to find out the initial address of the data segment, and its contents. You will do this by disassembling the first instruction MOV AX,@DATA of your program, then dumping the contents of several memory locations starting at the address you just found. Issue the commands shown below: A:\>DEBUG PROG2A.EXE -U CS:0 1<ENTER> 10A2:0000 B8A410 MOV AX,10A4

The disassembly shown above allows you to figure out that the address of the data segment is 10A4. Continue below. -D 10A4:0 2<ENTER> 10A4:0000 33 24 00 3$.

The DEBUG command D 10A4:0 2 will dump the contents of the first three memory locations in the Data Segment. These three locations were defined in the program to contain the variable N1, N2, and SUM as shown below: N1 DB 33H N2 DB 24H SUM DB 0H

Page 18: EE3751 Microprocessor Laboratory Summer 2009

13

To execute the program, and to display the memory, follow the steps below. These steps allow you to verify if the program executed correctly. -G=0<ENTER> -D 10A4:0 2<ENTER> 10A4:0000 33 24 57 3$W

Note that the third value, which is the value of the SUM variable, was originally set to zero, but now it contains the result of the operation 33+24=57. Quitting DEBUG. -Q<ENTER> Z:\>

Copy and save steps 6, 7 and 8. Subroutines (Procedures) Subroutines are groups of instructions that usually perform one task. These tasks may be reused as often as necessary and may be called from anywhere in the program. Memory is saved by using procedures, but one disadvantage is the longer execution time needed for the computer to link to the procedure and to return to the location where the procedure was called. A program may be composed of a single procedure, but usually it is composed of several small procedures thus making the program more structured. Procedures are defined as shown below: DELAY PROC operand DELAY ENDP The operands may be the NEAR or the FAR ones. The difference between these operands is the size of the address they store onto the stack to identify the returning location for the subroutine. The FAR operand stores both the segment and the effective addresses while the NEAR operand only stores the effective address. This difference allows a procedure to be stored anywhere in memory when defined as a FAR one and only within the current segment when defined as a NEAR one. DOS requires that the entry procedure, also known as the main procedure, be defined as a FAR procedure. Two instructions are used with procedures:

• CALL - used to execute the procedure; • RET - used to return program execution to the point following the CALL

statement. Note that a program may have many CALL statements, but the address stored onto the stack refers to the CALL being executed.

Page 19: EE3751 Microprocessor Laboratory Summer 2009

14

Example of a procedure: ; This procedure is used to generate a delay DELAY PROC NEAR PUSH ECX MOV ECX,07FFFFH AGAIN: LOOP AGAIN POP ECX RET DELAY ENDP One may arrange his subroutines in any order due to the fact that the entry or main subroutine is identified by the END Name of Subroutine statement located at the end of the program. For this lab and your next labs, you will follow the following format for the placement of your program’s procedures: .MODEL SMALL .STACK 64 .DATA MESS DB ‘Hello World!’,13,10,’$’ .CODE MAIN PROC FAR ;Always defined as FAR and always on the top. MOV AX,@DATA MOV DS,AX MOV AH,9H MOV DX,OFFSET MESS INT 21H CALL DELAY MOV AH,4CH INT 21H MAIN ENDP DELAY PROC NEAR ;May be defined as FAR or NEAR

; and always follows the main routine PUSH CX MOV CX,0FFFFH

AGAIN: LOOP AGAIN POP CX RET DELAY ENDP END MAIN ;This statement defines which procedure is the entry one. Procedure Communication

Page 20: EE3751 Microprocessor Laboratory Summer 2009

15

Occasionally a procedure will need to operate on data which has to be passed from the calling procedure. This communication may be done in different ways which will be explored in the next paragraphs. There are three different ways to pass information between procedures:

- Passing parameters via registers; - Passing parameters via memory; - Passing parameters via stack.

Using registers is the easiest way to pass parameters among procedures. One simply:

- selects one or more registers; - stores the desired information to be passed to the procedure into

them; - call the procedure.

The limited number of registers a CPU has is only one problem with this method. If the amount of information to be passed among procedures is large, one may use either memory or the stack for that purpose. When using memory, an area of RAM is reserved for the purpose of holding the information to be used by the procedure. The problem with this method is that there must be universal agreement regarding the addresses used to pass the information amongst the different procedures. I would venture to say, this task would be impossible amongst different software designers. Using the stack would avoid the problem of agreeing to a specific memory range, but this method has its own issues that need to be addressed. The stack is a very critical data structure used by the system to store important information and addresses, and one needs to be extremely careful when using it, so that the information and addresses stored by the system are not corrupted in any way or form, which would cause the system to crash. 9 – Using the information learned up to now, write a program to read the values of an array containing temperature information in degrees Celsius and convert

the data read to degrees Fahrenheit. The conversion formula is 325

9+

°×=°

CF

and the results may be truncated to an integer value. Name your program PRG2GPXY.ASM, where X is your section number and Y your desk number. The arrays are defined below: .DATA TEMP_CENT DB -5, 0, 5, 20, 36, 100 TEMP_FAHR DB 6 DUP(?) The main procedure of your program should:

- read into AL a value from the TEMP_CENT array;

Page 21: EE3751 Microprocessor Laboratory Summer 2009

16

- call the procedure CONVERT to perform the conversion and store the result in AL;

- the converted value, returned from the subroutine in AL, should be stored into the array TEMP_FAHR upon returning to the main procedure;

- stop execution of program after the last element of array has been reached otherwise repeat from the beginning.

Note that you will be using a register, AL in this case, to communicate with the CONVERT procedure. Use the LOOP instruction to create the loop in the main routine and make sure to use the appropriate form of the multiply and divide instructions, both in terms of the size of the data but also in term of the data being integer (negative values included). Assemble, link, and execute your program, then find out the address of the data segment and display the contents of the two arrays. Make sure to create the listing, by using the /L attribute when you assemble your program. Copy and save step 9. 10 – Open the listing file you created during assembly and find the address of the first instruction in the CONVERT subroutine and the address of the instruction following the CALL CONVERT instruction. 1 0000 .MODEL SMALL 2 0000 .STACK 64 3 0000 .DATA 4 0000 33 N1 DB 33H 5 0001 24 N2 DB 24H 6 0002 00 SUM DB 0H 7 0003 .CODE 8 0000 BEGIN PROC FAR 9 10 0000 B8 0000s MOV AX,@DATA 11 0003 8E D8 MOV DS,AX 12 13 0005 E8 000E CALL DELAY 14 0008 A0 0000r MOV AL,N1 15 000B 02 06 0001r ADD AL,N2 16 000F A2 0002r MOV SUM,AL 17 18 0012 B4 4C MOV AH,4CH 19 0014 CD 21 INT 21H 20 21 0016 BEGIN ENDP 22 23 0016 DELAY PROC NEAR 24 25 0016 B9 FFFF MOV CX,0FFFFH 26 0019 E2 FE AGAIN: LOOP AGAIN 27 001B C3 RET 28

Page 22: EE3751 Microprocessor Laboratory Summer 2009

17

29 001C DELAY ENDP 30 31 END BEGIN Using the example shown above, I will find the address of the first instruction of the DELAY subroutine and the address after the CALL DELAY instruction. The attributes of the address of the instructions of interest has been changed to italics and red. The addresses are:

- 0008 for the instruction following the CALL DELAY instruction; - 0016 for the first instruction of the DELAY subroutine.

Issue a command in debug to execute your program from the beginning up to the first instruction of the subroutine. The command should have the following form: -G =0 XXXX Where: XXXX is the address of the first instruction in subroutine, which you found in the assembler listing. When DEBUG stops the execution of the program at the desired address, it will display the contents of the registers at that point. Use the stack segment address – SS and the stack pointer address – SP to dump a few bytes of the stack. Check the stack and notice that the last entry on the stack is the address of the instruction following the CALL CONVERT instruction from your program. Needs clarifying. This series of steps allowed you to verify that when the CPU executes a CALL instruction it stores into the stack the return address so that when the RET instruction is reached the CPU will know where to return to in the program. Copy and save step 10.

Page 23: EE3751 Microprocessor Laboratory Summer 2009

18

Experiment 3 – BIOS and DOS Interrupts. Objectives:

• to write small assembly language program containing interrupt subroutines;

• to list, define and use the different interrupts and their different options. Included within the BIOS and DOS one will find a set of interrupts that are extremely useful. These interrupt subroutines may be used by issuing a software interrupt call ( INT type ). The user will also have to identify which function is being used by setting the AH register to a specific value. Other registers may also need to be modified. One should note that interrupts are a FAR call, in other words, when an interrupt is executed the return address is stored as CS:IP. Two interrupt calls will be described in this experiment, they are:

BIOS interrupt - INT 10H DOS interrupt - INT 21H

BIOS INT 10H INT 10H are stored in the BIOS ROM of the IBM PC type computers, and they are used to control the screen video. The monitor screen in normal text mode is composed of 25 rows and 80 columns, and text mode is the default mode whenever a monitor is turned on. There are several types of video modes including: MDA, MCGA, CGA, EGA and VGA. In all these modes the text screen is 80X25 characters long. The text locations are numbered from 0 to 24 for the rows and 0 to 79 for the columns as shown in the diagram below.

00,00 00,79 24,00 24,79

Several functions are performed by INT 10H, therefore the programmer needs to identify which one is being used by storing an appropriate value in register AH. For example: AH = 00H ;Selects the change video mode function INT 10H ;Executes BIOS interrupt 10H.

Page 24: EE3751 Microprocessor Laboratory Summer 2009

19

Depending on the function being used, other register may be used to pass information to the interrupt subroutine. In Experiment 2 this action was labeled procedure communication using registers. Following are the descriptions of several of the most common INT 10H functions. INT 10H Function 02H: Set Cursor Position AH = 02H BH = Page number DH = Row number DL = Column number BH = 0 when graphics mode is in use. INT 10H Function 06H: Scroll window up INT 10H Function 07H: Scroll window down AH = 06H to scroll up or 07H to scroll down AL = Number of lines to scroll BH = Display attribute CH = Y coordinate of top left CL = X coordinate of top left DH = Y coordinate of lower right DL = X coordinate of lower right If AL = 0 the entire window is blank, otherwise, the screen will be scrolled upward/downward by the value stored in AL. Lines scrolling off the screen are lost and blank lines are scrolled in at the bottom/top according to the attribute in BH. INT 10H Function 08H: Read character and attribute at cursor position AH = 08H BH = Display page AH = Returned attribute byte AL = Returned ASCII character code INT 10H Function 09H: Write character and attribute at cursor position AH = 09H AL = ASCII character code BH = Display page BL = Attribute CX = Number of characters to write

Page 25: EE3751 Microprocessor Laboratory Summer 2009

20

The character attribute is defined as shown in the following tables: Monochrome display attributes Blinking Background Intensit

y Foreground

D7 D6 D5 D4 D3 D2 D1 D0 D7 Non-blinking= 0 Blinking = 1 D3 Normal intensity = 0 Highlighted intensity = 1 D6 D5 D4 and D2 D1 D0 White = 0 0 0 Black = 1 1 1 CGA display attributes

Blinking Background Intensit

y Foreground

R G B R G B D7 D6 D5 D4 D3 D2 D1 D0

D7 Non-blinking= 0 Blinking = 1 D3 Normal intensity = 0 Highlighted intensity = 1 Both blinking and intensity are applied to foreground only. D6 D5 D4 and D2 D1 D0 Color as defined on the following table Color Attributes

I R G B Color 0 0 0 0 Black 0 0 0 1 Blue 0 0 1 0 Green 0 0 1 1 Cyan 0 1 0 0 Red 0 1 0 1 Magenta 0 1 1 0 Brown 0 1 1 1 White 1 0 0 0 Gray 1 0 0 1 Light blue 1 0 1 0 Light green 1 0 1 1 Light cyan 1 1 0 0 Light red 1 1 0 1 Light magenta 1 1 1 0 Yellow 1 1 1 1 High intensity white

Page 26: EE3751 Microprocessor Laboratory Summer 2009

21

DOS INT 21H INT 21H is provided by DOS, and it is stores in DRAM when the operating system is loaded. The user can invoke this interrupt to perform several useful functions, like inputting data from keyboard, and outputting data to monitor. The invoking procedure is like the one used with INT 10H, in other words, identify the function by setting register AH to a specific value then call INT 21H. Following are the descriptions of several of the most common INT 21H functions. INT 21H Function 01H: Inputting a single character from the keyboard with echo. AH = 01H AL = inputted ASCII character code Code example to input a single character from keyboard and to echo it to the display. MOV AH,01H INT 21H INT 21H Function 02H: Outputting a single character to the monitor. AH = 02H DL = ASCII character code to be displayed INT 21H Function 09H: Outputting a string terminated with $ to the monitor. AH = 09H DX = String address INT 21H Function 4CH: Terminate a process ( EXIT ). AH = 4CH AL = binary return code This interrupt terminates a process and returns control to DOS or the parent process. Procedure Using the interrupts described above, modify the program written in experiment 2 to query the user for the Celsius value, see below. Enter temperature in degree Celsius: _

Page 27: EE3751 Microprocessor Laboratory Summer 2009

22

Communication between the keyboard and the CPU is done using ASCII code, and it is very common for numerical Information to be converted from ASCII to binary so that the CPU can operate on them. Sometimes numerical data is operated upon in ASCII form due to the fact that the CPU has instructions that can perform arithmetic operation using ASCII values. It is important for you to know that the CPU has a much greater variety of instructions that can operate binary values than ASCII values, therefore conversion between different data formats will be discussed below. Let’s assume the decimal value 53 was entered from the keyboard. This value is transmitted from the keyboard to the CPU as a sequence of two ASCII codes which are shown below: 35H, 33H. The ASCII codes for 5 and 3 are respectively 35H and 33H, and you can verify that in the ASCII table which can be found in Appendix B. To convert these two ASCII codes into a binary number with the same magnitude, use the following procedure: Binary value = 35H – 30H * 0AH + 33H – 30H * 1H Your program should 1 – Query for the value of the temperature in degrees Celsius or the ASCII values ‘Q’ or ‘q’. If the value entered is equal to ‘Q’ or ‘q’, then clear the screen and quit the program, else convert the degree Celsius, entered using the keyboard, from ASCII to binary form and store it in the TEMP_CENT array, then go to step 2. 2 – Clear the screen. 3 - Perform the calculations to convert the temperature from degrees Celsius to degrees Fahrenheit. 4 – Store Fahrenheit value in the TEMP_FAHR array. 5 – Go back to step 1. All values for this experiment will be 2 digits positive integers ( 0 to 99 ). Use the subroutine you created in experiment 2 to convert the degrees Celsius value to degrees Fahrenheit and create new subroutine called CLR_SCREEN to clear the monitor screen. After the execution of the program dump the contents of the data segment, then copy and save the information to a text file which should be submitted with the copy of your program. Note that in the previous program the arrays were defined to contain up to 6 elements each. Keep it that way, and make sure you do not query for more than 6 values otherwise you will overrun your arrays.

Page 28: EE3751 Microprocessor Laboratory Summer 2009

23

Experiment 4 – BIOS and DOS Interrupts - II Objectives:

• to write small assembly language program containing interrupt subroutines;

Procedure Using the interrupts described in experiment 3, modify the program written in experiment 3 to display the converted degrees Fahrenheit values to the computer screen, as shown below. Enter temperature in degree Celsius: 24 24 degrees Celsius is equal to 75 degrees Fahrenheit. In the previous experiment you learned to convert a decimal value represented in ASCII form to the equivalent binary value. This was done so that you could easily perform arithmetic operations (Celsius to Fahrenheit conversion) on the data entered from the keyboard. In this experiment you are going to perform the reverse operation so that the Celsius to Fahrenheit conversion result expressed in binary can be displayed to the monitor in decimal form. This conversion will be done in two steps. The first step is to convert the binary value to its decimal equivalent, and this is done by dividing the binary value consecutively by ten until a zero quotient is achieved. Below is an example showing the procedure using the number 7510 = 10010112 : Quotient Remainder 1001011B/1010B 111B 101B = 5 LSD – Least significant digit 111B/1010B 0B 111B = 7 MSD – Most significant digit The algorithm described above provided two binary values equivalent to the decimal digits of the number 75. In the second step you will convert the binary values computed in the first step to their ASCII equivalent, and this is done by adding 30H to them as shown below: 111B = 5H 111B = 7H 5H + 30H = 35H = ASCII 5 7H + 30H = 37H = ASCII 7 Create the following subroutines: BIN2ASC – This subroutine will convert a binary valued found in AL into its decimal equivalent which is represent as a ASCII string. This ASCII string is

Page 29: EE3751 Microprocessor Laboratory Summer 2009

24

stored in an array called DECIMAL_IN_ASCII. This array which is defined below contains three byte size elements and the third element is always equal to ‘$’. This is done to simplify the display of the decimal value to the screen. DISP_SCREEN – This subroutine will display the value the values and messages to the screen. It should do: 1 – Read the Celsius value from the TEMP_CENT array. 2 - Call BIN2ASC to convert the binary value to ASCII. 3 – Display the value DECIMAL_IN_ASCII to the screen. 4 – Display the message ‘ degrees Celsius is equal to ‘ to the screen. 5 – Read the Fahrenheit value from the TEMP_FAHR array. 6 - Call BIN2ASC to convert the binary value to ASCII. 7 – Display the value DECIMAL_IN_ASCII to the screen. 8 – Display the message ‘ degrees Fahrenheit.‘ to the screen.

Page 30: EE3751 Microprocessor Laboratory Summer 2009

25

Experiment 5 – Mouse and Keyboard Programming

In this experiment you are going to be exposed to both mouse and keyboard programming. Keyboard programming will be discussed first, and this entails, a discussion of the programming interface to the keyboard of your PC. Like the previous BIOS and DOS interrupts, keyboard programming is achieved by the use of BIOS Interrupt 16H explained below. Interrupt 16H Option 0H: Keyboard Read. Result registers:

• AH – Key scan code. • AL – ASCII character.

Note: Reads and removes one character from the keyboard buffer. If there isn’t one it waits until there is. Interrupt 16H Option 1H: Get keyboard status. Result registers and flags:

• ZF = 1 if no key is waiting. • ZF = 0 if key is waiting:

o AH – Key scan code. o AL – ASCII character.

Note: Checks to see if there is a key waiting in the keyboard buffer. If a key press is waiting in the keyboard buffer, then ZF=0, and the codes are returned in AH and AL respectively. This function works like function 0 except the character is not removed from the keyboard buffer. Interrupt 16H Option 2H: Get keyboard status bytes. Result registers and flags:

• AL – ASCII character. o D0 – Right Shift pressed; o D1 Left shift pressed; o D2 – Ctrl pressed; o D3 – Alt pressed; o D4 – Scroll Lock state toggled; o D5 – NumLock state toggled; o D6 – CapsLock state toggled; o D7 – Insert toggled.

Page 31: EE3751 Microprocessor Laboratory Summer 2009

26

The table of scan codes is given in the appendix. Notice that many keys that do not have an ASCII equivalent may be programmed using scan codes. Some examples: F1, F2, PgDn, NumLock, etc. Mouse Programming The mouse was not available when the first PC was released to the public, but it became available with a later version of the PC. The BIOS and DOS interrupt use register AH to pass information regarding which function is to be performed by the interrupt, but INT 33H (mouse interrupt) uses the AX register for that purpose. In graphics mode the mouse pointer will be shown as an arrow; in text mode the mouse pointer is shown as a blinking rectangular block. Mouse sensitivity is measured in mickeys. This unit associates the movement of the cursor on the screen with the movement of the mouse on the pad. For example: a mouse which moves the cursor 400 pixels for every 1 inch of mouse movement has a sensitivity of 400 mickeys. INT 33H Function 0H: Detect the presence of a mouse AX = 0H Upon return: AX = 0 – No mouse is supported AX > 0 – Mouse is supported Example: MOV AX,0 INT 33H CMP AX,0 JE Exit … … INT 33H Function 1H: Displays the mouse cursor AX = 1H INT 33H Function 2H: Hides the mouse cursor AX = 2H

Page 32: EE3751 Microprocessor Laboratory Summer 2009

27

INT 33H Function 3H: Gets current mouse cursor position AX = 3H Upon return: CX = Horizontal coordinate in pixels. DX = Vertical coordinate in pixels. In text mode, one needs to divide these coordinates by 8 to get the character location. This is due to the fact that each character is made with an 8X8 pixel matrix. INT 33H Function 4H: Sets current mouse cursor position AX = 4H CX = Horizontal coordinate in pixels. DX = Vertical coordinate in pixels. In text mode, one needs to divide these coordinates by 8 to get the character location. This is due to the fact that each character is made with an 8X8 pixel matrix. INT 33H Function 5H: Gets mouse button press information AX = 5H BX = 0 for left button, 1 for right button, 2 for center button; Upon return: AX = button status, where: D0 = Left button: 1 = Down, 0 = Up; D1 = Right button: 1 = Down, 0 = Up; D2 = Center button; 1 = Down, 0 = Up BX = Button press count since the last call to this function. CX = Horizontal coordinate in pixels at the last button press. DX = Vertical coordinate in pixels at the last button press. INT 33H Function 6H: Gets mouse button release information AX = 6H BX = 0 for left button, 1 for right button, 2 for center button;

Page 33: EE3751 Microprocessor Laboratory Summer 2009

28

Upon return: AX = button status, where: D0 = Left button: 1 = Down, 0 = Up; D1 = Right button: 1 = Down, 0 = Up; D2 = Center button; 1 = Down, 0 = Up BX = Button release count since the last call to this function. CX = Horizontal coordinate in pixels at the last button press. DX = Vertical coordinate in pixels at the last button press. INT 33H Function 7H: Sets horizontal for the mouse pointer AX = 7H CX = Minimum x coordinate in pixels. DX = Maximum x coordinate in pixels. INT 33H Function 8H: Sets horizontal for the mouse pointer AX = 8H CX = Minimum x coordinate in pixels. DX = Maximum x coordinate in pixels. INT 33H Function 10H: Sets an exclusion area for the mouse pointer AX = 10H CX = Upper horizontal coordinate in pixels. DX = Upper vertical coordinate in pixels. SI = Lower horizontal coordinate in pixels. DI = Lower vertical coordinate in pixels. Procedure Write a program to:

1. Change the background attribute to blue with yellow foreground. 2. Display a rectangular area with red background, and yellow foreground. A

diagram is given below denoting the location of the rectangle and messages.

3. When you click the left button on the mouse a message should be displayed, in the appropriate area (blue or red one), giving the mouse cursor coordinates and button press count (max of 9). Use the character coordinate (0,0 to 24,79) because it requires a maximum of two digits to

Page 34: EE3751 Microprocessor Laboratory Summer 2009

29

be represented. You already have the code for that from previous experiments.

4. Check for keyboard input and do: a. Clear the screen and quit the program for either a ‘Q’ or ‘q’ is

pressed. b. If a ‘R’, ‘r’, ‘B’, or ‘b’ is pressed, update the appropriate press count

display and also update the Coordinate display to indicate a ’-:-‘ coordinate.

Note that the max number of button or keyboard presses is 9, to facilitate the code implementation.

Button or keyboard press count = 6

Coord: -,-

Button or keyboard press count = 3

Coord: 12, 34

.

Page 35: EE3751 Microprocessor Laboratory Summer 2009

30

Appendix A – DOS Commands

CD or CHDIR

CD (Change Directory) is a command used to switch directories in MS-DOS.

SYNTAX

CHDIR [drive:][path] CHDIR[..] CD [drive:][path] CD[..]

EXAMPLES

cd\

Changes the directory to the root directory of the drive.

cd..

Goes back one directory.

cd work

Changes from the present directory to the subdirectory called work

cd\work

The directory would initially be changed to the root directory and then to the work directory.

CLS CLS is a command that clears contents of the screen, leaving only a prompt. SYNTAX

CLS

Page 36: EE3751 Microprocessor Laboratory Summer 2009

31

COPY

Copy one or more files to another location.

SYNTAX

COPY [/A | /B] source [destination] [/A | /B]] [/V] [/Y | /-Y]

source Specifies the file or files to be copied. /A Indicates an ASCII text file. /B Indicates a binary file. destination Specifies the directory and/or filename for the new file(s). /V Verifies that new files are written correctly.

/Y Suppresses prompting to confirm you want to overwrite an existing destination file.

/-Y Causes prompting to confirm you want to overwrite an existing destination file.

To append files, specify a single file for destination, but multiple files for source (using wildcards or file1+file2+file3 format).

EXAMPLES

copy *.* a:

Copy all files in the current directory to the floppy disk in drive a:

copy file1.txt+file2.txt

Copy the contents of file2.txt and combine it with the contents of file1.txt.

DIR

Displays a list of files and subdirectories in a directory.

SYNTAX

DIR [drive:][path][filename] [/A[[:]attributes]] [/B] [/C] [/D] [/L] [/N] [/O[[:]sortorder]] [/P] [/Q] [/S] [/T[[:]timefield]] [/W] [/X] [/4]

[drive:][path][filename] Specifies drive, directory, and/or files to list. Attributes D Directories

Page 37: EE3751 Microprocessor Laboratory Summer 2009

32

R Read-only files H Hidden files A Files ready for archiving S System files - Prefix meaning not

/B Uses bare format (no heading information or summary). /C Display the thousand separator in file sizes. This is the default.

Use /-C to disable display of separator. /D Same as wide but files are list sorted by column. /L Uses lowercase. /N New long list format where filenames are on the far right. /O List by files in sorted order. Sortorder N By name (alphabetic)

S By size (smallest first) E By extension (alphabetic) D By date/time (oldest first) G Group directories first - Prefix to reverse order

/P Pauses after each screenful of information. /Q Display the owner of the file. /S Displays files in specified directory and all subdirectories. /T Controls which time field displayed or used for sorting Timefield C Creation

A Last Access W Last Written

/W Uses wide list format. /X This displays the short names generated for non-8dot3 file

names. The format is that of /N with the short name inserted before the long name. If no short name is present, blanks are displayed in its place.

/4 Displays four-digit years

EXAMPLES

dir

Lists all files and directories in the directory that you are currently in.

dir /p

Page 38: EE3751 Microprocessor Laboratory Summer 2009

33

Using this command will display all files one page at a time. Useful when the number of files exceed what can be displayed in a single page.

Page 39: EE3751 Microprocessor Laboratory Summer 2009

34

Appendix B – ASCII Table

Control and alphanumeric codes: Char Dec Hex | Char Dec Hex | Char Dec Hex | Char Dec Hex --------------------------------------------------------------------- (nul) 0 0x00 | (sp) 32 0x20 | @ 64 0x40 | ` 96 0x60 (soh) 1 0x01 | ! 33 0x21 | A 65 0x41 | a 97 0x61 (stx) 2 0x02 | " 34 0x22 | B 66 0x42 | b 98 0x62 (etx) 3 0x03 | # 35 0x23 | C 67 0x43 | c 99 0x63 (eot) 4 0x04 | $ 36 0x24 | D 68 0x44 | d 100 0x64 (enq) 5 0x05 | % 37 0x25 | E 69 0x45 | e 101 0x65 (ack) 6 0x06 | & 38 0x26 | F 70 0x46 | f 102 0x66 (bel) 7 0x07 | ' 39 0x27 | G 71 0x47 | g 103 0x67 (bs) 8 0x08 | ( 40 0x28 | H 72 0x48 | h 104 0x68 (ht) 9 0x09 | ) 41 0x29 | I 73 0x49 | i 105 0x69 (nl) 10 0x0a | * 42 0x2a | J 74 0x4a | j 106 0x6a (vt) 11 0x0b | + 43 0x2b | K 75 0x4b | k 107 0x6b (np) 12 0x0c | , 44 0x2c | L 76 0x4c | l 108 0x6c (cr) 13 0x0d | - 45 0x2d | M 77 0x4d | m 109 0x6d (so) 14 0x0e | . 46 0x2e | N 78 0x4e | n 110 0x6e (si) 15 0x0f | / 47 0x2f | O 79 0x4f | o 111 0x6f (dle) 16 0x10 | 0 48 0x30 | P 80 0x50 | p 112 0x70 (dc1) 17 0x11 | 1 49 0x31 | Q 81 0x51 | q 113 0x71 (dc2) 18 0x12 | 2 50 0x32 | R 82 0x52 | r 114 0x72 (dc3) 19 0x13 | 3 51 0x33 | S 83 0x53 | s 115 0x73 (dc4) 20 0x14 | 4 52 0x34 | T 84 0x54 | t 116 0x74 (nak) 21 0x15 | 5 53 0x35 | U 85 0x55 | u 117 0x75 (syn) 22 0x16 | 6 54 0x36 | V 86 0x56 | v 118 0x76 (etb) 23 0x17 | 7 55 0x37 | W 87 0x57 | w 119 0x77 (can) 24 0x18 | 8 56 0x38 | X 88 0x58 | x 120 0x78 (em) 25 0x19 | 9 57 0x39 | Y 89 0x59 | y 121 0x79 (sub) 26 0x1a | : 58 0x3a | Z 90 0x5a | z 122 0x7a (esc) 27 0x1b | ; 59 0x3b | [ 91 0x5b | { 123 0x7b (fs) 28 0x1c | < 60 0x3c | \ 92 0x5c | | 124 0x7c (gs) 29 0x1d | = 61 0x3d | ] 93 0x5d | } 125 0x7d (rs) 30 0x1e | > 62 0x3e | ^ 94 0x5e | ~ 126 0x7e (us) 31 0x1f | ? 63 0x3f | _ 95 0x5f | (del) 127 0x7f

Page 40: EE3751 Microprocessor Laboratory Summer 2009

35

IBM PC extended codes:

Page 41: EE3751 Microprocessor Laboratory Summer 2009

36

Scan codes Hex Key Hex Key Hex Key Hex Key 01 Esc 17 I and i 2D X and x 43 F9 02 ! and 1 18 O and o 2E C and c 44 F10 03 @ and 2 19 P and p 2F V and v 45 NumLock 04 # and 3 1A { ans [ 30 B and b 46 ScrollLock 05 $ and 4 1B } and ] 31 N and n 47 7 and Home 06 % and 5 1C Enter 32 M and m 48 8 and ↑ 07 ^ and 6 1D Ctrl 33 < and , 49 9 and PgUp 08 & and 7 1E A and a 34 > and . 4A - (keypad) 09 * and 8 1F S and s 35 ? and / 4B 4 and ← 0A ( and 9 20 D and d 36 Right shift 4C 5 (keypad) 0B ) and 0 21 F and f 37 PrtSc and * 4D 6 and → 0C - and _ 22 G and g 38 Alt 4E + (keypad) 0D + and = 23 H and h 39 Spacebar 4F 1 and End 0E Backspace 24 J and j 3A CapsLock 50 2 and ↓ 0F Tab 25 K and k 3B F1 51 3 and PgDn 10 Q and q 26 L and l 3C F2 52 0 and Ins 11 W and w 27 : and ; 3D F3 53 . and Del 12 E and e 28 “ and ‘ 3E F4 13 R and r 29 ~ and ` 3F F5 14 T and t 2A Left shift 40 F6 15 Y and y 2B | and \ 41 F7 16 U and u 2C Z and z 42 F8

Page 42: EE3751 Microprocessor Laboratory Summer 2009

37

Appendix C – Datasheets 1. Device datasheets are easily found by searching the internet with your favorite

search engine. Search for the part number, i.e., 74LS08.

2. Request the TTL Logic book from the Monitor in room 128. You will need to present your student id to be able to use the book.

Page 43: EE3751 Microprocessor Laboratory Summer 2009

38

Appendix D – Parallel Port Information

Table 1 Data Register (Base Address)

Bit Pin: DB-25 Signal Name Inverted at connector? I/O

0 2 Data bit 0 No Output 1 3 Data bit 1 No Output 2 4 Data bit 2 No Output 3 5 Data bit 3 No Output 4 6 Data bit 4 No Output 5 7 Data bit 5 No Output 6 8 Data bit 6 No Output 7 9 Data bit 7 No Output Status Register (Base Address + 1)

Bit Pin: DB-25 Signal Name Inverted at connector? I/O

3 15 nError No Input 4 13 Select No Input 5 12 PaperEnd No Input 6 10 nAck No Input 7 11 Busy Yes Input Control Register (Base Address + 2)

Bit Pin: DB-25 Signal Name Inverted at connector? I/O

0 1 NStrobe Yes Output 1 14 nAutoLF Yes Output 2 16 Ninit No Output 3 17 nSelectIn Yes Output

4 IRQ 1 = enabled

5 Bidirectional 1 = input

Ground Connections

Bit Pin: DB-25 Signal Name Inverted at connector? I/O

18 – 25 Ground

Page 44: EE3751 Microprocessor Laboratory Summer 2009

39

DB-25 and DB-9 connector pin out.

Base addresses

• 278H

• 378H

• 3BCH

Page 45: EE3751 Microprocessor Laboratory Summer 2009

40

Memory location containing the three addresses of the parallel ports used by the PC.

408H 409H 40AH 40BH 40CH 40DHLow byte

High byte

Low byte

High byte

Low byte

High byte

LPT1 LPT2 LPT3

Page 46: EE3751 Microprocessor Laboratory Summer 2009

41

Appendix E – Serial Port Information

DB9 pin out

Pin Description1 Data carrier detect - DCD'2 Received data - RxD3 Transmitted data - TxD4 Data terminal ready - DTR5 Signal ground - GND6 Data set ready - DSR'7 Request to send - RTS'8 Clear to send - CTS'9 Ring indicator - RI

Page 47: EE3751 Microprocessor Laboratory Summer 2009

42

DB25 pin out

Pin Description1 Protective ground2 Transmitted data - TxD3 Received data - RxD4 Request to send - RTS'5 Clear to send - CTS'6 Data set ready - DSR'7 Signal ground - GND8 Data carrier detect - DCD'9 Reserved for data set testing10 Reserved for data set testing11 Unassigned12 Secondary data carrier detect13 Secondary clear to send14 Secondary transmitted data15 Transmit signal element timing16 Secondary received data17 Receive signal element timing18 Unassigned19 Secondary request to send20 Data terminal ready - DTR'21 Signal quality detect22 Ring indicator - RI23 Data signal rate select24 Transmit signal element timing25 Unassigned