# Help needed with simple assembly program.

Page 1 of 1

## 3 Replies - 2826 Views - Last Post: 02 February 2009 - 06:35 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=84255&amp;s=4da8da7d00590dddead0356f1c5bfad2&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 mattpd

Reputation: -1
• Posts: 50
• Joined: 15-March 08

# Help needed with simple assembly program.

Posted 02 February 2009 - 06:03 PM

Hello. New to programing, and looking for some help with SPARC assembly. My assignment is to find the maximum value of y = x^6 – 14x^2 +56x, for x=-2,-1,0,1,2,3,and 4. In other words I need to find the maximum y value, and store it in ymax, and store the corresponding x value in xmax. I have already completed and debugged the main part of the program that computes all the values, but I am confused about how to determine the largest values.
I'm guessing that after every run of the loop, you would take the result for y and compare it to what is in ymax. If y is larger than ymax, then it should be replaced by y, and the loop run again. Im just not sure how to do this in assembly though. Also, I have no clue how to find the x value that corresponds with the largest y. I already know that the largest x will produce the largest y, just by looking at the equation. But my goal is to find the x value that corresponds to the largest y value, so just finding the largest x will not do. Here is what I have so far:

```/*

cs32114
CSC 3210
Program #2
Due Date Feb 10, 2009
This program will calculate y=(x^6)-(14x^2)+56x for x=-2,-1,0,1,2,3,4
*/

/*Constants are:*/

define(a2,56)
define(a1,14)

/*X and Y variable*/
define(x_r,l0)
define(y_r,l1)

define(xmax, l2)
define(ymax, l3)

.global main
main:
save  %sp, -96, %sp
mov -2, %x_r

.global loop
loop:
cmp %x_r, 5
bge done

mov %x_r, %o0 !This will compute x^6, the first part of equation
mov %x_r, %o1
call .mul
nop
mov %x_r, %o1
call .mul
nop
mov %x_r, %o1
call .mul
nop
mov %x_r, %o1
call .mul
nop
mov %x_r, %o1
call .mul
nop
mov %o0, %y_r !completes first part of equation and stores in y.

mov %x_r, %o1 !This will computer 14x^2
mov %x_r, %o0
call .mul
nop
mov a1, %o1
call .mul
nop
sub %y_r, %o0, %y_r !completes first two parts of equation

mov a2, %o0  !computes 56x.
mov %x_r, %o1
call .mul
nop
add %y_r, %o0, %y_r !equation complete. Store result in y_r.

ba  loop
nop

done:
mov 1, %g1
ta 0

```

This post has been edited by mattpd: 02 February 2009 - 06:35 PM

Is This A Good Question/Topic? 0

## Replies To: Help needed with simple assembly program.

### #2 Auzzie

Reputation: 43
• Posts: 573
• Joined: 20-January 09

## Re: Help needed with simple assembly program.

Posted 02 February 2009 - 06:15 PM

first thing i would like to know is what assembly are you using for this? i.e. x8086 because last time i checked you were meant to define it as well i dont recognise the registers

### #3 mattpd

Reputation: -1
• Posts: 50
• Joined: 15-March 08

## Re: Help needed with simple assembly program.

Posted 02 February 2009 - 06:31 PM

Forgive me I am still a noob, I didn't know there were differences. The book I am using is called SPARC Architecture, so I assume it is SPARC assembly language. The registers I used were local registers %l0-%l17 also known as %r16-%r23.

### #4 Auzzie

Reputation: 43
• Posts: 573
• Joined: 20-January 09

## Re: Help needed with simple assembly program.

Posted 02 February 2009 - 06:35 PM

Well the only thing i know about SPARC is that it is a sun microsystems based ASM, it isnt one that i know by try this manual