Jump to content
  • Advertisement
Sign in to follow this  

An assembly language problem

This topic is 4415 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
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 copy
add si, bx ; set si to the start of the requested data
for:
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 loop



Viktor

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
Quote:
Original post by edd1986
I 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],AX


But 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, AX
add SI, BX
mov DI, BP

rep movsw


Share this post


Link to post
Share on other sites
Quote:
Original post by edd1986
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 :)

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!