#### Howdy, Stranger!

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

# reverse array

Member Posts: 1
how do i reverse an array of characters read in from the user?

• Member Posts: 675
: 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#)).
• Member Posts: 6,519
: : 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]
• Member Posts: 621
: : : 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

• Member Posts: 0

____ // http://forcoder.org // free video tutorials and ebooks about // R Swift Go Visual Basic .NET Visual Basic C Python PHP C# PL/SQL MATLAB Objective-C C++ Scratch Ruby Assembly Perl Delphi JavaScript Java Kotlin Apex Rust Erlang Bash Hack ABAP Prolog Alice Ada LabVIEW Julia D Scala Clojure F# Crystal Scheme Lua SAS COBOL FoxPro Awk Transact-SQL Fortran VBScript ML Dart Lisp Logo // _______