![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Jan 2006
Posts: 58
Rep Power: 3
![]() |
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, %o0Last edited by sackarias; Sep 27th, 2006 at 2:46 PM. |
|
|
|
|
|
#2 | |
|
Hobbyist Programmer
|
Quote:
__________________
"Time is an illusion. Lunchtime doubly so." -the late, great Douglas Adams |
|
|
|
|
|
|
#3 |
|
Programmer
Join Date: Jan 2006
Posts: 58
Rep Power: 3
![]() |
It does and I got it to work now. Thanks a lot.
|
|
|
|
|
|
#4 |
|
PFO Founder
![]() ![]() |
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. |
|
|
|
|
|
#5 |
|
Programmer
Join Date: Jan 2006
Posts: 58
Rep Power: 3
![]() |
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, %o0Last edited by big_k105; Sep 27th, 2006 at 6:52 PM. Reason: Added Code Tags |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |