News:

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

data segment

Started by xxxx, February 03, 2005, 02:39:21 PM

Previous topic - Next topic

xxxx

    MOV AX,@DATA
    MOV DS,AX

what would happen to the program if MOV DS,AX was left out?


thanks

BigDaddy

Just pretend that you have a program with a single data segment, DSEG1 and a single ASSUME directive, ASSUME DS:DSEG1.  Let's further say that you have defined a variable named MYVAR at offset 20 in DSEG1. 

Any code after the ASSUME will believe that DS points at DSEG1, and any assembler instruction that uses MYVAR will be assembled using an offset of 20. 

Now, let's just say that you've assembled an EXE, and to add a dash of excitement, you use EXE2BIN to turn it into a COM file.  When DOS loads that program, it will point DS at the beginning of your program.  Since most programs are at least 20 bytes long, the first instruction that updates MYVAR will change your program's instructions! 

I've seen this done on purpose, but it's ordinarily a mistake. 

MichaelW

xxxx.

If you left these two instructions out of the code for an EXE, then DS would be left pointing at the PSP instead of at the data segment, and none of your data references would work correctly.
eschew obfuscation