LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-07-2018, 02:59 PM   #1
A. E. Mauri
LQ Newbie
 
Registered: Apr 2018
Posts: 2

Rep: Reputation: Disabled
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.
 
Old 04-07-2018, 08:10 PM   #2
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,338

Rep: Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501
Quote:
Originally Posted by A. E. Mauri View Post
Hello everyone,
I'm very new to MIPS and I just can't understand how dynamic memory works.
If you're instructor/textbook hasn't explained how it works yet, the problem shouldn't require dynamic memory.

Quote:
I just have the following problem about sequences: consider a variable integer (for instance, 0 < K < 10)
[...]
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.
It sounds like you can assume K is less than 10; saving up to 10 elements on the stack shouldn't crash.
 
Old 04-08-2018, 05:26 AM   #3
A. E. Mauri
LQ Newbie
 
Registered: Apr 2018
Posts: 2

Original Poster
Rep: Reputation: Disabled
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".
 
Old 04-08-2018, 07:59 AM   #4
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,338

Rep: Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501
Quote:
Originally Posted by A. E. Mauri View Post
The first idea my instructor said is about creating a vector of length K without memorizing it in the stack
Yes, you could put it on the stack also, but it's a bit more complicated that way. Have you learned how to declare static variables?
 
Old 04-08-2018, 08:54 AM   #5
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 9,078
Blog Entries: 4

Rep: Reputation: 3165Reputation: 3165Reputation: 3165Reputation: 3165Reputation: 3165Reputation: 3165Reputation: 3165Reputation: 3165Reputation: 3165Reputation: 3165Reputation: 3165
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."
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
detour in mips assembly ineya Programming 2 05-15-2010 04:56 PM
[SOLVED] dynamic memory allocation in assembly hda7 Linux - Software 9 10-28-2009 08:25 AM
MIPS: assembly language query ashlesha Linux - Newbie 2 09-11-2006 11:05 PM
MIPS assembly question Gnute Programming 1 08-24-2004 05:33 PM
MIPS assembly fenriswolf Programming 0 10-17-2001 03:01 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration