×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Problem with offsets

Problem with offsets

Problem with offsets

(OP)
Hello. I have a buffer containing a load of data with the starting address in BX. I am wanting to copy just a section of this data into another buffer with starting address BP. The offset of the start of the data i want to copy is held in SI, and the length of subsector i want to copy is held in AX.

This is the code i am trying:

      ;use length of subsector as count
      mov CX, AX

      For:

      mov AX,[BX+SI+CX] ;Buffer+StartLocation+Count
      mov [BP+CX],AX ;Subsector Address+Count

      loop For

However i get two errors pointing at the two lines in my for loop, saying 'Invalid Effective Address'

Any ideas/solutions?

Thanks in advance

RE: Problem with offsets

You cannot use CX as an index to a memory address, i think
that is the cause of the error.

btw:
The first line of your loop copies data from the data segment (DS) to AX.
The second line copies AX to the stack segment (SS).
So even when CX is removed the code would not work.
I recommend reading a book or a tutorial about the various
addressing modes available on your processor.

Replace your loop code with this:

add si,bx
mov cx,ax
mov di,bp
rep movsb

that will hopefully solve your problem.

RE: Problem with offsets

... I hope we got a good grade again?

RE: Problem with offsets

You not only can't use cx as a index, but you can't even
use three registers as one memory index at the same time.
If you would be using the 32 bit registers than the ecx
would be possible to use but not three registers.

So you have to build a pre-index first and then use it
with the third indexing register.

Tessa

RE: Problem with offsets

Three indexes ARE possible, but only with 2 registers and
an immediate value.

  mov ax,[bx+si+0DEAD]

RE: Problem with offsets

As I wrote: you can't use three "register" as a index in
one instruction.
So don't correct me with a third index.
An immedicate value can be seen as an index, but normally
it is used as the base address of the array you want
to index within.

Tessa

RE: Problem with offsets

... please, everybody, remember this is a standard homework question and the original poster has only ever posted one question in tek-tips...

RE: Problem with offsets

Have we got an "A" yet?

RE: Problem with offsets

tessa,
i wasn't correcting you, i was supplementing your remarks.

lionel & zeit,
as long as the problem is fun to solve, i am willing to answer
their question, even though it is a school question.
if they want to be lazy, go ahead. its their choice.

RE: Problem with offsets

  I tend to agree with denc.  And edd might just have possibly learned something in the transaction.  If they don't, it'll show later on down the line.

The simplest solution is the best!

RE: Problem with offsets

The only thing I'm allways curious about is, like lionelhill is asking: what grade did we get.

And denc is just stating what I think about answering
this kind of questions, its fun to find out a simple and
compleet answer.

Tessa

RE: Problem with offsets

yup, it's OK, provided the teacher/examiner isn't suffering from the temptation to judge individuals relative to the class average. Because if the class average is being messed up by the top 5 cheats, then the bottom 5 real achievers suffer.

RE: Problem with offsets

I gave up caring what teachers thought when my Open University marker dropped my assignment marks because I used the comments field to explain what the code achieved rather than explaining what the instruuctions meant...

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close