Microprocessing and Interfacing Lab 1
Microprocessing and Interfacing Lab 1
Lab Session 1
Intro to Debug & DebugX
Anubhav Elhence
2 Anubhav Elhence
DOS-BOX
• The program is configurable, allowing
the user to change various settings
such as CPU cycles, sound, graphics
and even network support. It also
supports various types of mount
points, which allows you to use files
and directories on your host system as
if they were on a virtual drive within
the DOSBox environment.
Anubhav Elhence 3
What is MASM?
MASM stands for Microsoft Macro Assembler. It is an x86 assembly
language compiler and development environment developed by Microsoft
for their operating systems. It was first released in the early 1980s for
the 8086 and 8088 processors, and later versions were released for the
286, 386, and higher processors.
The most recent version of MASM is the MASM32. It is a free and open-
source software and it supports all versions of Windows.
You will be using DEBUGX which is a program similar to DEBUG but offers full support for 32-bit
instructions and addressing. DEBUGX includes the 80x86 instructions through the Pentium instructions.
5 Anubhav Elhence
Installing DosBox and DebugX
DOSBOX
• If you have a sytem with Windows 8 and higher as an operating system - you will not have
access to the command line prompt. In this case you can use DOSBOX. Download the software
from the link below. The setup file is executable just run it - DosBox gets installed
automatically.
• https://bitsiotlab.com/mup-lab-content/
• If you have a Linux system - you can refer to this Wiki on DosBox in Ubuntu. It gives all details
on installation and usage of DosBox in Ubuntu
• https://help.ubuntu.com/community/DOSBox
MASM611
• Microsoft Assembler- Download the software from the link. Extract the files into any Folder of
your choice. The MASM executable will be in MASM611/BIN
Installing DosBox 3. Copy the MASM611 folder directly in the 'D' drive (Remember
and DebugX
the drive, this will be important later)
Anubhav Elhence
How to start DebugX?
Once you have all the software installed, this is the procedure
you’ll need to follow to start DebugX. In short, we need to
mount the drive where the MASM611 folder is stored (D
Drive here). You will have to do this many times, please note it
down:-
Anubhav Elhence 10
List of DebugX commands
Command Syntax Description
Register
A <segment>:<offset> Assemble- Prompts the code segment to write instructions (assembled into machine code)
U <offset> Unassemble- Displays the Symbolic code (instructions) written at the offset (from CS)
G <address of last instruction> Go- Executes commands all at once, until the address specificed (Change IP Value using R first!)
Data
Misc.
12 Anubhav Elhence
Now let’s view where the instructions got stored in memory
13 Anubhav Elhence
executing MOV AX,0001H
14 Anubhav Elhence
Another follow along example:
Now let’s try to see the contents of random memory locations
15 Anubhav Elhence
This is the BYTE equivalent code of our ALP
Isn’t this amazing to note that the instructions also lie in the same segment as our data
does and can be read/copied/executed/etc. Now let’s store 0xDEAD at memory location
DS:155h
16 Anubhav Elhence
let’s store 0xDEAD at memory location DS:155h
17 Anubhav Elhence
Finally, let’s copy the content of memory location DS:0155h to CX register
18 Anubhav Elhence
Ten Offences against the MASM Compiler
If you commit any of these ten offences, no matter how well you have coded in the past,
immediately, your program will behave abnormally.... Until you rectify your mistake and
say sorry to the compiler.
1st offence:
Thou shalt never attempt to manually change the contents of segments using debugX or
fiddle with the data segment where the instructions are written.
19 Anubhav Elhence
DebugX commands
A: Assemble
The Assemble command (A) is used to enter assembly mode. In assembly mode, DEBUG prompts
for each assembly language statement and converts the statement into machine code that is
then stored in memory. The optional start address specifies the address at which to assemble the
first instruction. The default start address is 100h. A blank line entered at the prompt causes
DEBUG to exit assembly mode.
Syntax: A [address]
D: Dump
The Dump command (D), when used without a parameter, causes DEBUG to display the contents
of the 128-byte block of memory starting at CS:IP if a target program is loaded, or starting at
CS:100h if no target program is loaded. The optional range parameter can be used to specify a
starting address, or a starting and ending address, or a starting address and a length. Subsequent
Dump commands without a parameter cause DEBUG to display the contents of the 128-byte block
of memory following the block displayed by the previous Dump command.
Syntax: D [range]
R: Register
The Register command (R), when used without a parameter, causes DEBUG to display the
contents of the target program's CPU registers. The optional register parameter will cause
DEBUG to display the contents of the register and prompt for a new value.
Syntax: R [register]
Syntax: R [register] [value]
20 Anubhav Elhence
DebugX commands
T: Trace
• The Trace command (T), when used without a parameter, causes DEBUG to
execute the instruction at CS:IP. Before the instruction is executed, the
contents of the register variables are copied to the actual CPU registers. After
the instruction has executed, and updated the actual CPU registers (including
IP), the contents of the actual CPU registers are copied back to the register
variables and the contents of these variables are displayed. The optional
address parameter can be used to specify the starting address. The optional
count parameter can be used to specify the number of instructions to
execute. To differentiate the address parameter from the count parameter, the
address parameter must be preceded with an "=". Note that the first byte at
the specified address must be the start of a valid instruction.
Syntax: T [=address] [number]
21 Anubhav Elhence
Tasks to be completed
1. Using three addressing modes (Immediate, Register, Register-Indirect), write instructions to
• Move the value 1133 into the register AX.
• Swap the lower and higher bytes in AX and move them into BX (If AX is pqrs, BX should be rspq)
• Move the value in BX to the memory location at an offset of 20 (from BX)
Note down the machine code equivalents of the four MOV statements.
(Hint: You need to use the following commands- A to write the instructions, and U to view the machine code
and unassembled instructions, T to execute and D to view the memory location)
2. Move the first letter of your name (ASCII Character) to the location DS:0120
(Hint: Recall the rules for the Immediate addressing mode)
3. Fill 32 (decimal) bytes of the Extra Segment with ASCII characters for the first two letters of your name. (Like
“ABABAB…”)
(Hint: Use the F (Fill) command to fill a memory region with a byte pattern
To fill for example the first 8000h bytes of current data segment with pattern 55:
F 0 L 8000 55
[Syntax: F <start-address> L <range> <pattern>])
22 Anubhav Elhence
Thank You