Initializing DX to Code Segment(CS) Memory Address…?!? 
Author Message
 Initializing DX to Code Segment(CS) Memory Address…?!?

;portion of source code from test.exe

find db 'test.exe',00h
mov ax,3d02h
mov dx,offset find
int 21h
xchg bx,ax
mov ah,40h
mov cx,20 ;20 bytes to be copied
mov dx,offset start_copy
int 21h
mov ah,3eh
int 21h
.
.
.
start_copy:  lea bx,start0
xor_loop1: mov ah,cs:[bx]
           xor ah,0ffh
           mov cs:[bx],ah
           inc bx
           cmp bx,offset start0+39
           jle xor_loop1
start0:

Here is my question! I am coding a program. Let's call this program "test.exe".
I created a target file. Let's call the target file "target.exe". Here is what
I am trying to do. I am trying to copy portion of source code from "test.exe"
to "target.exe" by using "mov ah,40h int 21"

I set CX to the numbers of bytes to be copied from "test.exe" to "target.exe".
So far so good!

I have to set DX so that it points to the address where "start_copy" starts,
and that address *should* point to Code Segment (CS) because that's where the
bytes, that I like to copy, are...

When I initialize DX to "start_copy" by using "mov dx,offset start_copy". DX
points to Data Segment (DS), which is not where the bytes, that I want to copy,
are  

What can I do so that DX points to Code Segment(CS)?

Any ideas?



Thu, 18 Mar 2004 23:55:50 GMT  
 Initializing DX to Code Segment(CS) Memory Address…?!?

Quote:

>I have to set DX so that it points to the address where "start_copy"
starts,
>and that address *should* point to Code Segment (CS) because that's where
the
>bytes, that I like to copy, are...

>When I initialize DX to "start_copy" by using "mov dx,offset start_copy".
DX
>points to Data Segment (DS), which is not where the bytes, that I want to
copy,
>are

>What can I do so that DX points to Code Segment(CS)?

DS, CS and DX are all registers.  DS:DX points to a particular memory
location.  You want DS:DX to point to a location in your code segment.

push ds
push cs
pop ds
Later you can pop ds again to point to the original data segment.
Or you could write your program as a .COM file, with everything in
one segment, if it will fit in 64k.



Fri, 19 Mar 2004 06:56:18 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Initializing DX to Code Segment(CS) Memory Address...?!?

2. Code Segment Address

3. Effective address to 'segmented' address

4. data segment vs code segment

5. error in segment CS ?

6. Accessing absolute memory addresses in machine code

7. Initializing segment registers

8. Linking plain assembly and the /i (initialize all segments) option

9. initialize DS to data segment

10. Initialized data segment when using entries (CA-REALIA 5.x)

11. Locating the memory address range of a network card MAC address

12. assume cs:code,ds:code

 

 
Powered by phpBB® Forum Software