EXPERIMENT 1. FAMILIARITY WITH DEBUG, x86 REGISTERS and MACHINE INSTRUCTIONS

Similar documents
Name (10) # Student. Student. 2017, Microprocessors 1 / 11

LABORATORY 1: EXPLORING THE SOFTWARE ARCHITECTURE OF THE MICROPROCESSOR

VARDHAMAN COLLEGE OF ENGINEERING (AUTONOMOUS) Shamshabad, Hyderabad

Intel Architecture Segment:Offset Memory Addressing

E CpE185 Laboratory Fall Introduction to Debug

Experiment N o 1. 1 Introduction to Assembly Language Programming

Lab 10 CST8214 Ian! D. Allen Fall 2007

We can study computer architectures by starting with the basic building blocks. Adders, decoders, multiplexors, flip-flops, registers,...

Tutorial Letter 103/3/2012 Computer Organization COS2621 Semesters 1 & 2

COE 205: Computer Organization & Assembly Language Introductory Experiment-B By Louai Al-Awami

Chapter Three Addressing Mode MOV AX, BX

1. Introduction to Assembly Language

FACULTY OF ENGINEERING LAB SHEET

EXPERIMENT WRITE UP. LEARNING OBJECTIVES: 1. Get hands on experience with Assembly Language Programming 2. Write and debug programs in TASM/MASM

Computer Organization and Assembly Language. Lab Session 01

Computer Architecture 1 ح 303

Microprocessor and Assembly Language Week-5. System Programming, BCS 6th, IBMS (2017)

Microcomputer Architecture..Second Year (Sem.2).Lecture(2) مدرس المادة : م. سندس العزاوي... قسم / الحاسبات

Code segment Stack segment

16-Bit Intel Processor Architecture

ORG ; TWO. Assembly Language Programming

Assembling, Linking and Executing 1) Assembling: .obj obj .obj.lst .crf Assembler Types: a) One pass assembler:

Experiment 3 3 Basic Input Output

Intel 8086 MICROPROCESSOR ARCHITECTURE

FACULTY OF ENGINEERING LAB SHEET

Intel 8086: Instruction Set

EEM336 Microprocessors I. Data Movement Instructions

CS401 Assembly Language Solved MCQS From Midterm Papers

Marking Scheme. Examination Paper Department of CE. Module: Microprocessors (630313)

Intel 8086 MICROPROCESSOR. By Y V S Murthy

Microprocessors & Assembly Language Lab 1 (Introduction to 8086 Programming)

INTRODUCTION. NOTE Some symbols used in this manual CL = Click Left CR = Click Right DCL = Double Click Left = Enter. Page 1

CS401 - Computer Architecture and Assembly Language Programming Glossary By

Philadelphia University Student Name: Student Number:

Computer Organization and Assembly Language CSC-210

Chapter 2 COMPUTER SYSTEM HARDWARE

The x86 Microprocessors. Introduction. The 80x86 Microprocessors. 1.1 Assembly Language

Lab 2: Introduction to Assembly Language Programming

CS1110 Lab 1 (Jan 27-28, 2015)

Lesson 1. Fundamentals of assembly language

ADVANCE MICROPROCESSOR & INTERFACING

Transfer of Control. Lecture 10 JMP. JMP Formats. Jump Loop Homework 3 Outputting prompts Reading single characters

Microprocessor I, Spring 2007 Lab 2: Assembling and executing instructions with DEBUG software Due on 03/02/2007, 12:30pm EST

Computer Architecture and System Software Lecture 07: Assembly Language Programming

Introduction to Microprocessor

Experiment N o 1. Introduction to Assembly Language Programming

Chapter 4: Data Movement Instructions. 4 1 MOV Revisited

8088/8086 Programming Integer Instructions and Computations

Program controlled semiconductor device (IC) which fetches (from memory), decodes and executes instructions.

EC-333 Microprocessor and Interfacing Techniques

ECOM 2325 Computer Organization and Assembly Language. Instructor: Ruba A.Salamah INTRODUCTION

Experiment #5. Using BIOS Services and DOS functions Part 1: Text-based Graphics

