Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

first asm program help

Status
Not open for further replies.

CppMaster

Programmer
Apr 19, 2006
12
CA
I started a book on assembly, but it's a bit old and I wasn't able to assemble the fist program :s. Here's the code:
Code:
.MODEL  SMALL
.STACK  64
.DATA
    DATA1    DB    52H
    DATA2    DB    29H
    SUM     DB      ?
.CODE
MAIN    PROC    FAR
           MOV        AL,DATA
           MOV        DS,AL
           MOV        AL,DATA1
           MOV        BL,DATA2   
           ADD        AL,BL
           MOV        SUM,AL
           MOV        AH,4CH
           INT         21H
MAIN    ENDP
           END    MAIN
What changes would need to be made for this program to work? Thank you.
 
I'm on Windows and I tried doing compiling with MASM32.
 
That code looks very much like 16 bit dos assembler to me.

I'd bet that MASM32 wouldn't like it much, as you've found out.

If you have a look through some of the threads in this forum, you'll see that various free assemblers are recommended that will cope very nicely with dos type programming.

A86 is one that springs to mind.

And there's one called NASM that gets recommended too.

Some of these assemblers might need to be run from as dos prompt or command prompt.

You'll also need a debugger to execute the code: debug is still supplied with Windoze but there are better debuggers available... :eek:) like D86.

 
Thanks, I'll look for NASM for 16-bit code. But I'd still like to know how I'd write it in win32 (I read an ebook by Dr. Paul Carter on win32 ASM, but he mixes it with C to make the actual program). Thank you very much.
 
There is a bit of a problem if your writing code
for win32.
The segment registers can't be changed the way as in 16 bit
or real code assembly.
The segment registers under win32 hold segment selectors and not real segment values.
The selectors are read from a Global Discripter Table.
So if you don't use DS ES FS gs or SS derecty you can run
the code with win32.

Succes, Tessa
 
Don't misunderstand the statement:
"So if you don't use DS ES FS gs or SS derecty you can run the code with win32". If you use an assembler that thinks it's writing 32-bit code, the product won't run in a 16-bit environment. There are all sorts of differences beyond the (very true) difference in segment registers. For instance, if the processor thinks it's in 32-bit mode then every reference to ax will involve a segment size override prefix byte that the assembler must put in. If it's in 16 bit mode there won't be an override prefix for ax, but there would be for eax. The assembler and the processor need to be in agreement about this!

You don't need debug to run your program assuming you have an assembler that comes with some sort of linker and can therefore create a .exe (or .com) file. I can't speak for nasm or a86 being a tasm person, which comes with tlink. tasm produces the object file (.obj) and tlink turns it into an exe.




 
Would it be possible for you to write me a skeleton that I could use to write 32 bit programs? Thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top