x86 Assembly

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

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
[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!

Thanks for reading.

Report
Re: [x86 Assembly] Help with an algortyhm. Posted by Heroere on 7 Jan 2011 at 4:16 AM
No need to assemble it.
Report
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
LEA    SI, Array    ; LOAD ADDRESS OF FIRST ELEMENT INTO SI
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
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.