11 Replies - 42505 Views - Last Post: 20 February 2009 - 07:40 AM

#1 tweedr01  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 17-February 09

Fibonacci Assembly Language

Posted 17 February 2009 - 07:20 PM

Hi, this is my first post, but I have found this site very helpful. I have been doing Java for the past few semesters and this is my very first using Assembly Language. We are currently just doing basic stuff, but am now trying to complete my Fibonacci program non recursively with just the basics. I posted my code below and it seems to work except for the last few numbers, and for the life of me I can't figure out what is keeping it from completing perfectly. Any help/assistance would be appreciated, and if you have any questions please feel free to ask, thanks very much!
TITLE Fibonacci				(fibonacci.asm)

; Description:
; 
; Revision date:

INCLUDE Irvine32.inc
.data
prev	DWORD ?
next	DWORD ?
value	DWORD ?
count	DWORD ?
total	DWORD ?

myMessage BYTE "Fibonacci Program",0dh,0ah,0

.code
main PROC
		mov	ecx,12
		mov	value, 1
		mov	prev, -1
		mov	eax, 1
	L1:
		mov	count,ecx
		mov	ebx, value
		add	ebx, prev
		mov	total, ebx
		mov	ebx, value
		mov	prev, ebx
		mov	eax, total
		mov	value, eax
		call DumpRegs 
		loop L1

		
	

	mov	 edx,OFFSET myMessage
	call WriteString

	exit
main ENDP

END main


This post has been edited by tweedr01: 17 February 2009 - 07:21 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Fibonacci Assembly Language

#2 bsaunders  Icon User is offline

  • D.I.C Addict

Reputation: 44
  • View blog
  • Posts: 571
  • Joined: 18-January 09

Re: Fibonacci Assembly Language

Posted 18 February 2009 - 01:15 AM

What stops the L1 loop?
Was This Post Helpful? 0
  • +
  • -

#3 tweedr01  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 17-February 09

Re: Fibonacci Assembly Language

Posted 18 February 2009 - 04:50 AM

View Postbsaunders, on 18 Feb, 2009 - 12:15 AM, said:

What stops the L1 loop?

The first few lines I have are setting the some of the memory and registers. After I have L1:, which creates the loop. The loop stops at the bottom where it says, loop L1, which then brings it back to the top and restarts the loop. Is that what you were asking? Please let me know if that answered your question, or if you were looking for something different, thanks.
Was This Post Helpful? 0
  • +
  • -

#4 tweedr01  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 17-February 09

Re: Fibonacci Assembly Language

Posted 18 February 2009 - 09:47 AM

I apologize, I previously posted this in the 'Other Languages', before I realized that there was an Assembly Topics Link I could post this in. I tried looking for a way to transfer it but I could not find one. I am trying to complete this Fibonacci code non-recursively. I posted my code below and it seems to work except for the last few numbers, and for the life of me I can't figure out what is keeping it from completing perfectly. Any help/assistance would be appreciated, and if you have any questions please feel free to ask, thanks very much!
TITLE Fibonacci				(fibonacci.asm)

; Description:
; 
; Revision date:

INCLUDE Irvine32.inc
.data
prev	DWORD ?
next	DWORD ?
value	DWORD ?
count	DWORD ?
total	DWORD ?

myMessage BYTE "Fibonacci Program",0dh,0ah,0

.code
main PROC
		mov	ecx,12
		mov	value, 1
		mov	prev, -1
		mov	eax, 1
	L1:
		mov	count,ecx
		mov	ebx, value
		add	ebx, prev
		mov	total, ebx
		mov	ebx, value
		mov	prev, ebx
		mov	eax, total
		mov	value, eax
		call DumpRegs 
		loop L1

		
	

	mov	 edx,OFFSET myMessage
	call WriteString

	exit
main ENDP

END main


Was This Post Helpful? 0
  • +
  • -

#5 Inokil  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 07-January 09

Re: Fibonacci Assembly Language

Posted 18 February 2009 - 03:23 PM

At first glance it appears that it's working correctly. If you change the line "call DumpRegs" right before the loop command to "call WriteInt" and then "call CRLF" it will print the numbers out in decimal form. When I did that, it was easier to tell if the numbers were coming out correctly. So far it appears that they are.


View Posttweedr01, on 18 Feb, 2009 - 08:47 AM, said:

I apologize, I previously posted this in the 'Other Languages', before I realized that there was an Assembly Topics Link I could post this in. I tried looking for a way to transfer it but I could not find one. I am trying to complete this Fibonacci code non-recursively. I posted my code below and it seems to work except for the last few numbers, and for the life of me I can't figure out what is keeping it from completing perfectly. Any help/assistance would be appreciated, and if you have any questions please feel free to ask, thanks very much!
TITLE Fibonacci				(fibonacci.asm)

; Description:
; 
; Revision date:

INCLUDE Irvine32.inc
.data
prev	DWORD ?
next	DWORD ?
value	DWORD ?
count	DWORD ?
total	DWORD ?

myMessage BYTE "Fibonacci Program",0dh,0ah,0

.code
main PROC
		mov	ecx,12
		mov	value, 1
		mov	prev, -1
		mov	eax, 1
	L1:
		mov	count,ecx
		mov	ebx, value
		add	ebx, prev
		mov	total, ebx
		mov	ebx, value
		mov	prev, ebx
		mov	eax, total
		mov	value, eax
		call DumpRegs 
		loop L1

		
	

	mov	 edx,OFFSET myMessage
	call WriteString

	exit
main ENDP

END main


Was This Post Helpful? 0
  • +
  • -

#6 bsaunders  Icon User is offline

  • D.I.C Addict

Reputation: 44
  • View blog
  • Posts: 571
  • Joined: 18-January 09

Re: Fibonacci Assembly Language

Posted 18 February 2009 - 05:44 PM

View Posttweedr01, on 18 Feb, 2009 - 03:50 AM, said:

View Postbsaunders, on 18 Feb, 2009 - 12:15 AM, said:

What stops the L1 loop?

The first few lines I have are setting the some of the memory and registers. After I have L1:, which creates the loop. The loop stops at the bottom where it says, loop L1, which then brings it back to the top and restarts the loop. Is that what you were asking? Please let me know if that answered your question, or if you were looking for something different, thanks.


I was wondering when the looping stopped. I understand that control returns to the beginning of the loop when loop L1 is encountered, but when does it stop looping? Is there some condition that is met that decides, "Okay, we're done looping."?
Was This Post Helpful? 0
  • +
  • -

#7 tweedr01  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 17-February 09

Re: Fibonacci Assembly Language

Posted 18 February 2009 - 08:23 PM

View Postbsaunders, on 18 Feb, 2009 - 04:44 PM, said:

View Posttweedr01, on 18 Feb, 2009 - 03:50 AM, said:

View Postbsaunders, on 18 Feb, 2009 - 12:15 AM, said:

What stops the L1 loop?

The first few lines I have are setting the some of the memory and registers. After I have L1:, which creates the loop. The loop stops at the bottom where it says, loop L1, which then brings it back to the top and restarts the loop. Is that what you were asking? Please let me know if that answered your question, or if you were looking for something different, thanks.


I was wondering when the looping stopped. I understand that control returns to the beginning of the loop when loop L1 is encountered, but when does it stop looping? Is there some condition that is met that decides, "Okay, we're done looping."?


Not in this code, the only thing that stops the loop is when ecx reaches 12. Before the loop begins I have set ecx as 12, ecx is the default for number of loops wanted. When it reaches 12, it stops looping and continues to the code after the loop. It is like a for loop, it starts at 1 and ends at 12, and increments after every loop.
Was This Post Helpful? 0
  • +
  • -

#8 tweedr01  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 17-February 09

Re: Fibonacci Assembly Language

Posted 18 February 2009 - 08:26 PM

That's a good idea, but something I should have mentioned earlier, my fault, is that DumpRegs is the way I am required to display what eax equals. So when it displays each number, it has to be displayed by using the 'call DumpRegs'. Again, sorry, I should have mentioned that earlier.

** Edit ** Removed quotes
Was This Post Helpful? 0
  • +
  • -

#9 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Fibonacci Assembly Language

Posted 18 February 2009 - 08:41 PM

Topics merged.
Was This Post Helpful? 0
  • +
  • -

#10 Inokil  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 07-January 09

Re: Fibonacci Assembly Language

Posted 18 February 2009 - 10:05 PM

