The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
The Guiding Principles and New Rules document is now in effect.

UNIX Algorithm Help

Raziel078Raziel078 Registered User regular
edited October 2007 in Help / Advice Forum
so I'm writing a program in Unix and the thing is I can't figure out this last little bit and its a little clutch the assignment is to write a program that tests x values between -2 and 8 for the function X^3 - 14x^2 + 56x - 64. I just can't figure how get it so that it compares the values after the function is finished and then storing the higher one and holding onto it through the next loop and comparing again. Help I could just cheesedick my way through it because I know the answers to the eq but I want a solid blind way of testing.

thanks
oh heres my code so far

define (a1, 14)
define (a2, 56)
define (a3, 64)
define (x_r, -2)

.global main
main:
save %sp, -96, %sp

.global loop
loop:
clr %l0 !initialize %l0 to zero
mov %x_r, %o0 !move x into %o0
call .mul !execute x^2
mov %x_r, %o1

mov %o0, %l2 !store x^2 in %l2

mov %x_R, %O1 !move x into %o1
call .mul !execute x^3
nop

mov %o0, %l3 !store x^3 in %l3
mov %l2, %o0 !moves x^2 into %o0
call .mul
mov %a1, %o1 !moves a1 into %o1

sub %l3, %l2, %l2 !X^3 - 14x^2 stored in %l2
mov %a2, %o0
call .mul
mov %x_r, %01

add %l2, %o0, %l2 !%l2 + 56x stored in %l2
sub %l2, %a3, %l2 !%l2 - 64 stored in %l2

add %x_r, 1, %x_r !x++

cmp %l2, %l0

I would like to put something clever and about me but I fear my company will find it
Raziel078 on

Posts

  • Raziel078Raziel078 Registered User regular
    edited October 2007
    please

    Raziel078 on
    I would like to put something clever and about me but I fear my company will find it
  • LewishamLewisham Registered User regular
    edited October 2007
    a) we don't do your homework - Read the rules.
    b) You haven't mentioned what language you are writing in. I'm going to assume Assembly (which has nothing to do with UNIX). The point about Assembly is it is very difficult to figure out what is going on without sitting down and reading the whole of it. Which people aren't going to do.

    The best thing you can do is sit down with a pen and paper and go through it's execution step-by-step. If you honestly don't "get" it, sit down with a book or go and talk to your TA/Professor during office hours.

    Lewisham on
  • mastmanmastman Registered User regular
    edited October 2007
    can't you just initalize a permanent solution variable to something really low at the start of the program. and each iteration through compare it and the function's outcome and store the higher value in the permanent solution variable. That way the higher value is passed on and compared to each function's result?


    sorry, I can't spend the time right now to read your code.

    mastman on
    ByalIX8.png
    B.net: Kusanku
  • /../.. Registered User regular
    edited October 2007
    Write your program in C then use the -S flag in GCC to automatically put out the assembly code version of it.

    /.. on
  • MonoxideMonoxide Registered User, ClubPA regular
    edited October 2007
    I believe he's writing it in SPARC assembly though I really have no time to read through this code, especially because it's not documented whatsoever.

    Protip: Assembly is hard as fuck to interpret line by line, especially if you're using subroutines so you're not rewriting the same code over and over. Document it.

    Monoxide on
Sign In or Register to comment.