1

I am just following the book from my university to run this simple code I found as an example for my coding practice. I am new to assembly language.

The problem is that I only know how to assemble in TASM with tasm <filename> tlink /t <filename>, then running the .COM file, based on the teachings of my professor. I would just like to know where I can assemble this code and make it work.

When assembling on DOSBox, TASM would generate an error of:

Cannot generate COM file: stack segment present

or what can I change in my code to assemble it with TASM and generate the .COM file?

TITLE MYPROG.ASM
DOSSEG
.MODEL SMALL
.STACK 0100h
.DATA
    NEYM    DB 08h, ?, 08h DUP ("$")
    Q       DB "What is your name? $"
    A1      DB 0Ah, 0Dh, "What a nice name! $"
    A2      DB 0Ah, 0Dh, "I'm glad to meet you! $"

.CODE
start:
    MOV AX, @DATA
    MOV DS, AX
    
    MOV AH, 09h
    MOV DX, OFFSET Q
    INT 21H
    
    MOV AH, 0Ah
    MOV DX, OFFSET NEYM
    INT 21H
    
    MOV AH, 09H
    MOV DX, OFFSET A1
    INT 21H
    
    MOV DX, OFFSET NEYM+2
    INT 21
    
    MOV DX, OFFSET A2
    INT 21H
    
    MOV AX, 4C00H
    INT 21H
END start
    

I tried following this:

How to fix "error:cannot generate COM file, stack segment present"?

  • removing the stack segment
  • writing the org 100h
  • replacing SMALL with TINY

and it gave me an error:

Cannot generate COM file: segment-relocatable items present

1
  • 1
    In a .com, you also need to remove MOV AX, @DATA / MOV DS, AX. A .com starts with segments already set up for the "tiny" model, all the same. The source you have is for a .exe. Commented May 15 at 14:23

1 Answer 1

2

The problem is that I only know how to assemble in TASM ...

I would just like to know where can I assemble this code and make it work.

It is always a good thing to know about more than one tool. IMO an assembler like FASM makes for an excellent choice for any novice programmer. It is a modern tool that is still kept up-to-date by its author. Moreover you don't need a separate linker.

Look at the below examples that represent your program, and admire the simplicity of it all!

EXE program using FASM

Segments can be specified in any order. Both DS and ES start out pointing at the PSP, so you must manually make DS and/or ES point at the DATA segment(s). The stack has the size that you mention explicitly with stack 256.

format MZ
entry main:start
stack 256

segment text
 NEYM   DB 08h, ?, 08h DUP ("$")
 Q      DB "What is your name? $"
 A1     DB 0Ah, 0Dh, "What a nice name! $"
 A2     DB 0Ah, 0Dh, "I'm glad to meet you! $"

segment main
 start: MOV AX, text
        MOV DS, AX
        
        MOV AH, 09h
        MOV DX, Q
        INT 21H
        
        MOV AH, 0Ah
        MOV DX, NEYM
        INT 21H
        
        MOV AH, 09H
        MOV DX, A1
        INT 21H
        
        MOV DX, NEYM+2
        INT 21h
        
        MOV DX, A2
        INT 21H
        
        MOV AX, 4C00H
        INT 21H

COM program using FASM

Here you put the DATA below the CODE. All the segments start equal to each other, and the stack occupies the high region on the 64KB unique segment. The ORG 256 is the only mention that you need to obtain a .COM executable.

        ORG 256

        MOV AH, 09h
        MOV DX, Q
        INT 21H
        
        MOV AH, 0Ah
        MOV DX, NEYM
        INT 21H
        
        MOV AH, 09H
        MOV DX, A1
        INT 21H
        
        MOV DX, NEYM+2
        INT 21h
        
        MOV DX, A2
        INT 21H
        
        MOV AX, 4C00H
        INT 21H

NEYM    DB 08h, ?, 08h DUP ("$")
Q       DB "What is your name? $"
A1      DB 0Ah, 0Dh, "What a nice name! $"
A2      DB 0Ah, 0Dh, "I'm glad to meet you! $"

The only command that you must write is:

C:\>fasm askname

FASM knows that 'askname' is actually ASKNAME.ASM and will automatically create the ASKNAME.EXE or ASKNAME.COM depending on what is written in the file. It doesn't get any simpler than that.


MOV DX, NEYM+2
INT 21

A small error here: the hex suffix is missing from the interrupt number.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.