SRI VENKATESWARA COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF ECE EC6504 MICROPROCESSOR AND MICROCONTROLLER (REGULATION 2013)

MICROPROCESSOR TECHNOLOGY

MODE (mod) FIELD CODES. mod MEMORY MODE: 8-BIT DISPLACEMENT MEMORY MODE: 16- OR 32- BIT DISPLACEMENT REGISTER MODE

Lecture 5:8086 Outline: 1. introduction 2. execution unit 3. bus interface unit

Assembly Language Lab # 9

Assembly Language. Dr. Esam Al_Qaralleh CE Department Princess Sumaya University for Technology. Overview of Assembly Language

Internal architecture of 8086

9/25/ Software & Hardware Architecture

Computer Architecture and System Software Lecture 04: Floating Points & Intro to Assembly

CG2007 Microprocessor systems.

Experiment 3. TITLE Optional: Write here the Title of your program.model SMALL This directive defines the memory model used in the program.

Ex : Write an ALP to evaluate x(y + z) where x = 10H, y = 20H and z = 30H and store the result in a memory location 54000H.

Microprocessor. By Mrs. R.P.Chaudhari Mrs.P.S.Patil

Microprocessors (A) DOS Services

CS 31: Intro to Systems ISAs and Assembly. Martin Gagné Swarthmore College February 7, 2017

CC411: Introduction To Microprocessors

Basic characteristics & features of 8086 Microprocessor Dr. M. Hebaishy

Topics. Hardware and Software. Introduction. Main Memory. The CPU 9/21/2014. Introduction to Computers and Programming

LAB 3: Programming in Assembly Language

LABORATORY 8: USING BIOS ROUTINES FOR KEYBOARD INPUT AND DISPLAY OUTPUT

Assembly Language Each statement in an assembly language program consists of four parts or fields.

ALT-Assembly Language Tutorial

8086 INTERNAL ARCHITECTURE

Chapter 3: Addressing Modes

EE2007 Microprocessor systems.

SECTION 3 ASSEMBLY LANGUAGE PROGRAMMING

Q1: Multiple choice / 20 Q2: Memory addressing / 40 Q3: Assembly language / 40 TOTAL SCORE / 100

EC-333 Microprocessor and Interfacing Techniques

LAB WORK NO. 3 TURBO DEBUGGER ENVIRONMENT

Computer Principles and Components 1

x86 and C refresher Lab

1. Open VirtualBox and start your linux VM. Boot the machine and log in with the user account you created in Lab #1. Open the Terminal application.

Marking Scheme. Examination Paper. Module: Microprocessors (630313)

if 2 16bit operands multiplied the result will be

Computer Organization & Assembly Language Programming. CSE 2312 Lecture 15 Addressing and Subroutine

Arithmetic Instructions

SPRING TERM BM 310E MICROPROCESSORS LABORATORY PRELIMINARY STUDY

Assembly Language: g Part III. First Semester 2013 Department of Computer Science Faculty of Science Chiang Mai University

Advanced Batch Files. Ch 11 1

Week /8086 Microprocessor Programming I

ECpE 185 Laboratory Hand Assembly Fall 2006

Logic Instructions. Basic Logic Instructions (AND, OR, XOR, TEST, NOT, NEG) Shift and Rotate instructions (SHL, SAL, SHR, SAR) Segment 4A

EXPERIMENT NINE DEVELOPING MACRO SEQUENCES

reply db y prompt db Enter your favourite colour:, 0 colour db 80 dup(?) i db 20 k db? num dw 4000 large dd 50000

Number Systems. The Computer Works in Binary, or how I learned to think like a computer. The computer s natural number system is binary not decimal.

Ex: Write a piece of code that transfers a block of 256 bytes stored at locations starting at 34000H to locations starting at 36000H. Ans.

16.317: Microprocessor Systems Design I Spring 2014

Basic Assembly SYSC-3006

Transcription:

