News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

DOS code is not dead

Started by Echo, March 06, 2010, 06:57:06 PM

Previous topic - Next topic

Echo

Not sure what I'm looking for here, well to learn.  I'm having fun so it's all good.  

I'm going through "Peter Norton's Assembly Language Book for the IBMPC" book, trying to write and assemble his program samples.  The book was published in 1986, back when DOS was king.  The first 80 pages deal with using DEBUG and building and running programs. Lots of fun.  Now the book is moving onto using an editor and of course the samples are based on 8088 processors and uses a prehistoric MASM.  
I've managed to build and run a couple of the code samples.
The first one was (this is the entire code)

CODE_SEG   SEGMENT
   MOV   AH,2h
   MOV   DL,2Ah
   INT   21h
   INT   20h
CODE_SEG   ENDS
   END

Normal you would assemble it using MASM, then link, then EXE2BIN.  As you might expect I ran into immediate trouble when I tried to assemble it with the MASM that comes with MASM32 project.  I know right off I'm having problems with memory model. A little Google and searching this site, I rewrite the code

.MODEL SMALL
.DATA
.CODE

start:
   MOV     AH,02h
   MOV     DL,02Ah
   INT     21h
   INT     20h
END start

The Assembler likes it. Now it's time to link.  No go, a little more Google and site search I discover I need a 16bit linker.  Because of the great user base on this site I find a link to a linker.  Yea!, the program links fine.  Next is converting from EXE to a COM.  Expecting trouble, I get none, it converts just fine. I get a great little 8 byte program that prints an * in a console window.

I move on to a new code sample.

CODE_SEG   SEGMENT
   ASSUME  CS:CODE_SEG
   MOV     AH, 01H
   INT      021h
   INT      21h
   MOV     DL,AL
   SUB      DL,30h
   CMP     DL,09H
   JLE      DIGIT1
   SUB     DL, 07h

DIGIT1:
   MOV    CL,04h
   SHL     DL,CL
   INT     21h
   SUB    AL,30h
   CMP    AL,9h
   JLE     DIGIT2
   SUB    AL,07h

DIGIT2:
   ADD     DL,AL
   INT     20h

CODE_SEG    ENDS
   END


I do like I did on the previous sample I remove the CODE_SEG (knowing in the end this Memory Segment stuff is going to bite me the butt again and again) then add .model, .code, START etc.  It won't assemble; I think the problems with the procedure calls.

Ok, I've presented this as a way for me to get involved on this forum (even if it's only as a taker/learner). If you would like to play I want to end up with a .com file.

echo
:bdg :bdg :bdg

MichaelW

Using ML 6.14 and the available 16-bit linker this code:

CODE_SEG SEGMENT
MOV AH,2h
MOV DL,2Ah
INT 21h
INT 20h
CODE_SEG ENDS
END


Assembled and linked with these command lines (EXE2BIN is not needed for the later 16-bit linkers):

ML /c test.asm
LINK16 /TINY test.obj;


Produces an 8-byte .COM program that runs OK. The linker does issue two warnings:

LINK : warning L4045: name of output file is 'test.com'
LINK : warning L4055: start address not equal to 0x100 for /TINY


But in this case they are of no consequence. The first warning can be avoided by specifying the name of the output file on the linker command line:

LINK16 /TINY test.obj, test.com;

The second can be avoided by specifying the starting address, with or without the ORG 100h:

CODE_SEG   SEGMENT
  ORG 100h
  START:   
    MOV   AH,2h
    MOV   DL,2Ah
    INT   21h
    INT   20h
CODE_SEG   ENDS
   END START

eschew obfuscation