MARIE Assembly Language

Status
Not open for further replies.

Thread Starter

rshackd

Joined Nov 24, 2012
4
Need some assistance with MARIE assembly language program. I have written a program to sort through an array of 5 numbers and count the number of negative and positive numbers, now I need to sort and arrange them in ascending order. I cannot find a way to get them to sort and gather an output in ascending order. Please see my code below. Any assistance would be greatly appreciated.
ORG 100
If, LoadI Addr /Load element found at address Addr.
Skipcond 800 /IF AC > 0, skip to next instruction.
Jump Else /Otherwise, Jump to Else.

Then, Load Addr /Load element in at Addr.
Add One /NNeg + 1
Store Addr /Store Addr.
Load NNeg /Load NNeg.
Add One /Increment NNeg by 1.
Store NNeg /Store NNeg count.
Load N /Load Array number.
Subt One /Subtract 1 from Array.
Store N /Store new Array count.
Skipcond 400 /If AC = 0, Halt Program.
Jump If /Jump to If.

Else, Load Addr /Load element in Addr
Add One /Add 1 to Neg
Store Addr /Store Addr.
Load Neg /Load Neg.
Add One /Increment Neg by 1.
Store Neg /Store Neg count.
Load N /Load Array number.
Subt One /Subtract 1 from Array.
Store N /Store new Array count.
Skipcond 400 /If AC = 0, Halt Program.
Jump If /Jump to If.

EndIf, Halt /Terminate Program.

One, Dec 1 /Set One to 1.

N, Dec 5 / Number of array elements.
NNeg, Dec 0 / Number of values >= 0.
Neg, Dec 0 / Number of values < 0.

Addr, Hex 11F /Beginning Address.
Dec 18 /First element in Array.
Dec -3 /Second element in Array.
Dec 10 /Third element in Array.
Dec 1 /Fourth element in Array.
Dec -3 /Fifth element in Array.
 

Thread Starter

rshackd

Joined Nov 24, 2012
4
I manipulated the MARIE program and took out the neg and pos and attempted the sorting with new values and below is what I have, however, I cannot get them to sort appropriately.

ORG 100
Load Addr /Load address of first number
Store Next /Store this address is our Next pointer
Load Num /Load the number of items to be sorted
Subt One /Decrement
Store Ctr /Store this value in Ctr to control looping
Loop, Load Sum /Load the Sum into AC
AddI Next /Add the value pointed to by location Next
Store Sum /Store this sum
Load Next /Load Next
Add One /Increment by one to point to next address
Store Next /Store in our pointer Next
Load Ctr /Load the loop control variable
Subt One /Subtract one from the loop control variable
Store Ctr /Store this new value in loop control variable
Skipcond 000 /If control variable < 0, skip next instruction
Jump Loop /Otherwise, go to Loop
Halt /Terminate program
Addr, Hex 200 /Numbers to be sorted start at location 200
Next, Hex 0 /A pointer to the next number to add
Num, Dec 6 /The number of values to sort
Sum, Dec 0 /The sum
Ctr, Hex 0 /The loop control variable
One, Dec 1 /Used to increment and decrement by 1
Dec 18
Dec -3
Dec 10
Dec 1
Dec -3
Dec 0
 

WBahn

Joined Mar 31, 2012
30,055
Have you traced the execution? Pretend you are the processor and execute your program manually, keeping track of what is actually happening (and not what you want to have happen).
 

Thread Starter

rshackd

Joined Nov 24, 2012
4
Yes, I've attempted the review of the bubble sort, the problem is that MARIE is limited in its language and I can't figure out how to use it with the limited options. I've stepped through the process but can't figure out how to store it and place them in ascending order without interferring with the manipulation of the code. Been doing JAVA for some time now and I think that's the problem, it's hard to go back to BASIC. I need them to place themselves in the appropriate order without my intervention.
 

SgtWookie

Joined Jul 17, 2007
22,230
Isn't this homework that was assigned to the class by a teacher/professor/instructor, as Marie is an instructional assembler language?

We can't do your homework for you, as we would not be doing anyone a favor - especially you.
 

WBahn

Joined Mar 31, 2012
30,055
Yes, I've attempted the review of the bubble sort, the problem is that MARIE is limited in its language and I can't figure out how to use it with the limited options. I've stepped through the process but can't figure out how to store it and place them in ascending order without interferring with the manipulation of the code. Been doing JAVA for some time now and I think that's the problem, it's hard to go back to BASIC. I need them to place themselves in the appropriate order without my intervention.
1) What do you mean "without interferring with the manipulation of the code"?

2) What do you mean "place themselves ... without my intervention"?

3) If you have stepped through the code, then why don't you explain at what point the code stops doing what it is supposed to be doing and starts doing something else? Don't make us do everything from scratch -- this is YOUR code and YOUR assignment. We are willing to help with YOUR efforts to solve YOUR problem, but don't expect us just to do YOUR work for you.
 

WBahn

Joined Mar 31, 2012
30,055
Have you written out a clear pseudocode description of your algorithm? That's a good place to start. Another is to write the program in C (or other suitable language that doesn't do too much of your thinking for you).

Then map out the control structures in MARIE that match your pseudocode or high level language description. Then work out the MARIE sequences that implement each statement in your description.
 

atferrari

Joined Jan 6, 2004
4,769
Have you traced the execution? Pretend you are the processor and execute your program manually, keeping track of what is actually happening (and not what you want to have happen).
The manual from Ronald Zacks teaching how to program the Z80 (one of the two best technical books ever), encouraged that technique

In 15 days, including the voyage from Curaçao to Recalada, just by doing that, I was able to program that micro. I was a busy Chief Officer and knew nothing about micros.

I used to draw the registers at the right of every line of code even those that did not change, to make evident the progress. Say that I had "invented" the manual MPLAB SIM! :p :p :p
 

WBahn

Joined Mar 31, 2012
30,055
Simulators (and lots of other things) are wonderful TOOLS. But, in all too many places, they have replaced THINKING and undermined any semblence of true understanding of what is going on. It's a shame, but it's also pretty much inevitable.
 

Thread Starter

rshackd

Joined Nov 24, 2012
4
Thanks, stayed up til 3am and was able to get it to work by translating my JAVA into MARIE. Appreciate everyone's help and suggestions.
 

jayrond1

Joined Nov 25, 2012
1
It sounded like you were able to come up with a solution. Do you mind providing some insight on the sorting algorithm you used? I am having similar problems that you had earlier..

Any help would be great. Thank you!
 

dba mcitp

Joined Nov 15, 2014
2
You are to write an assembly language program for the MARIE ISA. The program will sort an array of integers in ascending order.The general structure of the assembly language source code is illustrated in figure 1. Note that your code will precede the data area.
ORG 100
/Your program goes here
HALT
Addr, HEX 200 /Address of 1st array elements
N, DEC 6 /Number of array elements
DEC 18 /First Value
DEC -3
DEC 10
DEC 1
DEC -3
DEC 0
Figure 1 - Code template and definition of data area
 

shteii01

Joined Feb 19, 2010
4,644
You are to write an assembly language program for the MARIE ISA. The program will sort an array of integers in ascending order.The general structure of the assembly language source code is illustrated in figure 1. Note that your code will precede the data area.
ORG 100
/Your program goes here
HALT
Addr, HEX 200 /Address of 1st array elements
N, DEC 6 /Number of array elements
DEC 18 /First Value
DEC -3
DEC 10
DEC 1
DEC -3
DEC 0
Figure 1 - Code template and definition of data area
Oh good, you found the thread from 2 years ago.
 
Status
Not open for further replies.
Top