EXPERIMENT 1 FAMILIARITY WITH DEBUG, x86 REGISTERS and MACHINE INSTRUCTIONS Pre-lab: This lab introduces you to a software tool known as DEBUG. Before the lab session, read the first two sections of chapter 4 in the Uffenbeck textbook for an introduction to the X86 registers and a discussion of DEBUG. Appendix B in the Irvine textbook has a tutorial on DEBUG with a description of all of the commands. If you are unfamiliar with the DOS command line window, read Appendix A in this lab before proceeding. Appendix A also describes how to capture DOS command line windows for inclusion in your lab report. Post-lab: Answer the 4 questions in this lab and submit them with your lab report. Objective: Become familiar with the internal structure of the x86 microprocessor register set and the Microsoft DEBUG utility. DEBUG is a utility program shipped with DOS/Windows that can be used to debug programs by allowing the user to examine memory and register contents, assembling and disassembling programs, single-stepping, and a variety of other functions. Experiment: To invoke the DEBUG program, a user opens a DOS window and enters the following: (NOTE: you can also click on the start button, choose run, and enter debug from windows 95, 98 or NT). C:\> debug DEBUG responds with the hyphen, -, prompt. The hyphen prompt indicates that DEBUG is ready to accept commands in an interactive environment. One of the most important commands is? which gives a summary of all valid commands. A list of all valid DEBUG commands is given on page 155 of the class textbook. Invoke DEBUG now and list all commands: C:\> debug -? You should get a list of all commands displayed to the screen. They may all be invoked with single letters, some requiring additional arguments. Arithmetic Using DEBUG: H is the DEBUG command that returns both the sum and difference of two arguments. DEBUG computes in Hexadecimal only! From a DEBUG prompt, enter the following: -H 3 2

You should see the following appear on your screen: 0005 0001 This is the sum and difference respectively, 3+2=5 and 3-2=1. Now try: -H 2 3 In this case, the negative difference, 2-3, is represented in 2 s complement form. A negative number can always be identified by checking if the leading bit (MSB) is set to 1. However, a positive sum can also have MSB=1. It is UP TO THE PROGRAMMER to interpret the result correctly. As an example, enter the following: -H E1F6 1E09 The positive sum is also FFFF! Now try: -H 5C3F0 4BC6 The error occurs because DEBUG operates on WORDs only. For the x86 architecture, a word is 16 bits in length. Registers and Memory: The x86 (at least the 8086 version) contains 14 basic registers. To examine the content of the registers, enter the following: -r Notice the 2-letter abbreviations on the far right side of the second line. These indicate the values of the bits in the FLAGS register. To examine and change the content of a single register, the r command can be used with a register name as the argument. As an example, enter the following: -r ax ax 0000 :3A7 Now examine the registers again using the r command. You should see that register ax now contains 03A7. Load the value, 92A into the bx register using the r command. Verify that bx and ax contain the values 3A7 and 92A respectively. Instead of adding 3A7+92A using DEBUG, we will let the x86 microprocessor add them by placing machine instructions in its memory that tell it to perform addition for us. The command for examining and changing memory is e. Enter the following: -e 100 3756:0100 E4.01 -e 101 3765:0101 85.D8 You will probably have different values displayed from the 3756, E4 and 85 shown above. This is OK since these values depend on what was present in memory prior to invoking DEBUG. You should enter the 01 and D8 values at offsets 0100 and 0101. By typing e 100, you are telling DEBUG to load a byte of

data at address offset 0100 in the current code segment. In the example above, the current byte, E4, present at segmented address 3756:0100 is being replaced (overwritten) by the user-entered byte, 01. In the example above, the code segment is 3756, yours will probably be different, but it doesn t matter here. Multiplying the code segment by hexadecimal 10 and adding the offset will produce the physical address. x86 systems generally specify memory addresses in segmented form. Addition Using the x86: Examine the register content: -r The display should resemble: AX=03A7 BX=092A CX=0000 DX=0000 SP=#### BP=#### SI=#### DI=#### DS=#### ES=#### SS=#### CS=#### IP=0100 NV UP DI PL NZ NA PO NC ####:0100 01D8 ADD AX, BX Where # represents a hexadecimal digit. The last line of the display indicates that 01D8 is stored in memory. This, in fact, is the machine language representation for the ADD AX, BX instruction which causes the contents of the two registers to be added and the sum placed in the AX register. Since the x86 is a byte-addressable architecture, the data is organized as follows: 3756:0100 01 3756:0101 D8 Although the instruction is present in memory, before it can be executed the x86 must be told where the instruction is located. The method used by the x86 is to use two special registers, the CS and IP which contain the segmented address of the next instruction to be executed and hence effectively point to the instruction in memory by containing the code segment (in the CS register) and the offset (in the IP register). If necessary, use the r command to load IP with the correct offset, 0100. DEBUG has a trace instruction, t, which causes a single machine language instruction to be executed. Instruct DEBUG to execute the trace command as follows: -t The AX register should now contain 0CD1 which is the sum of 03A7 and 092A.. Notice that the original content of AX has been overwritten with the sum. Also note that the IP now contains 0102. The x86 automatically increments IP in anticipation of executing the next instruction in memory. Now use the x86 to add 092A (in BX) to the value 0CD1 (in AX). Use the r instruction in DEBUG to set IP to the proper value. To perform subtraction, it is necessary to store the machine language command for subtracting into the code segment. Do this now by using the e command to store 29D8 beginning at offset 0100 in the current code segment. Use r to verify that you have indeed stored the SUB AX, BX instruction in memory, then execute using the DEBUG trace command. Using DOS Functions from Assembler language Programs: The INT instruction allows the x86 to access special programs that are present in memory when the computer is booted and DOS has copied them from the harddisk into main memory. For now, you can think of INT as a function call.

Using DEBUG, load AX with 0200 and DX with 0041. The machine instruction for INT 21 is CD21. Put CD in memory in the code segment at offset 0102 followed by 21 in the next location. Set IP to 0102 and verify the registers and memory contain the proper values by using the r command. Next, execute the instruction by entering the following: -g 104 g is DEBUG s go until instruction. You are telling the x86 to execute all instructions from the current location in the code segment (specified by the CS:IP content) to CS:0104. If the t command were used, all instructions in the INT 21 routine would need a t to execute, that is, you would have to single-step through the entire INT 21 routine which could be lengthy. Using g allows execution to proceed until CS:0104 is reached. Note that an A was printed on your monitor. The particular INT routine actually executed was type number 21. This is the INT used to access DOS functions. The 02 in register AH (AH is most significant byte of AX) told DOS to print a character to the monitor. The actual character printed was specified by the 41 that was loaded into DL. 41 is the ASCII character code for the letter A. Exiting Programs: When an assembly (or machine language) program finished execution, the x86 must be allowed to be controlled by the operating system. One way to accomplish this is to call INT 20. When you create programs in a high-level language, such as C, the compiler automatically inserts this command at the end of the program. At this lower level of programming, it is up to you, the assembler language programmer to include INT 20 at the end of your programs. Now, write a 2-line program: INT 21 INT 20 by doing the following steps: 1. load ax with 0200 and dx with 0043 using the DEBUG r command 2. load memory with the following: CD 21 CD 20 3. set IP and CS to contain the memory address of the INT 21 instruction 4. use the DEBUG g command with a valid ending offset to execute the program Congratulations! You have just written and executed your first machine language program. Demonstrate the running of this program to the lab instructor. QUESTION 1: What was printed and why was it printed in the 2-line program above? Assemble/Disassemble: Most programs are longer than two lines. To view the mnemonics of the code (the human readable part), change the IP to the beginning of the 2-line program and enter the DEBUG unassemble command: -u

You should see your 2-line program in mnemonic form followed by the hexadecimal machine language that is stored in memory. It is much easier for humans to enter the program into the computer using mnemonics rather than hexadecimal machine codes. DEBUG provides an assemble command, a, for this purpose. As an example, the two-line program can be entered at code segment offset 0100 by entering the following: -a 100 int 21 int 20 The above commands allow you to enter the program in mnemonic form rather than hexadecimal machine codes. DEBUG Scripts: It is possible to create assembly language programs using DEBUG only (although there are some limitations that we will discuss in more detail later in the class). You can create a file containing DEBUG instructions and assembly code mnemonics and pipe it into DEBUG using the DOS redirection operator '<'. As an example, do the following exercise: 1. Create a file named TEMP.DBG on your PC. The file contents are given below. You may use any text editor or word processing program that you wish, but you must be sure to save the file as a TEXT or ASCII file! a 100 mov ah, 02 mov dl, 2a int 21 int 20 n temp.com r bx 0 r cx 08 w q Be sure to insert the blank line in your file as shown above. This signals DEBUG that you are finished entering assembly language instructions. 2. Invoke from a DOS prompt in a DOS window as follows: C:\> DEBUG < TEMP.DBG 3. Give an explanation for each of the lines contained in the TEMP.DBG file. Also give a description of the other debug commands used in this lab (a, e, g, h, r, t). You should now have an executable file named TEMP.COM on your harddisk. QUESTION 2: Run TEMP.COM, what does it do?

QUESTION 3: Give an explanation for each of the lines contained in the TEMP.DBG file. Also give a description of the other debug commands used in this lab (a, e, g, h, r, t). QUESTION 4: Describe what you learned from this experiment. Include both the good points and the areas that could use improvement. APPENDIX A: The DOS Command Window Use of a DOS command window may be unfamiliar to you. The DOS command window allows you to execute programs, change directories, create/delete directories/files, etc. via commands typed from the keyboard. This was the standard way of accomplishing these tasks before Microsoft created the Windows Graphical User Interface (GUI). Use of command line windows ( shells ) are common in other operating systems such as Linux and UNIX-variants. Expert users normally find command line interfaces more efficient at common file system tasks than a GUI. We will use the DOS command line window for running certain programs in this class. To open a DOS command line window, execute the program named Command Prompt (normally found under from the Start Programs list under Windows). You should get a window that looks something like this: The C:\" is called the command prompt and shows you the current directory ( folder ) that you are in. You can change to another folder via the cd directoryname command (cd stands for Change Directory). C:\> cd Data C:\Data> The command prompt changes to show you the current directory that you are in. You can back up one directory level by using.. for the directory name: C:\Data> cd.. C:\

You can change drives by just typing the name of the drive letter followed by a colon : : C:\Data> H: H:\ To see a list of files in the current directory, you use the dir command (directory) command. To execute a program, just type the name of the program (myfile.exe or just myfile -- you can leave off the.exe). The program either needs to be in the current directory or found in the list of directories specified in the PATH environment variable. If DOS says that it cannot find the program, then type in the complete path to the program such as c:\data > C:\data\mydir\myfile.exe. To add directories to the PATH environment variable, you can do the following: C:\ set path=%path%;c:\data\mydir To see the list of the directories on the path variable just type path after the prompt and the value of the path environment variable will be displayed. You should not have to change the path variable on the PCs in the Micro I labs; all of the programs that we will use are in directories that are included on the path variable. However, you may have to change the path variable on your local PC. We will not be using the DOS command prompt to create/delete directories -- you can do this via the normal Windows interface. However, if you want to access that directory from a DOS command window, you should keep your directory names to 8 characters or less and do not put space characters in the directory name. If you want to find out more about the commands available from the DOS command line, type HELP. You can also find many DOS tutorials on the WWW. The Micro I lab PCs are set up such that when you log in, the H: drive is your home directory that is available from your ECE Unix account. You will need to log into the Micro I PCs using your ECE username/password. You should always use the H: drive for any files that you create in this class. Occasionally, you may want to capture a DOS command window for inclusion in your lab report. One way to do this is hit ALT+PRINTSCREEN (hold down ALT and hit the print screen button) while you are in the DOS command window. This saves the current window to the clipboard as a picture object. You can now open the Paint program (under Start Programs Accessories) and use the Edit Paste command to paste the window on the current image. Then use the File Save As command to save the image to file (use the 256 color bitmap format to reduce the file size of the image). When you are preparing your lab report, you can paste this image into your lab report.