Section 4.7, #6.. assuming it's the fifth edition of the book, heh.

The teacher I had when I took my assembly class asked if I wanted to help him grade the homework, and this one's on there.

Looking at the question, yeah, I see that it's asking for a call DumpRegs, but my teacher said it was easier to just display the numbers with call WriteInt (for him to grade, at least, heh). As it looks like right now, it seems to work. I would just say go with what your teacher wants you to do. If he/she wants you to use call DumpRegs, then do that.

View Posttweedr01, on 18 Feb, 2009 - 07:26 PM, said:

That's a good idea, but something I should have mentioned earlier, my fault, is that DumpRegs is the way I am required to display what eax equals. So when it displays each number, it has to be displayed by using the 'call DumpRegs'. Again, sorry, I should have mentioned that earlier.

** Edit ** Removed quotes

Was This Post Helpful? 0
  • +
  • -

#11 tweedr01  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 17-February 09

Re: Fibonacci Assembly Language

Posted 19 February 2009 - 10:53 AM

View PostInokil, on 18 Feb, 2009 - 09:05 PM, said:

Section 4.7, #6.. assuming it's the fifth edition of the book, heh.

The teacher I had when I took my assembly class asked if I wanted to help him grade the homework, and this one's on there.

Looking at the question, yeah, I see that it's asking for a call DumpRegs, but my teacher said it was easier to just display the numbers with call WriteInt (for him to grade, at least, heh). As it looks like right now, it seems to work. I would just say go with what your teacher wants you to do. If he/she wants you to use call DumpRegs, then do that.

View Posttweedr01, on 18 Feb, 2009 - 07:26 PM, said:

That's a good idea, but something I should have mentioned earlier, my fault, is that DumpRegs is the way I am required to display what eax equals. So when it displays each number, it has to be displayed by using the 'call DumpRegs'. Again, sorry, I should have mentioned that earlier.

** Edit ** Removed quotes


Nice, yeah I probably won't be grading Assembly with him, but I'd like to think I can pick it up pretty quickly. You're right on though, its #6 5th edition.


View PostJayman, on 18 Feb, 2009 - 07:41 PM, said:

Topics merged.

Thanks for merging, I apologize about the double post.
Was This Post Helpful? 0
  • +
  • -

#12 tweedr01  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 17-February 09

Re: Fibonacci Assembly Language

Posted 20 February 2009 - 07:40 AM

Hey, Inokil, sorry for taking so long to post this. I finally got a chance to sit down and try to print it out using the decimal form, you're right it does print them out fine already. The dumpregs printout made it look as if the numbers were a little screwy. Thanks for the help!

View PostInokil, on 18 Feb, 2009 - 02:23 PM, said:

At first glance it appears that it's working correctly. If you change the line "call DumpRegs" right before the loop command to "call WriteInt" and then "call CRLF" it will print the numbers out in decimal form. When I did that, it was easier to tell if the numbers were coming out correctly. So far it appears that they are.


View Posttweedr01, on 18 Feb, 2009 - 08:47 AM, said:

I apologize, I previously posted this in the 'Other Languages', before I realized that there was an Assembly Topics Link I could post this in. I tried looking for a way to transfer it but I could not find one. I am trying to complete this Fibonacci code non-recursively. I posted my code below and it seems to work except for the last few numbers, and for the life of me I can't figure out what is keeping it from completing perfectly. Any help/assistance would be appreciated, and if you have any questions please feel free to ask, thanks very much!
TITLE Fibonacci				(fibonacci.asm)

; Description:
; 
; Revision date:

INCLUDE Irvine32.inc
.data
prev	DWORD ?
next	DWORD ?
value	DWORD ?
count	DWORD ?
total	DWORD ?

myMessage BYTE "Fibonacci Program",0dh,0ah,0

.code
main PROC
		mov	ecx,12
		mov	value, 1
		mov	prev, -1
		mov	eax, 1
	L1:
		mov	count,ecx
		mov	ebx, value
		add	ebx, prev
		mov	total, ebx
		mov	ebx, value
		mov	prev, ebx
		mov	eax, total
		mov	value, eax
		call DumpRegs 
		loop L1

		
	

	mov	 edx,OFFSET myMessage
	call WriteString

	exit
main ENDP

END main


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1