Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 27th, 2006, 2:18 PM   #1
sackarias
Programmer
 
sackarias's Avatar
 
Join Date: Jan 2006
Posts: 58
Rep Power: 3 sackarias is on a distinguished road
loop problem!

The loop wont work? This is my first program in assembly and I'm getting frustrated as all hell. It reads the data correctly, but it just wont loop. scanf returns into %o0 the amount of pieces of data it read correctly, which when I'm testing i'm always using 2, so I can't see why it wont loop and ask for 2 more integers. As far as the math portion i'll get that done later.

help..please.

/****************************************************
Author: Zack Hitz
Class: CIS 235
File: Exercise2
Date: September 28, 2006
Purpose: Read two integers, compute x*x + y*y, then
         output x, y, and the answer.
****************************************************/

        .data

!String constants
        .align 4
prompt:         .asciz "Enter two integers: "
        .align 4
formati:        .asciz "%d %d"
        .align 4
formato:        .asciz "x = %d\ny = %d\nh = %d\n"

        !int x = 0;
        !int y = 0;
        !int sum = 0;
    .align 4
x:      .word 0
y:      .word 0
h:      .word 0

!void main()
!{
! printf(prompt);
! scanf(formati, &x, &y);
! sum = (x*x)+(y*y);
! printf(formato, x, y, sum);
! call exit(0);
!}

        .text
        .align 4
        .global main
main:
        save %sp, -64, %sp

        loop:
        !printf(prompt)
        sethi %hi(prompt), %o1
        call printf, 0
        or %o1, %lo(prompt), %o0

        !scanf(formati, %x, %y)
        set formati, %o0
        set x, %o1
        set y, %o2
        call scanf, 0
        nop

        ld[%o1],%o1
        ld[%o2],%o2

        sethi %hi(formato), %l1
        call printf,0
        or %l1, %lo(formato), %o0

        cmp %o0, 2
        be loop
        nop

        call exit, 0
        mov 0, %o0

Last edited by sackarias; Sep 27th, 2006 at 2:46 PM.
sackarias is offline   Reply With Quote
Old Sep 27th, 2006, 4:12 PM   #2
sarumont
Hobbyist Programmer
 
sarumont's Avatar
 
Join Date: Apr 2004
Location: /dev/urandom
Posts: 154
Rep Power: 5 sarumont is on a distinguished road
Send a message via ICQ to sarumont Send a message via AIM to sarumont Send a message via Yahoo to sarumont
Quote:
Originally Posted by sackarias View Post
        be loop
Not being fluent in x86 ASM, does the 'be' instruction exist? That looks like where you are attempting to branch back to 'loop', but I cannot (quickly) find a reference to that instruction.
__________________
"Time is an illusion. Lunchtime doubly so."
-the late, great Douglas Adams
sarumont is offline   Reply With Quote
Old Sep 27th, 2006, 5:08 PM   #3
sackarias
Programmer
 
sackarias's Avatar
 
Join Date: Jan 2006
Posts: 58
Rep Power: 3 sackarias is on a distinguished road
It does and I got it to work now. Thanks a lot.
sackarias is offline   Reply With Quote
Old Sep 27th, 2006, 5:11 PM   #4
big_k105
PFO Founder

 
big_k105's Avatar
 
Join Date: Mar 2004
Location: Fargo, ND
Posts: 1,623
Rep Power: 10 big_k105 is on a distinguished road
Send a message via AIM to big_k105 Send a message via MSN to big_k105 Send a message via Yahoo to big_k105
What was the problem with your code, if you don't mind me asking? Maybe it could help others out.
__________________
BIG K aka Kyle
Programming Forums
Kyle K Online

Please do not PM or email me programming questions. Post them in the forums instead.
big_k105 is offline   Reply With Quote
Old Sep 27th, 2006, 6:23 PM   #5
sackarias
Programmer
 
sackarias's Avatar
 
Join Date: Jan 2006
Posts: 58
Rep Power: 3 sackarias is on a distinguished road
Not at all..
main:
	save %sp, -64, %sp

	loop:	
		!printf(prompt)
		sethi %hi(prompt), %o1
		call printf, 0
		or %o1, %lo(prompt), %o0

		!scanf(formati, %x, %y)
		set formati, %o0
		set x, %o1
		set y, %o2
		call scanf, 0
		nop
                		

                !basically, branch not equals, so you want to be done
                !otherwise, it will run through the code, hitting the end
                !and going right back to 'loop' 


		!while(scanf(formati, %x, %y) == 2)
		cmp %o0,2
		bne done 
		nop

                !code was here
                
		!printf(formato, %o1, %o2, %o3)
		sethi %hi(formato), %l1 
		call printf,0
		or %l1, %lo(formato), %o0	

	ba loop
	nop
done:
	call exit, 0
	mov 0, %o0

Last edited by big_k105; Sep 27th, 2006 at 6:52 PM. Reason: Added Code Tags
sackarias is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
new program infinite loop problem codylee270 C 18 Jan 13th, 2006 12:52 AM
Problem with while loop... jch02140 C 6 Jul 30th, 2005 4:22 PM
Help in QBASIC (I think it's similar to VB) phoenix987 Visual Basic 3 May 9th, 2005 12:33 PM
Help with a QBASIC program phoenix987 Other Programming Languages 4 May 5th, 2005 12:27 PM
Problem with a while loop. Vengeance Java 2 Apr 30th, 2005 9:39 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:03 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC