-4

编写、运行和测试一个 MARIE 汇编语言程序。该程序应允许用户输入 8 个数字并找出最小和最大的数字。然后程序应该打印最小的数字和最大的数字。数字仅限于整数,可以是正数、负数或零。您不必提示输入或标记输出。

  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

我正在尝试打印最小值和最大值。这将只打印最大值。谁能帮我让它打印给定数组中的最小值。

4

1 回答 1

2

仅供参考,这是您向我们展示的代码,在过去十年中略有修改,网址:https ://www.justanswer.com/computer-programming/38kwi-marie-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

从互联网上复制一些代码是不合适的,这些代码已经流传了 10 多年,代表你写了它,假装你理解它,你只需要解决一件小事,这很明显是这段代码的实际作者。

作弊和剽窃不符合本网站和大多数其他网站的精神。

在这个大流行时期,许多教师正在转向他们不熟悉的在线方法。学生也无法获得他们需要的指导。所以,我同情将所有参与。

但我们绝不能屈服于欺骗的诱惑。为什么不试试别的?就像学习你发现的这段代码实际上做了什么?研究 Skipcond 可以做什么。大多数突然过渡到在线的课程也提供了额外的时间来完成作业。利用这段时间学习一些东西。

于 2020-04-26T00:36:33.507 回答