| sackarias |
Sep 27th, 2006 2:18 PM |
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
|