Lab 3: Debug, Assembly and Memory Addressing .
I only need a 3 to 4 lines conclusion for the lab report attached.
Lab 3
Debug, Assembly and Memory Addressing
Purpose
The purpose of this experiment is to show you how instructions are assembled and dis-
assembled in Debug and to introduce the basic Intel addressing schemes.
Procedure I: Program Assembly with Debug
The computer only understands instructions written in binary that are often written in hex
so they are easier for human interpretation. Even this is very difficult however so
mnemonics are employed to represent the instructions. An “assembler” is a program that
converts these mnemonic instructions into their proper binary format. Debug has a basic
assembler that we will use to study the microprocessor instruction set. A dis-assembler is
a program that reverses this, i.e. converts binary numbers into mnemonics.
Objective: The objective of this procedure is for you to learn how to assemble and dis-
assemble commands function in Debug.
In order to meet this objective we need an instruction to assemble. For this we will use
the instruction that moves data from a source to a destination. The source and destination
can be registers or memory locations (offsets from the data segment). The mnemonic is:
MOV destination, source
A. Start MSDOS and Debug. What is the code segment, CS = 073E? (hint: use -R)
What is IP = 0 100. By default all programs in Debug are entered from offset 0100h in the
code segment so if the IP is not 0100h change it using -R IP.
B. Instructions are entered into Debug using the Assemble (A) command. Instructions
will be entered from 0100h of the CS if no argument is given, i.e., -A. Otherwise
instructions are entered from the offset given, i.e., -A 200 would start entering instruction
at offset 0200h of the CS.
1. Enter -A to start the assembler.
2. Note that the code segment and offset are given first
3. Now Debug is waiting for you to enter instructions
4. Type in: MOV AX, 1234 and then hit enter.
NOTE: Debug only recognizes numbers entered in hex so “H” is not used. This enters an
instruction that, when executed, moves immediate the hex number 1234h into AX.
5. Now type in: MOV BH, AL and hit enter.
This instruction moves the low byte of AL into the high byte of BH.
6. Hit enter again, with no instruction typed to exit from the Assemble command.
You should see something like the following on your screen:
1
-a
158E:0100 mov ax, 1234
158E: 0103 mov bh, al
158E:0105
Notice that Debug keeps track of how many bytes are required for each instruction. The
first instruction required three bytes so the next instruction was entered at offset 0103h.
You can see that the MOV BH, AL takes two bytes since the next entry is to be at 105h.
The entry is not case sensitive.
7. We can now see what the hex machine code of these instructions is by using
the dump (-D CS:0100) command. Use this to determine the machine code of:
MOV AX,1234: 38 34 12
MOV BH,AL: 88 C7
Question: What do you notice about the way 1234h is stored in memory?
C. Another way to examine memory when instructions are involved is to use the
Unassemble (U) command. This command starts a dis-assembler that will attempt to
form instructions from the contents of memory. If the memory is just left over data then
the instructions will be nonsense. If it is instructions we know to be valid then it will be
meaningful. To see how this works:
1. Enter -U CS:100
This will unassemble the hex numbers in memory locations starting at CS:100. Your
output will look something like:
-u C5:0100
158E: 0100 B83412
MOV
AX, 1234
158E:0103 8807
MOV BH, AL
158E:0105 0000
ADD BX+SI], AL
158E:0107 E85FOB
CALL 0069
158E:010A 8B7E02
MOV DI, [BP+02]
158E:010D 803000
CMP BYTE PTR [DI],00
158E: 0110 7515
INZ 0127
158E: 0112 BAFC7E
MOV DX, 7EFC
158E: 0115 BOJA
MOV AL, 3A
158E: 0117 3845FE
CMP [DÍ-02], AL
158E: 011A 7599
INZ 00B5
158E: 011c 3400
XOR AL,00
158E: 011E 7015
IGE 0135
Notice that the instructions we entered with -A are there. The rest of the “instructions”
are actually nonsense attempts by the unassembler to turn arbitrary hex numbers into
instructions. Notice that the unassembler also gives you the machine code of the
instructions, so that MOV BH,AL is 88C7h.
2
Procedure II: Single-Step Instruction Execution
When a program is executed we expect all instructions to be executed until the program
ends. For our study of the instruction set however we often want to execute just one
instruction to see what it does. This is provided for in Debug by the Trace (T) command,
Objective: In this procedure you will learn how to execute one instruction at a time and
be able to observe the consequences of that execution.
A. The Trace (-T) command executes the instruction located in the CS at the present
value of the IP. It is possible to override the IP by entering an offset after the T, but it
must be done with an equal sign!! Thus, -T =200 will execute the instruction located at
CS:0200. BE CAREFUL! If there is not valid instruction code at the location the
machine may “hang-up” trying to execute nonsense instructions. If you enter a number
after the T without an equal sign it means that many instructions should be executed
before stopping, i.e., not just one instruction.
1. Use -R to examine the registers. Verify that IP = 0100h. If not, use -R IP to
set it to 0100h and use -R again to verify. Note that -R shows the instruction pointed to
by the IP after the register contents are displayed. Record the registers:
AX=0000 BX= 0000
2. Now use-T to execute the first instruction. Note that Debug automatically
displays the registers, flags and the next instruction. What is IP? 2100. You can see
that it is automatically pointing to the next instruction. What is AX = 12314?
3. Use-T again and the next instruction is executed. What is BX = 3520?
Did AL get moved to BH? What happened to BL?
Procedure III Addressing Modes
There are many ways that the destination and source of an instruction can be specified.
We present just a few of them here.
Objective: To learn and use several of the addressing modes possible with the Intel
microprocessor family: register-register, immediate, direct, register indirect, base plus
index, register indirect relative.
A. Register-register: this addressing was used above to move between A and B. This
can be done 8-bit, 16-bit or 32-bit and any pair of registers.
B. Immediate: This was done above to move 16-bit data into AX. You can also do 8-bit
immediate.
C. Direct: This means direct addressing of memory using its offset from the data
segment. The offset is entered with square brackets, [ ], to distinguish from immediate.
1. Use the assembler to add a new instruction after those entered above. You will
recall that the next instruction was to be entered at CS:105. So enter -A CS:105
Then enter the instructions: MOV [200], BH
MOV [300], AX
MOV DL,[300]
3
The first instruction moves the 8-bit contents of AL into memory location DS:200 and the
second moves 16-bits from AX into memory location DS:300. The third instruction
moves a byte from 0300h into DL.
2. Use –D to determine the contents of memory offsets 0200h, 0300h, 0301h and
record in the table below.
3. Use-T (trace) to single step through the three instructions. DL= 34
4. Use -D to determine and record the new contents of memory for the table.
Offset
0200h
0300h
0301h
Content
Before
bo
oo
02
Content
After
34
34
12
D. Register Indirect: In this case a register (BP, BX, DI or SI) holds the offset of a
memory location to be used in the instruction. We use square brackets [ ] to tell the
assembler it is register indirect addressing. NOTE: 80386 and above can use any register.
1. After the last instruction above add:
MOV [03F2], AX
;store the contents of AX into DS:03F2h
MOV SI, 03F2
;this immediate loads SI with 03F2h
MOV BX, [SI]
;Here is the register indirect movement
So these instructions essentially move AX into BX through memory location 03F2h and
03F3h (because is a 16-bit move) using register indirect addressing.
2. Fill out the initial values in the table below (before execution of the
instructions)
3. Single step through these instructions.
4. Fill out the table with values after execution and confirm that the transfer
occurred.
Offset/ Content Content
Register Before After
03F2h 00 34
03F3h oo 12
AX 123411234
BX 3400 1234
SI
0000
03 F2
E. Register Indirect Relative: In this case we have a numeric shift of the memory
location from that contained in a register.
1. Add the following instructions following those above:
MOV DI,0400
;We load immediate DI with 0400h
MOV DH,[DI+6]
;Now we move a byte from memory
;location formed as the contents of DI plus
;6h = 0406h
2. Use -D to determine the contents of DS:0406h = 073E.
3. Single step through these instructions then record: DH= 20.
Confirm that the movement occurred.
4
F. Base plus Index: In this case the offset is determined as the sum of the contents of
two registers. BP or BX plus DI or SI. (In the 80386 and above any registers can be
used)
1. Add the following instructions to those entered above:
MOV AX,FFFF
;load some data into AX
a 120
MOV BP,0100
; Load the base pointer, BP
MOV SI,0200
; Load an index register, SI
MOV [BP+SI),AX ; move contents of AX into memory pointed
;to by the BP + SI.
2. What is the offset into which AX will be moved? 0300_ What is the memory
content now: 00 oo
3. Single step through these instructions observing register content changes.
4. Use -D to examine memory and confirm that AX was moved into that location.
New content: 34 12
G. Use -U 100 to observe all the instructions you have entered. You may hit -U again
to view another set of instructions.
4 나
time
-UTO
UID
What is the offset of the last of your instructions? 0129