I have written a small 8086 programme to display a string on the PC screen using MS DOS interrupts....
I would like to have my string "Hello World !" stored in the data segment...
My assembler a86/nasm demands the datasegment to be defined before the code segment...
The code is generated and when I see the .com file, the string is defined before the code.... And in DEBUG Utility, the string is placed at cs:0100 and the dat a is executed before the code.... I guess that the programming is giving the desired output only by fluke...
Please help....
Code:
.DATA SEGMENT
hm:
db 'Hello World'
.DATA ENDS
.CODE SEGMENT
mov ax,SEG hm
mov ds,ax
mov si,OFFSET hm
mov cx,0005h
mov ah,02h
writestring:
mov dl,[si]
int 21h
inc si
loop writestring
int 20h
.CODE ENDS
.ORG is not recommended while writing 8086 codes in MS DOS as the codes are supposed to be relocatable....
I am looking for mydata to be at the end of the code segment...
This works if I define lables and use the lables as the address locations of the data. How evcer variables are not forward referenced by any of the assembles that I have used...
It does not define the data segment seperate... see the mov ax,cs and mov ds,ax
NASM was creating a problem while defining locations as it was not permitting the file preamble created by DOS. I had to add 100h to my locations for the programme to work correctly.
Demonstrates a way out... I do not like it... It does not allow one 256Kb space (CS+DS+ES+SS) as the data segment and the code segment overlap.... I do not have such large programs to write but I would like to incorporate good practice.
He's using NASM, the open source netwide assembler.
NASM's syntax is quite different to MASM, it doesn't support OFFSET or SEG, it doesn't even use labels or data types, it purely uses addresses which is better in my opinion.
For example to reference an address:
section .code
org 100h ;Mandatory, since it will assume it's a .sys file and use 0h.
Mov SI, Msg
section .data
Msg: db 'hello world'
I'm a bit rusty, I haven't done assembly programming in DOS for years as it's long been obsolete, there again it's good for learning about how computers work so it's a good thing to do.