# [SOLVED] MIPS Assembly - Display numbers between two number??



## huggies12345 (Oct 12, 2008)

Hi,

I am using MARS.

I have an integer stored in $a1 and another integer stored in $a2.

I need to display the numbers inbetween those two integers using a for loop

E.g. If $a1 is 1 and $a2 is 10 then it would display 12345678910

Does anyone know how to do this??

Thanks.


----------



## Ninjaboi (Dec 27, 2010)

*Re: MIPS Assembly - Display numbers between two number??*

Hello huggies12345!

In the MARS programming language, there is no support for a 'for' loop. Please see the MARS language documentation on the matter:

Frequently Asked Questions — Mars v0.3.1 documentation

You can however use a 'while' loop to do the job. A sample of a while loop in action can be found here:

~/uni/research/mars/trunk/samples/bfs.mar.html

I've never used the language before, but the jargon of the program would be something like this:


```
$a1 = 1.
$a2 = 10.
numinc = $a1.
 
[DISPLAY $a1]
WHILE numinc is NOT EQUAL to $a2:
     numinc + 1.
     [DISPLAY numinc]
#LOOP UNTIL $a1 IS EQUAL to $a2.
```
EDIT: Changed the jargon code slightly to fit with exactly what you wanted to accomplish.


----------



## huggies12345 (Oct 12, 2008)

*Re: MIPS Assembly - Display numbers between two number??*

Thanks.

Just sorted it now.


----------



## JayboyM (Jan 13, 2012)

Im also using MARS MIPS and I have the same problem, I have two numbers stored in $s0 and $s1 (these are numbers inputted by the user) and I want to display the numbers in-between them? I'm really stuck and not even sure where to begin

any help would be appreiciated  thank you


----------



## Ninjaboi (Dec 27, 2010)

Hello JayboyM!

Please see the pseudo-code from above ( altered based on what you said ):


```
$s0 = (INPUT).
$s1 = (INPUT).
numinc = $a1.
 
[DISPLAY $a1]
WHILE numinc is NOT EQUAL to $s1:
     numinc + 1.
     [DISPLAY numinc]
#LOOP UNTIL numinc IS EQUAL to $s1.
```
Implement that using MARS and it's syntax and that should do the job you require.


----------

