Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

[x86 Assembly] Help with an algortyhm.

HeroereHeroere Posts: 2Member
ok guys, I don't know who else to ask. I'm pretty much screwed if someone of you doesn't help me.

Let's get to the problem. I've had a problem to solve, I've made the algorythm, all cool. Problem is, there are some structures such as array and/or do/do..while cycles that weren't taught to us!

So this is the algorythm.
[code]START
N(int)=0
i(int)=0
V[N]
even=0
odd=0
input N
do
input V[i]
i=i+1
while i<N
i=0
do
if i%2=0
then V[i]=V[i]+1
else
V[i]=V[i]^2
i=i+1
while i<N
i=0
do
if V[i] is even
then even=even+1
else odd=odd+1
i=i+1
while i<N
output pair
output odd
END[/code]

Whoever can help me with this, I would appreciate it tons and even pay something for it. Please!

Thanks for reading.

Comments

  • HeroereHeroere Posts: 2Member
    No need to assemble it.
  • AsmGuru62AsmGuru62 Posts: 6,519Member
    [color=Blue]Since you need to input values from console and output them back to console take a look here:

    [link=http://www.codexxi.com/MyBlocks.html]http://www.codexxi.com/MyBlocks.html[/link]

    The project you need called: "Sorting integer values (DOS, TASM)" - get it and take a look at the code. I wrote it even before I switched to FASM.

    As for arrays and loops they are very easy. To declare an array use DUP directive:
    [/color]
    [code]
    [color=Green];
    ; Reserve ten 16-bit values following each other
    ; in memory and set all ten values to zero
    ;[/color]
    Array DW DUP (0)[/code]
    [color=Blue]To address such an array in a loop use following code:[/color]
    [code]
    MOV CX, 10 [color=Green]; LOOP TEN TIMES[/color]
    LEA SI, Array [color=Green]; LOAD ADDRESS OF FIRST ELEMENT INTO SI[/color]
    XOR DX, DX [color=Green]; DX=0 IF YOU NEED INDEX FOR SOMETHING[/color]

    NEXT_ELEMENT:
    MOV AX, [SI] [color=Green]; LOAD Array[I] INTO REGISTER AX[/color]
    [color=Green];
    ; ... do whatever you need with AX
    ;[/color]
    ADD SI, 2 [color=Green]; SHIFT SI BY 2 BYTES, SO IT WILL ADDRESS NEXT ITEM[/color]
    INC DX [color=Green]; DX WILL BE 0,1,2,3,...[/color]
    LOOP NEXT_ELEMENT
    [color=Green];
    ; At this point ALL TEN ARRAY ITEMS HAVE BEED PROCESSED
    ;[/color]
    [/code]
    [color=Blue]Inside the loop (between lines [color=Red]NEXT_ELEMENT:[/color]
    and [color=Red]LOOP NEXT_ELEMENT[/color]) do not change CX register and if you need it for something - use PUSH/POP to preserve it.[/color]
Sign In or Register to comment.