#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2009
    Posts
    27
    Rep Power
    0

    EMU8086 - Help converting 8-bit array to 16-bit array


    I'm not new to programming, but I am fairly new to assembly and I am having a little bit of trouble converting over. I realize this is a simple process, but any and all help would be much appreciated.

    I have two arrays declared:
    array1 db 10h, 20h, 30h, 40h, 50h
    array2 dw 5 dup(?)

    I need to copy the data in the 8-bit array1 to the 16-bit array2.

    I believe I need to store the data in one of the registers first, then transfer it over to array2. I am not sure the syntax to use for this or the correct process. Thanks.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2007
    Posts
    765
    Rep Power
    928
    What have you tried / where are you stuck? If you have code that doesn't work post it here (surround it with [code][/code] tags to make it legible) as well as any error messages (or if its running what you expected to happen vs. what did happen).

    If you haven't manage to write code yet, where are you stuck? Do you know how to create, assemble and run a program? How to move values between registers? between registers and memory? Can you code a loop?

    As the sticky at the top of the forum says, no one here is going to do your homework for you, but if you show your efforts we can look for errors and point you in the right direction.
    sub{*{$::{$_}}{CODE}==$_[0]&& print for(%:: )}->(\&Meh);
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2009
    Posts
    27
    Rep Power
    0
    Thanks OmegaZero, I would rather no one just give me the code as well. I'm a learn by doing person.

    I understand how to create, assemble and run a program. The only program I've done is taking values from an array, and adding them together. I also implemented a simple loop to do this process. I understand how to move data using "mov".

    I could use a little clarity on the "mov" function. Does "mov" transfer data to a specified location. And is there a different function that just transfers the address, acts as a pointer?

    I've already declared the two arrays in the data section. And in the code segment, my professor has confirmed that this is the way he wants us to start:
    Code:
    lea bx, array1
    lea si, array2
    I could use a little help/pointers on how to increment between the values of the array.

    Also, if I "mov array2, si" data from a register to an array, it will place that data into the array. If I then do the same process again, such as "mov array2, si" will it add the data to the array or replace what is already in the array?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2007
    Posts
    765
    Rep Power
    928
    It sounds like you know about pointers from C. In which case this might help:
    Code:
    This assembler code
        value dw 0
        mov ax, value
        lea bx, value
    
    Looks like it is the same as the C
        int value = 0;
        ax = value;
        bx = &value;
    
    But is really
        // 0x1234 is some place in memory that
        // was initialized when the program was started
        const int *value = 0x1234;
        ax = *value;
        bx = value;
    (I.e. An identifier like "value" in "value db ..." is really just making a note of where in memory the ... starts)

    Originally Posted by BryanAdams
    I could use a little clarity on the "mov" function. Does "mov" transfer data to a specified location. And is there a different function that just transfers the address, acts as a pointer?
    'mov' transfers data from one of its operands to the other. Whether that's immediate->register register->register or memory->register, etc. depends on the operands you give it.

    Code:
    mov ax, 0
    mov ax, bx
    mov ax, [bx]
    (guessing on the syntax your assembler uses here.)

    'lea' moves an address into a register.

    Originally Posted by BryanAdams
    I could use a little help/pointers on how to increment between the values of the array.

    Also, if I "mov array2, si" data from a register to an array, it will place that data into the array. If I then do the same process again, such as "mov array2, si" will it add the data to the array or replace what is already in the array?
    Arrays are nothing more than an address in memory of the first element. Any mov instruction with 'array2' will read/write the same location in memory. To read or write the next byte in memory you need "address-of-array2 + 1" (which should hopefully explain why your teacher is having you store the address in a register)
    sub{*{$::{$_}}{CODE}==$_[0]&& print for(%:: )}->(\&Meh);
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2009
    Posts
    27
    Rep Power
    0
    Thanks OmegaZero, your explanations really helped out. My interpretations of the mov and lea function were slightly off in their purpose.

    I figured out the rest of the program. My biggest problem was moving from the 1-byte to the 2-byte register. When I realized I could just use a 1-byte register such as "al" to store each value from the array then transfer them over, it was a very simple process.

    Thanks again for the help, really gave me some clarity on the processes.

IMN logo majestic logo threadwatch logo seochat tools logo