MIPS Assembly - Dynamic Memory Problem
Hello everyone,
I'm very new to MIPS and I just can't understand how dynamic memory works. I just have the following problem about sequences: consider a variable integer (for instance, 0 < K < 10) and a sequence of N integers called A (input). We want to output another sequence B whose elements, for each index I in the interval [0 .. N-K-1], are the sum of the last K elements of sequence A in the interval [I .. I+K-1]. The array must be terminated when input 0 is given, but it will not be present in sequence B (I thought doing it li $v0, 10 syscall). The main problem I encountered is how I can output the sequence B only remembering the last K elements of sequence A, because a long sequence memorized in stack will just crash the execution of the program. So, if we have as input: 4 # K 97 77 51 -96 63 45 -23 26 -13 -42 -30 -95 47 -91 -12 -44 -10 53 -31 -71 0 # indicates end of sequence A, but it not belongs to A It will produce: 129 95 63 -11 111 35 -52 -59 -180 -120 -169 -151 -100 -157 -13 -32 -59 Another vague idea of mine is reading the input with li $v0, 5 syscall. |
Quote:
Quote:
|
The first idea my instructor said is about creating a vector of length K without memorizing it in the stack, because sequence B need to be printed while every line of sequence A is given: in the example, writing "4" (the value of K) it must return nothing, but if I subsequently put the first K values of the sequence A "97 77 51 -96" it returns the first value of B, "129".
|
Quote:
|
Given that you have already said that this is a homework problem, it's very important that you engage your instructor. Talk it over with him or her. In addition to giving you the help that you need, this will also give the instructor important feedback that can then be woven into an upcoming classroom session. "When we're standing there on the other side of that podium, we can't read your minds." If you're having trouble wrapping your head around this, "you're not the only one."
|
All times are GMT -5. The time now is 03:55 PM. |