Vous êtes sur la page 1sur 9

CpE 311MICROPROCESSOR SYSTEMS LABORATORY

Week of September 4, 2017


Lab #3
______
Fall 2017
Introduction:

One of the main focuses of this course is learning the assembly programming language.
Throughout the semester, students will learn to code, compile, execute, and debug
assembly programs. This lab is designed to introduce students to some of the basic
software tools that can be used for assembly programming.

Exercise 1: Introduction to DEBUG

DEBUG is a tool which is included in all distributions of Microsoft DOS (Disk Operation
System). DEBUG provides the ability to work with software at the assembly language
level. DEBUG can be used to trace program execution and debug assembly code (hence
the name). Although it is possible to create assembly programs using DEBUG, it is not
recommended for writing long or complicated programs. Other tools will be introduced
in the following weeks which provide a more proper environment for software
development.

To get to DEBUG in Windows, you need to first make sure that you have 'Xming' and
'PuTTY' installed on your computer. Then follow the following steps:

1.) Start Xming by searching for it under the Windows start button:

a. (an icon on the left corner of the PuTTY window will appear)

2.) Start PuTTY by searching for it under the Windows start button
a. This should bring up a window like the following:
3.) In PuTTY, under the Host Name (or IP address) field, enter our shell server
host name: shell.lcsee.wvu.edu
4.) Beside that, in the Port field, enter our shell servers port number: 20110

Your PuTTY Configuration should now look like the following:

5.) In PuTTY on the left, expand the SSH drop down list by clicking on the '+'
button.
6.) Select 'X11' that is under the 'SSH' drop down list
7.) Select (Check) 'Enable X11 Forwarding' (on the right hand side of the PuTTY
window
Your PuTTY Configuration should look like the following figure:
8.) Now Select the Open button on your PuTTY window which will automatically
open a PuTTY terminal for you.
a. If it prompts you for something like authenticity of the host/host keys/RSA
key fingerprint and bunch of other jumble, just select YES.
9.) Login with your MIX credentials.

You should now have the PuTTY shell terminal up:


10.) Run loud-bochs as
$ loud-bochs
a. This will bring up yet another window called Bochs x86-64 emulator.
Ignore it for now and go back to the PuTTY shell terminal
11.) bochs will execute in debug mode. Continue execution by entering
<bochs:1> c
at the prompt.
12.) The DOS environment will execute and initialize in the Bochs x86-64
emulator. Wait for the prompt
C:\>
13.) Enter the following command to start the debugger in the x86 emulator
C:\> debug

The debug window will open, and a - will appear before the cursor. Type a question
mark to bring up the help menu. This will provide a list of the commands available in
DEBUG.

Research/experiment with the commands to determine how they work. Be aware that
modifying certain memory locations may hang or reset the computer. Additional
DEBUG references are available in the CPE310 textbook.
To fully understand the debug commands listed in Figure 1 (next page), it is necessary to
research and manually test out these commands. For this exercise, choose four of the
eight commands of your choice found in Figure 1 and answer the following questions for
each command:

Questions:

1) What is the main purpose of this command?

2) What information must be entered to use this command?

3) What is displayed to the screen when this command is used?

4) Give an example of using this command. (Data entered, Results Displayed)


Figure 1: Debug Commands

Exercise 2: Using DEBUG

This exercise walks the students through a series of DEBUG commands. Follow the
instructions below, and be sure to comment on each step. Remember to fully answer all
questions asked.

1) Use the DISPLAY command to view the contents at address 2000 (D 2000).
DEBUG will display several rows of data to the screen. The first 8 hexadecimal
numbers signify the starting address of the row. The next two hexadecimal numbers
(one byte) signify the contents of memory location 2000. The next two signify the
contents of memory location 2001, and so on. At the end of each line (16 bytes long),
DEBUG displays the ASCII equivalent for each byte. In this example, all memory
locations contain 00, so there arent any ASCII values to display (dashes are used
for values that cant be displayed). Comment on what is observed.

Figure 2: Dump Command Example

2) When using the D 2000 command, there are 16 number pairs between addresses
2000 and 2010. Explain how this is possible.
3) Use the Enter command to place the value 24 into memory location 2000.
a. Verify the results using the Dump command.
i. Take a screenshot of this.
b. Does this value get interpreted as an ASCII character? If so, which
one.
c. What would happen if a decimal value was input rather than a
hexadecimal value (e.g. 1310)?

4) Use the Enter command to enter the binary number 01011010 into location 2000.
What operations have to be performed to do this? Comment on the results.

5) Use the Enter command to place a list of numbers into consecutive memory
locations (e.g. E 2000 1 2 3 4 5 6 7 8 9 A B C D E F).Verify the results using the
Dump command.
a. Take a screenshot of this.

6) Use the Enter command to place the letter G into memory location 2000 (e.g. E
2000 G).
a. What is actually stored at memory location 2000? What is the
hexadecimal equivalents for each ASCII character of the following string:
ALEX<3JBIEBER? HINT: DEBUG can interpret the following command:
E 2000 ALEX<3JBIEBER!!!
b. Take a screenshot of this.

TIP: If you need to look up several ASCII characters, using this method in DEBUG
is almost always faster than manually looking through a table.

7) After an assembly program is written, the assembly instructions are converted into
instructions that hardware can understand (1s and 0s). These 1s and 0s are then
stored in memory locations, which DEBUG will display in hexadecimal form. The
Disassemble command takes the data stored in memory and attempts to convert it
back into meaningful assembly instructions (like the ones you will learn this
semester). Whether this works or not depends on if the data stored is actually part of
an assembly program. If the stored data is not part of an assembly program, then the
resulting instructions will be meaningless. Try to disassemble the data starting at
memory location 2000 (e.g. U 2000). Did this do what you expected?
a. Take a screenshot of this.
b. Explain the output and interpret the output.

Exercise 3: Number Systems and Arithmetic Review

This exercise is designed to review number system conversions and arithmetic, while also
introducing students to their first basic assembly program. Be sure to fully answer all of
the questions asked in this section. (Note, do not use cell phone, calculator or computer)
Convert the following numbers to hex.

1) 1010 00102 = ______________


2) 1100 01102 = ______________
3) 0001 1100 1001 01112 = ______________
4) 0101 1111 1110 01112 = ______________
Convert the following numbers to binary.

5)1716 = ______________
6) A916 = ______________
7)7CE216 = ______________
8)FF8016 = ______________

9) This question involves creating an assembly program. In the debug window, type the
following:

a 2000
movbl, _____ (answer from question #1)
mov cl, _____ (answer from question #2)
add bl,cl

Press enter twice to finish the program and return to the - prompt.

Program Detailed Operation

- The first line, a 2000, begins an assembly program at memory location 2000
- The second line, movbl, ___, moves the value from question #1 into the bl
register.
- The third line, mov cl, ___, moves the value from question #2 into the cl
register.
- The last line, add bl, cl, adds the contents of the cl and bl registers and stores
the result in the bl register.

To execute the program, the instruction pointer register must contain the starting address
of the program we just wrote. This is accomplished using the Register command and
specifying the IP register (e.g. R IP). This will allow the value to be changed. Change
the value to 2000 (where we assembled our program).

Example:

-r ip
IP 0100:2000<ENTER>
-
After setting the IP register to the start of the program, the program can now be executed.
To see the program execute step by step, the Trace command should be used (T). This
command will execute the current instruction in the program and move the location of the
next instruction into the IP register. The trace instruction will also display all of the
register values after the current assembly program instruction has completed. Verify at
each step that these values are correct. Heres what the first trace output should look like
(read follow-up note after the picture):

What we expected to happen at address 200016 was the mov bl,A2 command to be
executed. Look at the value stored in the BX register output from the trace command. We
now have an A2, there so it looked like the command worked. Interestingly, our
command was not mov bx,A2, but was mov bl,A2. The l in bl stands for LOW,
which is the lower byte (i.e. two hexadecimal digits) of the BX register.

After running through the entire program, what value is stored in the BX register after the
third time that the trace command has been executed? Is this the value that was
expected? Explain.

Run the program again with the values: bl = -2610 and cl = 1910. What is the result in the
BX register after the add instruction? What does this process tell you about how negative
numbers are handled? Verify your answer by hand. HINT: Convert numbers to 2s
complement and then to hex. The sum given back to you will be in hex which then must
be converted to 2s complement and then back to decimal.

Grading:
Weight A (90-100) B(80-89) C(70-79) D(60-69) F(<60)
Documentation and 50 Excellent Good OK organization Poorly No organization
Report organization, organization but documentation, organized,
well documented not clear that somewhat confused hand written,
and neat writer poorly put
understands the together
solution
Operation 50 Works perfectly Hardware or Software seems to Neither Nothing works
software only work but hardware hardware nor at all.
works. does not, or vice software
versa works
completely

Vous aimerez peut-être aussi