-4

Write, run, and test a MARIE assembly language program.The program should allow the user to input 8 numbers and find the smallest and the largest. The program should then print the smallest number and the largest number. Numbers are limited to integers, and can be positive, negative, or zero. You do NOT have to prompt input or label output.

  ORG 100   / Calculation of the maximum

  Load First /loading 1st array member

  Store Next /address of next pointer,stores

  Load Array /Loading 1st element

  Store Max /maximum value with 1st element

  Loop, Clear

  AddI Next /Load next element!

  Subt Max /Comparing with the maximum once

  Skipcond 000 /If negative ->skip

  Jump NewMax /If not negative ->max value

  NextIdx, Load Next

  Add One /pointer++

  Store Next

  Load Count /counter--

  Subt One

  Skipcond 800 /counter is positive ->same proceeding

  Jump Print /else - printing the result

  Store Count /counter decresed and stored

  Jump Loop

  NewMax, Clear / new maximum value

  AddI Next

  Store Max

  Jump NextIdx

  Print, Load Max

  Output

  Halt /Terminate program

  First, Hex 11E /starting is location 11E(change as per...,as code changes don't forget to change it too)

  Next, Hex 0 /next element index (memory location)

  Max, Dec 0 /maximum value

  Count, Hex 8 / loop counter decreases

  One, Dec 1 /Loop stops

  Array, Dec -5
  Dec 15
  Dec -17
  Dec 20
  Dec -23
  Dec 12
  Dec 130
  Dec -12

I am trying ti print minimum and maximum value. This will print only max value. Can anyone help me out to make it print minimum value from the given array.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Krixnaas
  • 71
  • 2
  • 13
  • Do you understand how this code computes the max? – Erik Eidt Apr 25 '20 at 14:24
  • Yes. I do. But I am stuck with skipcond. – Krixnaas Apr 25 '20 at 22:25
  • That makes no sense. Skipcond can do it all. – Erik Eidt Apr 25 '20 at 23:36
  • You mean? @ErikEidt can you please explain it! – Krixnaas Apr 26 '20 at 00:12
  • 2
    My friend, you have posted some code you found on the internet dating as far back as 3/10/2010 asking us to change it for your purposes. You haven't bothered to understand how the code works as is, you just want us to solve your homework problem. Hmm.. (https://www.justanswer.com/computer-programming/38kwi-m-a-r-i-e-assembly-language-code-find-maximum.html). This is a disingenuous way to ask for help. – Erik Eidt Apr 26 '20 at 00:32
  • 1
    If I'm wrong, I now apologize in advance, but the code from back then is the same as what you've posted and the chances are low that you came up with the same algorithm, comments, and label names. I realize that this code may be circulating so you didn't necessarily get it from here. But I stand by my point. – Erik Eidt Apr 26 '20 at 00:33
  • 1
    @Krixnaas so you are a CSU student. – Amrit Tiwari Apr 26 '20 at 05:03

1 Answers1

2

FYI, here's the code you're showing us, just slightly modified over the last decade, url: https://www.justanswer.com/computer-programming/38kwi-m-a-r-i-e-assembly-language-code-find-maximum.html:

    ORG 100 / Calculate maximum
    Load First /Load address of first array member
    Store Next /Store this address is our Next pointer
    Load Array /Load first element
    Store Max /Initialize MAX value with 1st element
    Loop, Clear
    AddI Next /Load next element, Inderect addressing!
    Subt Max /Compare with Max
    Skipcond 000 /If Negative - skip to the next element
    Jump NewMax /If not negative - we have a new maximum - initialize it
    NextIdx, Load Next
    Add One /Increase array pointer by 1
    Store Next
    Load Count /Decrease counter
    Subt One
    Skipcond 800 /If the counter is Positive - proceed to the Loop cycle
    Jump Print /Else - output result
    Store Count /Store decreased counter
    Jump Loop
    NewMax, Clear /Store new maximum
    AddI Next
    Store Max
    Jump NextIdx
    Print, Load Max
    Output
    Halt /Terminate program
    First, Hex 11E /Array elements start at location 11E, if you change code, you should fix this value
    Next, Hex 0 /Previous Next element index (memory location)
    Max, Dec 0 /The maximum value
    Count, Hex 8 /The loop counter (will decrease)
    One, Dec 1 /Loop step
    Array, Dec -1
    Dec 10
    Dec -15
    Dec 25
    Dec -25
    Dec 120
    Dec 13
    Dec -10

It is inappropriate to copy some code from the internet, that's been floating around for over 10 years, represent that you wrote it, pretend you understand it, and you just need one little thing solved, something that would be obvious this code's actual author.

Cheating and plagiarism are not in the spirit of this website and most others.

In this time of the pandemic, many teachers are transitioning to online methods unfamiliar to them.  Students also do not have access to the the instruction they need.  So, I sympathize will all involved.

But we must not give in to the temptation to cheat.  Why not try something else?  Like learning what this code you found actually does?  Study up on what Skipcond can do.  Most coursework that has suddenly transitioned to online is also offering extra time to complete assignments.  Use that time to learn something.

Erik Eidt
  • 23,049
  • 2
  • 29
  • 53
  • +1 for finding the original source, but I don't see any claim in the original question that the OP *wrote* that code. It seemed pretty obvious to me when I first read the question this was just some code they found but didn't understand. As you say it would hopefully be clear how to update a min as well as a max in the loop for someone able to write this in the first place. – Peter Cordes Apr 27 '20 at 06:32
  • Like you, I have huge doubts about the OP's claim to understand how it computes a max if they don't understand skipcond. But plagiarism might be too strong a claim here, just the usual optimism that someone else will do work for them so they don't have to understand it. But yes, after the initial post, that comment which claims they understand it seems like deception, and that's not ok. – Peter Cordes Apr 27 '20 at 06:34
  • 1
    @PeterCordes, you are right, of course. Though I did stop short of actually accusing the OP of plagiarism, however, I suspect they are on that path, and I don't want us to participate in that eventuality, should it go that way. – Erik Eidt Apr 27 '20 at 16:44
  • Oh right, yeah that's fair. Little doubt they were planning to hand in a copy of something that someone posted as an answer. – Peter Cordes Apr 27 '20 at 21:15