d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Lc-3 Assembly Help I Am Stuck > Creating A Function Solver
Add Reply New Topic New Poll
Member
Posts: 3,689
Joined: May 20 2011
Gold: 1,302.50
Dec 1 2015 02:30pm
I am writing a program that will evaluate a function of the form f(x)=(a*x^b)/c + (d*x^f)/g. a b c d f g are all constants that will be loaded into main memory from x5000 to x5005. The output of the program needs to be an array of f(x) that corresponds to x values from [-100,100], so 201 outputs that will be stored in main memory. I have had to write four subroutines for this program: one for multiplication, division, exponentiation, and one to calculate the entire function.

I am stuck on writing a subroutine to calculate the entire function. I need to generate my range of x values internally, however I have no idea how to do this and haven't been able to find any resources that are helpful. How can I do this?

If it helps I can post the code for my other subroutines.
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Dec 1 2015 06:45pm
is that your only problem? creating x from [-100,100]? so you already wrote the subroutine assuming x is a constant (eg: 1)? if not, start with that. then it should be a simple matter of looping through it
Member
Posts: 3,689
Joined: May 20 2011
Gold: 1,302.50
Dec 2 2015 10:21am
I have finished the program now, and everything works. I want to optimize my code. I generated values for x from [-100,100] as such:



LD R0, LABEL
LD R1, LABEL ;I used this for a comparison test
;subroutine here which calculates the function for current value of x
;
;
ADD R0, R0, #1 ;this increments x
ADD R2, R1, R0 ;if R1 - R0 > 0, program is done
BRp DONE
BRnz ;Calculate subroutine again



LABEL .FILL #-100


Doing it this way was simple enough. I am just wondering if there is an OPCODE that will generate an array of x values for me internally.

This post was edited by Krister on Dec 2 2015 10:27am
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Dec 2 2015 04:56pm
Quote (Krister @ Dec 2 2015 11:21am)

Doing it this way was simple enough. I am just wondering if there is an OPCODE that will generate an array of x values for me internally.


Not that I'm aware of. But why would you want to? Looping and incrementing by 1 sounds like a better approach
Member
Posts: 3,689
Joined: May 20 2011
Gold: 1,302.50
Dec 3 2015 05:13pm
If I can generate values internally through an OPCODE then it will reduce the instruction count.
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Dec 3 2015 08:44pm
Quote (Krister @ Dec 3 2015 06:13pm)
If I can generate values internally through an OPCODE then it will reduce the instruction count.


allocating an array of length 201 is easy. set .ORIG label, but it's not an opcode. or you can have a ton of labels with .FILL for your inputs. but it's still not a good idea to store all your inputs in memory if you can generate them instead.

This post was edited by carteblanche on Dec 3 2015 08:48pm
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll