masm

47 views
Skip to first unread message

Shampa Chakraverty

unread,
Sep 2, 2012, 2:06:59 AM9/2/12
to coe2ns...@googlegroups.com
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)

Prerit Kohli

unread,
Sep 23, 2012, 2:15:59 PM9/23/12
to coe2ns...@googlegroups.com
Hello ma'am,
I am facing with the following problems in masm:
When I create my file (coe.asm) using EDIT command and save it with extension  .asm and then:

1- by using masm -> it asks the source file name (where i am writing coe.asm) then the object file name. etc. and  finely it returns "can not be open."

2- If i use masm coe-> it directly jumps to obj file thing. and the same thing repeats.

3-if i use masm coe. l -> i can see some list thing. But again i am not able to open.

Individually, link coe, debug coe.exe.. are working but in sequence it is showing error.fatal errors(i guess it means linking :|)

It also asks library when i use link command. (don't know what it means.any why here there is any need of library in linking?). 
I am getting some results if i directly use debug command.

Reply all
Reply to author
Forward
0 new messages