reverse array

how do i reverse an array of characters read in from the user?

Comments

  • : how do i reverse an array of characters read in from the user?
    :

    After the array is complete and the user is finished adding to it, reverse the array.

    You can reverse the array by looping through half of it and swapping each element(index = pass #) with the element(index = (length of array) - (pass#)).
  • : : how do i reverse an array of characters read in from the user?
    : :
    :
    : After the array is complete and the user is finished adding to it, reverse the array.
    :
    : You can reverse the array by looping through half of it and swapping each element(index = pass #) with the element(index = (length of array) - (pass#)).
    :
    [blue]
    1. Set a counter in CX to (array size / 2)
    2. Set a SI register at the first element of an array
    3. Set a DI register at the last element of an array

    4. Swap elements at [DI] and [SI]
    5. Move SI forward to a size of one element
    6. Move DI backward to a size of one element

    7. LOOP back to step #4 until CX is zero

    [/blue]
  • : : : how do i reverse an array of characters read in from the user?
    : : :
    : :
    : : After the array is complete and the user is finished adding to it, reverse the array.
    : :
    : : You can reverse the array by looping through half of it and swapping each element(index = pass #) with the element(index = (length of array) - (pass#)).
    : :
    : [blue]
    : 1. Set a counter in CX to (array size / 2)
    : 2. Set a SI register at the first element of an array
    : 3. Set a DI register at the last element of an array
    :
    : 4. Swap elements at [DI] and [SI]
    : 5. Move SI forward to a size of one element
    : 6. Move DI backward to a size of one element
    :
    : 7. LOOP back to step #4 until CX is zero
    :
    : [/blue]
    :
    [green]
    Or read four bytes with one move using 32 bit registers and the BSWAP instruction.
    [/green]


    Greets,
    Eric Goldstein
    www.gvh-maatwerk.nl

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories