flat assembler
Message board for the users of flat assembler.

Index > OS Construction > What does rep movsb take?

Author
Thread Post new topic Reply to topic
sid123



Joined: 30 Jul 2013
Posts: 339
Location: Asia, Singapore
sid123 25 Dec 2013, 04:42
I am trying to copy a block of code from one segment to the another,
using a rep movsb.
I think this is what rep movsb takes
SI : Source
DI : Destination (Offset)
CX : Bytes to copy
Is this correct? If not then please tell me what is the correct representation.
Now to the code.
This is an Interrupt that takes SI,CX and DI and when called it copies
stuff in SI to 0x5000:0x0000.
I tried it. It works pretty much. But I am still unsure whether this is doing what it should + If my representation of SI,DI and CX during movsb is correct or not.
Code:
int_26_ivt:
                                cmp ah,0x00
                                je segment_copy
segment_copy:
                                mov bx,0x5000
                                mov es,bx
                                ; SI : MOVed by programmer (Stuff to copy)
                                ; DI : MOVed by programmer (Offset to copy)
                                ; CX : MOVed by programmer (Bytes to Copy)
                                rep movsb ; Copy it!
                                mov ds,bx
                                call 0x5000:0 ; Call it!
                                ; Restore the segment registers
                                mov bx, 0x2000 
                                mov ds, bx
                                mov es, bx
                                ; Restore Everything
                                jmp int_26_exit
int_26_exit:
                                pop ds
                                pop es
                                pop fs
                                pop gs
                                popa
                                iret 
    

How can I forget this?!!!
Merry Christmas to all!

_________________
"Those who can make you believe in absurdities can make you commit atrocities" -- Voltaire https://github.com/Benderx2/R3X
XD
Post 25 Dec 2013, 04:42
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20401
Location: In your JS exploiting you and your system
revolution 25 Dec 2013, 04:50
Well the Intel/AMD manuals explain this so really you should be looking there for definitive answers, but the general sense of what you say is correct except for the segment registers and the direction flag which you didn't mention.

Source: DS:SI
Destination: ES:DI
Length: CX
Direction: DF

Plus you need to make sure that overlapping regions are copied in the proper sequence so as not to overwrite previous data.
Post 25 Dec 2013, 04:50
View user's profile Send private message Visit poster's website Reply with quote
sid123



Joined: 30 Jul 2013
Posts: 339
Location: Asia, Singapore
sid123 25 Dec 2013, 04:59
@revolution
Thanks.
I do clear the direction flag and push all the segment registers before calling the interrupt. Just wanted to focus on the main part.
Post 25 Dec 2013, 04:59
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20401
Location: In your JS exploiting you and your system
revolution 25 Dec 2013, 05:08
sid123 wrote:
I do clear the direction flag and push all the segment registers before calling the interrupt. Just wanted to focus on the main part.
Simply clearing DF is not always correct. You need to check for overlapping regions then set/clear DF and adjust SI & DI accordingly.
Post 25 Dec 2013, 05:08
View user's profile Send private message Visit poster's website 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


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.