flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > DOS > Variables definition placement and length

Author
Thread Post new topic Reply to topic
tagore



Joined: 20 May 2015
Posts: 1
Variables definition placement and length
Hello!

In this simply example of code I got different results, depended on the placement of db and the length of the defined variable.
The program prints “Hello World!”, the only difference is where the definition of the string is located.


Code:
        org 100h

string1 db 'Hello World!',10,0 ;(1)

        lea esi,[string1]

print:  mov dl,[esi]
        cmp dl0
        je  finish
        mov ah02h
        int 021h
        inc esi
        jmp print


finishmov ah01h
        int 021h
        int 020h
;(2)string1 db 'Hello World!',10,0



(1) The result is "llo World!" - missing two first characters.

When you put db on the end of the program(2) the result is "Hello World!" - correct one.

I can't see the difference, and why this should be wrong.

When you write "string1 db 'Hello World!', 13, 10, 0" or “string1 db 'Hello World!', 0” works in both cases, but I don't understand why.

From some trials I know that 10(line feed) is not the case, it depends of the string1 length, but why it should make a difference where is placed.
Post 27 May 2015, 15:56
View user's profile Send private message Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 518
Location: Munich
The program is executed in the first line !
You have to put data separate (into another segment) or at the end of the program. You could also use jmp print in the first line to skip the data section.

Your code is executed from the beginning regardless if you think this is text or code. The CPU doesn't know and try to execute your data "Hello World" which gives unpredicted results. Wink
Post 27 May 2015, 17:55
View user's profile Send private message Send e-mail Reply with quote
El Tangas



Joined: 11 Oct 2003
Posts: 119
Location: Sunset Empire
Exactly, you are making a .com executable, right? This format is just a flat binary that starts executing from the first byte, it doesn't have an "entry point". So your data gets executed as if it was code, who knows what kind of crazy instructions result from the "Hello World!" string... You could check with a DOS debugger...
Post 27 May 2015, 18:26
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.