Dear students,
Hopefully you have tinkered with DEBUG to understand the following:
1. Different registers in a CPU and the roles they play
2. Memory map
3. Working of the INT instructions
4. The working of DEBUG to trace, process, assemble instructions one by one, dump memory etc. DEBUG itself uses INT 01 to run in single step trace mode.
A small note: The number 10 in mov ax,10 is an immediate operand. How to specify a memory location in DEBUG? Use [10]. This actually means DS:10..
However, writing mov ax,[10] will give an error. Why?
Because DEBUG wont understand whether u wanted to move a byte or a word or a double word. You have to specify that using PTR: byte ptr, word ptr, etc
try this
mov word ptr [10], 4 // move the word 4 (2 memory locations) to DS:10
mov ax, word ptr [10] //move the same to AX
But debug has a huge drawback: it does not allow symbols instead of addresses and it assembles instructions only one by one, not in a file. MASM allows that.
1. It expects that all instructions to be assembled are in a file or even several files. So you have to use a proper editor such as EDIT to create the file.
2. It expects that stack segment, data segment and code segment are specified separately
3. It allows you to use symbols instead of addresses
4. An .OBJ file is created with the MASM cmd and then the .EXE file is created with the LINK cmd.
5. It gives you the facility of several directives that help you create neat programs. Ofcourse you can add comments to made readable programs.
Let begin with one.
TITLE My trial masm program --Two dashes means comment. TITLE is a directive
.model small --a command beginning with dot is a DOT command: basically shortcuts to a set of commands.
-----------.model is a dot command. Other MASM models are large, huge etc. This is a small program-----------
.stack 64 ---You are declaring 64 bytes stack segment.
.data ---Data segment begins. Note the use of symbols
operand1 DW 165
operand2 DW 200
result DW ??
------------End of data segment----------------Code segment begins next with another DOT cmd
.code
main PROC FAR ------The main program is a procedure PROC that uses FAR addresses (means large offsets can be used for jumps).------------
------------------Both PROC and FAR are directives----------------
----The two instructions below move the address of the data segment to DS. You cant mov to DS directly. It has to move through AX. -------------
mov AX, @data
mov DS, AX
----------------Now the actual logic of the program starts---------------------
mov ax, operand1
add ax, operand2
mov result, ax
------------Now end the program neatly with INT -------------------
mov ax, 4c00H --Note in debug numbers were hex. Here you have to specify H because default is decimal
int 21H
----------Now the program ---------------
main endp
end main
Start experimenting........
1. Create the file using edit naming it say coe.asm. It has to end with .asm
2. masm coe. I
3. link coe
4. debug coe.exe . You have to specify exe
5. start r t .....p (for int instructions)
--
____________________________
Dr Shampa Chakraverty
Professor & Head, Deptt. of Computer Engineering
Netaji Subhas Institute of Technology
Dwarka, Sector 3, New Delhi-110078
Phone: 91-011-25099062(O)
09899568694 (M)