## x86 Assembly

Moderators: None (Apply to moderate this forum)
Number of posts: 16011

This Forum Only

[x86 Assembly] Help with an algortyhm. Posted by Heroere on 7 Jan 2011 at 4:00 AM
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.
```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```

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

Re: [x86 Assembly] Help with an algortyhm. Posted by Heroere on 7 Jan 2011 at 4:16 AM
No need to assemble it.
Re: [x86 Assembly] Help with an algortyhm. Posted by AsmGuru62 on 7 Jan 2011 at 6:03 AM
Since you need to input values from console and output them back to console take a look here:

http://www.codexxi.com/MyBlocks.html

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:

```;
; Reserve ten 16-bit values following each other
; in memory and set all ten values to zero
;
Array DW DUP (0)```

To address such an array in a loop use following code:
```MOV    CX, 10       ; LOOP TEN TIMES
XOR    DX, DX       ; DX=0 IF YOU NEED INDEX FOR SOMETHING

NEXT_ELEMENT:
MOV    AX, [SI]     ; LOAD Array[I] INTO REGISTER AX
;
; ... do whatever you need with AX
;
ADD    SI, 2        ; SHIFT SI BY 2 BYTES, SO IT WILL ADDRESS NEXT ITEM
INC    DX           ; DX WILL BE 0,1,2,3,...
LOOP   NEXT_ELEMENT
;
; At this point ALL TEN ARRAY ITEMS HAVE BEED PROCESSED
;
```

Inside the loop (between lines NEXT_ELEMENT:
and LOOP NEXT_ELEMENT) do not change CX register and if you need it for something - use PUSH/POP to preserve it.

## Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic