   An assembly language problem
  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 ForHowever i get two errors pointing at the two lines in my for loop, saying 'Invalid Effective Address'Any ideas/solutions?Thanks in advance   
  It looks like you are using 16 bit x86 assembly. This mode doesn't allow multiple registers in one instruction. To make it work, add bx to si and use that as an address, then increment the si register manually. The si register will use the data segment the bp register will use the stack segment as a default segment.example:mov cx, ax ; cx = number of words (2 bytes) to copyadd si, bx ; set si to the start of the requested datafor:  mov ax, [si] ; load 2 bytes  add si, 2    ; step 2 bytes  mov [bp], ax ; store 2 bytes  add bp, 2    ; step 2 bytes  loop for; check the loopViktor   ;  Any particular reason you're working in 16 bit asm?   ;  I can use multiple registers in one instruction as i have done this in other parts of my code.Am not sure what type of assembly it is. I'm only doing this for a uni module tutorial. i hope never to look at assembly language again.Thanks for the advice, problem sorted :)   ;Quote:Original post by edd1986I can use multiple registers in one instruction as i have done this in other parts of my code.In 16-bit assembly, you can only use certain register combinations in effective address calculations. Neither of these are valid:mov AX,[BX+SI+CX]mov [BP+CX],AXBut the following are:mov AX, [BX]; mov AX, [BP]; mov AX, [SI]; mov AX, [DI];mov AX, [BX+SI]; mov AX, [BX+DI]; mov AX, [BP+SI]; mov AX, [BP+DI]Each of these can also have an optional displacement.Remeber that those which take BX as a base register (or have no base) use the DS segment register, and those which use BP use the SS register.Quote:Am not sure what type of assembly it is.16-bit x86.Quote:i hope never to look at assembly language again.That's a shame. Don't let the wierdness of 16-bit x86 put you off.Quote:Thanks for the advice, problem sorted :)The best solution to your particular problem is to use the "rep movsw" instruction, like this (I assume that you are working within a single segment and have DS==ES==SS. If not, you'll have to do some fiddling with the segment registers):mov CX, AXadd SI, BXmov DI, BPrep movsw;Quote:Original post by edd1986I can use multiple registers in one instruction as i have done this in other parts of my code.Am not sure what type of assembly it is. I'm only doing this for a uni module tutorial. i hope never to look at assembly language again.Thanks for the advice, problem sorted :)Use at least 32 bit assembly FLAT MEMORY MODEL, and if 16 bit assembly is required by teacher, ask him to teach you 32 bit assembly FIRST, or you'd be in danger to learn NOTHING useful. 32 bit assembly is significantly easier and more confortable, 16 is usable only for boot loaders (and seting up the computer into 32/64 bit mode).http://win32assembly.online.fr/tutorials.html Look here it's somewhat standard resource, and look into demonstration programs in the MASM32, and FLAT assembler.