Hello World! with standard segment directives

546 views Asked by At

I have written the "Hello World!" code with simplified segment directives,

.MODEL small
.STACK
.DATA
msg  DB 'Hello, World!', 0Dh, 0Ah, '$'
.CODE
.STARTUP

LEA DX, msg
MOV ah, 9
INT 21h

MOV ah, 4Ch
INT 21h
END

but I must have written something wrong (or miss something) when writing the same thing with standard directive. The code prints a bunch of symbols and only at the end the sentence "Hello World!". What am I missing?

myData SEGMENT
msg  DB 'Hello, World!', 0Dh, 0Ah, '$'
myData ENDS

myCode SEGMENT
ASSUME DS:myData, CS:myCode, SS:myStack

LEA DX, msg
MOV ah, 9
INT 21h

MOV ah, 4Ch
INT 21h
myCode ENDS

myStack SEGMENT
myStack ENDS

END
1

There are 1 answers

7
Jose Manuel Abarca Rodríguez On BEST ANSWER

My TASM tells "No entry point", and the garbage chars might indicate missing initialization of data segment, so let's fix both:

myData SEGMENT
msg  DB 'Hello, World!', 0Dh, 0Ah, '$'
myData ENDS

myCode SEGMENT
ASSUME DS:myData, CS:myCode, SS:myStack

begin:              ;◄■■ ENTRY POINT ◄────────┐
                                              │
mov ax, myData   ;◄■■ INITIALIZATION          │
mov ds, ax       ;◄■■ OF DATA SEGMENT.        │
                                              │
LEA DX, msg                                   │
MOV ah, 9                                     │
INT 21h                                       │
                                              │
MOV ah, 4Ch                                   │
INT 21h                                       │
myCode ENDS                                   │
                                              │
myStack SEGMENT                               │
myStack ENDS                                  │
                                              │
END begin          ;◄■■ ENTRY POINT ◄─────────┘

The "END" directive at the bottom of the code also indicates the point where the program starts to be executed. The initialization of data segment is required in TASM, EMU8086, GUI Turbo Assembler and others where "ASSUME" is not enough.