MARIE Assembly Language

Discussion in 'Programmer's Corner' started by rshackd, Nov 24, 2012.

Thread Status:
Not open for further replies.
  1. rshackd

    Thread Starter New Member

    Nov 24, 2012
    4
    0
    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.
     
  2. atferrari

    AAC Fanatic!

    Jan 6, 2004
    2,838
    941
    Nice to meet you, Marie!
     
  3. rshackd

    Thread Starter New Member

    Nov 24, 2012
    4
    0
    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
     
  4. tshuck

    Well-Known Member

    Oct 18, 2012
    3,527
    675
  5. WBahn

    Moderator

    Mar 31, 2012
    20,234
    5,757
    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).
     
    bance likes this.
  6. rshackd

    Thread Starter New Member

    Nov 24, 2012
    4
    0
    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.
     
  7. SgtWookie

    Expert

    Jul 17, 2007
    22,194
    1,764
    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.
     
  8. WBahn

    Moderator

    Mar 31, 2012
    20,234
    5,757
    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.
     
  9. WBahn

    Moderator

    Mar 31, 2012
    20,234
    5,757
    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.
     
  10. atferrari

    AAC Fanatic!

    Jan 6, 2004
    2,838
    941
    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
     
  11. WBahn

    Moderator

    Mar 31, 2012
    20,234
    5,757
    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.
     
  12. rshackd

    Thread Starter New Member

    Nov 24, 2012
    4
    0
    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.
     
  13. jayrond1

    New Member

    Nov 25, 2012
    1
    0
    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!
     
  14. dba mcitp

    New Member

    Nov 15, 2014
    2
    0
    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
     
  15. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,971
    616
    Oh good, you found the thread from 2 years ago.
     
  16. takao21203

    AAC Fanatic!

    Apr 28, 2012
    3,648
    477
  17. bertus

    Administrator

    Apr 5, 2008
    17,137
    3,008
    closed due to old age.

    Please start a new thread if you have a question.
    You can always refer to this thread.
     
Loading...
Thread Status:
Not open for further replies.