sportskid300 Grandmaster Cheater
Reputation: 0
Joined: 22 Jun 2006 Posts: 944 Location: You Wish.
|
Posted: Tue Jun 05, 2007 8:43 pm Post subject: Playing with dwords? |
|
|
As far as I know, I have to keep moving dwords into registers to mess with them.
Is there a way around this?
The reason I ask is because Im trying to make a simple program that spits out a specified number of terms in the Fibonacci sequence.
In case you didn't know, the Fibonacci sequence works like this:
1st term: 1
2nd term: 1
3rd term: addition of the first terms (2)
4th term: addiction of the last 2 terms (1+2=3)
5th term: addition of the last two terms (3+2=5)
So on and so forth.
This is as far as I got:
| Code: |
include \masm32\include\masm32rt.inc
.data
ass dd 1
ass1 dd 1
count dd 0
timer dd 0
.code
start:
call main
invoke ExitProcess, 0
main proc
mov ass, 1
mov ass1, 1
mov count, sval(input("How many terms of the Fibonacci sequence would you like shown? "))
mov eax, count
sub eax, 2
mov count, eax
cmp count, 0
jg first
je only
invoke ExitProcess, 0
only:
print chr$(10,"1",10,10,"1",10,10)
push 1000
call Sleep
invoke ExitProcess, 0
first:
print chr$(10,"1",10,10,"1",10,10)
do:
mov eax, ass
mov ebx, ass1
add eax, ebx
print str$(eax)
mov ass, eax
mov ass1, ebx
call space
mov eax, ass
mov ebx, ass1
add ebx, eax
print str$(ebx)
mov ass, eax
mov ass1, ebx
call space
jmp do
main endp
space proc
print chr$(10,10)
mov ecx, timer
mov edx, count
inc ecx
cmp ecx, edx
jne dont
push 1000
call Sleep
invoke ExitProcess, 0
dont:
mov timer, ecx
mov edx, count
push 800
call Sleep
ret
space endp
end start
|
It assembles just fine, but if you run it, it spits out:
1
1
2
2
3
3
etc...
Thanks for the help! _________________
|
|