Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with offsets

Status
Not open for further replies.

edd1986

Programmer
Apr 20, 2006
1
GB
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
 
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.
 
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
 
Three indexes ARE possible, but only with 2 registers and
an immediate value.

mov ax,[bx+si+0DEAD]
 
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
 
... please, everybody, remember this is a standard homework question and the original poster has only ever posted one question in tek-tips...
 
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.
 
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!
 
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
 
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.
 
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...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top