Asked by Anonymous
I'm trying to write a program for this piece wise function using CPU sim.its really argent...
f(n) = n^5 (n<0)
10 (n=0)
n^2 -2n +5 (n>0)
i have worte this program bust still give error on cpu simulator..
please can you help me correct this error.
Start: read 0 ; read n
store 42 ; store n
jump 26 ; if n is < 0 go to line 26
jump 38 ; else if u = 0 go to 38
load 46 ; else
multiply 46 ; 3xn
store 40 ; store temp result
load 42 ; load n
multiply 42 ; n2
subtract 40 ; n^2 x 2n +5
add 48 ; n^2 x 3n
write 0 ; output f(n)
stop 0 ; stop
load 42 ; load n
multiply 42 ; nxn
multiply 42 ; nxnxn
multiply 42 ; nxnxnxn
multiply 42 ; nxnxnxnxn
Done: jump 22 ; go to output
load 50 ; load 175
jump 22 ; goto output
Data: data 0 ; storage for n (38)
data 0 ; temp storage(40)
data 2 ; constant 2(42)
data 5 ; const 5(44)
data 175 ;const 175 (46)
f(n) = n^5 (n<0)
10 (n=0)
n^2 -2n +5 (n>0)
i have worte this program bust still give error on cpu simulator..
please can you help me correct this error.
Start: read 0 ; read n
store 42 ; store n
jump 26 ; if n is < 0 go to line 26
jump 38 ; else if u = 0 go to 38
load 46 ; else
multiply 46 ; 3xn
store 40 ; store temp result
load 42 ; load n
multiply 42 ; n2
subtract 40 ; n^2 x 2n +5
add 48 ; n^2 x 3n
write 0 ; output f(n)
stop 0 ; stop
load 42 ; load n
multiply 42 ; nxn
multiply 42 ; nxnxn
multiply 42 ; nxnxnxn
multiply 42 ; nxnxnxnxn
Done: jump 22 ; go to output
load 50 ; load 175
jump 22 ; goto output
Data: data 0 ; storage for n (38)
data 0 ; temp storage(40)
data 2 ; constant 2(42)
data 5 ; const 5(44)
data 175 ;const 175 (46)
Answers
There are no human answers yet.
There are no AI answers yet. The ability to request AI answers is coming soon!
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.