i need help in writing MARIE program

Thread Starter

bright22

Joined Feb 23, 2015
9
hello everyone ..

i have an issue converting a C code to MARIE assembly language..
actually i have homework due this friday.. i tried to solve the problem ( i should write a MARIE program) but i couldn't so i started writing it in C
here it is:
do {

scanf("%d",&num);
if (num <0)
break ;

count++;
sum+=num;

if(num>large)

large=num;
}while (num>0);

printf("%d\n",count);
printf("%d\n",sum);
printf("%d\n",large);

the problem is obvious i should ask the user to enter a positive number(loop) once he hit a negative number the program must ends and calculate three things:
1- how many numbers he entered( excluding the negative one).
2- sum of all numbers.
3- largest number.

all i know about MARIE is how the commands work( input,output,skipcond...,halt,store,load..etc)
please help me i'm really desperately lost ..i appreciate any help in this

thanks!
 

Thread Starter

bright22

Joined Feb 23, 2015
9
for anyone who's wondering what i came up with :


loop, input

store num

skipcond 800

jump loop


count, output

sum , output

largest , output

halt

num , dec 0

count , dec 0

sum , dec 0

i know i should have a test for largest ,, and calculate the sum , count .. but i don't know how to do it
 

Thread Starter

bright22

Joined Feb 23, 2015
9
hello everyone ..

i have an issue converting a C code to MARIE assembly language..
actually i have homework due this friday.. i tried to solve the problem ( i should write a MARIE program) but i couldn't so i started writing it in C
here it is:

do {

scanf("%d",&num);
if (num <0)
break ;

count++;
sum+=num;

if(num>large)

large=num;
}while (num>0);

printf("%d\n",count);
printf("%d\n",sum);
printf("%d\n",large);


the problem is obvious i should ask the user to enter a positive number(loop) once he hit a negative number the program must ends and calculate three things:
1- how many numbers he entered( excluding the negative one).
2- sum of all numbers.
3- largest number.

all i know about MARIE is how the commands work( input,output,skipcond...,halt,store,load..etc)
please help me i'm really desperately lost ..i appreciate any help in this

HERE IS WHAT I CAME UP WITH :


input num /use inputs first number
loop , load count /
skipcond 800
jump loop
test, load count
add one /increment the counter ?
store count
loop,load sum /load the sum into ACC
add num
count, output
sum , output
largest , output
halt
num , dec 0
count , dec 0
sum , dec 0





thanks!

MOD NOTE: No need for multiple threads. I've brought this post into this thread since it has a later version of the attempt at the code.
 
Last edited by a moderator:

WBahn

Joined Mar 31, 2012
29,976
seems that i'm the only one here who doesn't get an answer :(
i tried to fix the above code please if any one can help i will really appreciate it ... I'm really clueless here
It's unreasonable to expect immediate answers to any post -- my first post on the forum took three weeks before it got it's first response (and it went on to garner a lot of discussion). It's not unusual at all for posts to sit for a day or two before they get an initial response. Keep in mind that people have jobs, they have families, they need to eat, they need to sleep. They aren't sitting around starting at AAC to see if there's a new post they can answer (it just seems like it, sometimes). So getting impatient after less than four hours is not going to get you anywhere.

The main reason that no one is jumping on your post is because there aren't very many people here that know anything about MARIE -- as I understand it it's a pretty obscure assembly language for a fictitious processor used for educational purposes only. All of that is fine, but it means that very few people will be familiar with it. I'm certainly not and I'm not willing to spend a lot of time learning it. If I can glean enough from your code attempt and your description and comments to offer suggestions I will, but you are going to have to describe what and why you are doing things pretty clearly to make that possible.

Starting with a high-level language solution is a reasonable place to start. With library functions like scanf() and printf(), don't expect to translate those directly as these represent a huge amount of code at the assembly level. Also, be sure that your high-level solution will actually work -- yours won't. Hint: What if the initial values at the memory locations used for the variables sum, count, and large are 8742, -653, and 91874 respectively?

Break the problem into very small tasks that can be put together to build your program. Perhaps you might consider these:

Get a value from the user and display it.

Get a value from the user and display it's absolute value.

Set a variable equal to the larger of the values stored in two other variables.

Tackle those and show the code -- if nothing else some of us can get an idea for the constructs available in MARIE to be of better assistance.
 

darrough

Joined Jan 18, 2015
86
Do you have a compiler/interpreter? Can you put your program in and see what happens? Things will go much faster if you have a compiler. Break it up. First just read the numbers and discard. Then add in to display the count. When that works then add in to display the sum. Finally add in to display the largest.

It seems like "input num" should be inside the loop. It looks like you only read one number.

Put some more comments. Maybe someone can figure it out.
 
Top