Help with program in MARIE assemby

Discussion in 'Homework Help' started by Evilsithgirl, Nov 8, 2009.

  1. Evilsithgirl

    Thread Starter New Member

    Nov 8, 2009
    3
    0
    Hello. I have this problem to collect 8 numbers from the user and find which one is the lowest and which is the highest. I tried to perform this task by using 16 if/else statements but the compiler complained, saying "statement label must be unique". Here is what i have now:

    Code ( (Unknown Language)):
    1.  
    2.  Input
    3.  Store  Num1
    4.  Input
    5.  Store  Num2
    6.  Input
    7.  Store  Num3
    8.  Input
    9.  Store  Num4
    10.  Input
    11.  Store  Num5
    12.  Input
    13.  Store  Num6
    14.  Input
    15.  Store  Num7
    16.  Input
    17.  Store  Num8
    18. If, Load  Num1
    19.  Subt  Num2
    20.  Skipcond 800
    21.  Jump  Else
    22. Then, Load  Num1
    23.  Store  Lowest
    24. Else, Load  Num2
    25.  Store  Lowest
    26. If, Load  Lowest
    27.  Subt  Num3
    28.  Skipcond 800
    29.  Jump  Else
    30. Then, Load  Lowest
    31.  Store  Lowest
    32. Else, Load  Num3
    33.  Store  Lowest
    34. If, Load  Lowest
    35.  Subt  Num4
    36.  Skipcond 800
    37.  Jump  Else
    38. Then, Load  Lowest
    39.  Store  Lowest
    40. Else, Load  Num4
    41.  Store  Lowest
    42. If, Load  Lowest
    43.  Subt  Num5
    44.  Skipcond 800
    45.  Jump  Else
    46. Then, Load  Lowest
    47.  Store  Lowest
    48. Else, Load  Num5
    49.  Store  Lowest
    50. If, Load  Lowest
    51.  Subt  Num6
    52.  Skipcond 800
    53.  Jump  Else
    54. Then, Load  Lowest
    55.  Store  Lowest
    56. Else, Load  Num6
    57.  Store  Lowest
    58. If, Load  Lowest
    59.  Subt  Num7
    60.  Skipcond 800
    61.  Jump  Else
    62. Then, Load  Lowest
    63.  Store  Lowest
    64. Else, Load  Num7
    65.  Store  Lowest
    66. If, Load  Lowest
    67.  Subt  Num8
    68.  Skipcond 800
    69.  Jump  Else
    70. Then, Load  Lowest
    71.  Store  Lowest
    72. Else, Load  Num8
    73.  Store  Lowest
    74. If, Load  Num1
    75.  Subt  Num2
    76.  Skipcond 800
    77.  Jump  Else
    78. Then, Load  Num2
    79.  Store  Highest
    80. Else, Load  Num1
    81.  Store  Highest
    82. If, Load  Highest
    83.  Subt  Num3
    84.  Skipcond 800
    85.  Jump  Else
    86. Then, Load  Num3
    87.  Store  Highest
    88. Else, Load  Highest
    89.  Store  Highest
    90. If, Load  Highest
    91.  Subt  Num4
    92.  Skipcond 800
    93.  Jump  Else
    94. Then, Load  Num4
    95.  Store  Highest
    96. Else, Load  Highest
    97.  Store  Highest
    98. If, Load  Highest
    99.  Subt  Num5
    100.  Skipcond 800
    101.  Jump  Else
    102. Then, Load  Num5
    103.  Store  Highest
    104. Else, Load  Highest
    105.  Store  Highest
    106. If, Load  Highest
    107.  Subt  Num6
    108.  Skipcond 800
    109.  Jump  Else
    110. Then, Load  Num6
    111.  Store  Highest
    112. Else, Load  Highest
    113.  Store  Highest
    114. If, Load  Highest
    115.  Subt  Num7
    116.  Skipcond 800
    117.  Jump  Else
    118. Then, Load  Num7
    119.  Store  Highest
    120. Else, Load  Highest
    121.  Store  Highest
    122.  Halt
    123. If, Load  Highest
    124.  Subt  Num8
    125.  Skipcond 800
    126.  Jump  Else
    127. Then, Load  Num8
    128.  Store  Highest
    129. Else, Load  Highest
    130.  Store  Highest
    131.  Load  Lowest
    132.  Output
    133.  Load  Highest
    134.  Output
    135.  Halt
    136. Num1, Dec  0
    137. Num2, Dec  0
    138. Num3, Dec  0
    139. Num4, Dec  0
    140. Num5, Dec  0
    141. Num6, Dec  0
    142. Num7, Dec  0
    143. Num8, Dec  0
    144. Lowest, Dec  0
    145. Highest, Dec  0
    146.  
    What is wrong with my code? also:
    I was wondering if there was a way to loop through all 8 numbers to find the lowest and the highest without having to use 16 if/else statements.

    Thank you in advance
     
  2. beenthere

    Retired Moderator

    Apr 20, 2004
    15,815
    282
    While the language, MARIE, is a mystery, it appears that you have made some fundamental errors (or they would be in every other language).

    Your Input statement does not specify what to input, or from what source.

    You tell the simulator to Store the input, but do not specify a location.

    Your conditional statement do not appear to be valid. The usual convention is IF - Then, Else. So an evaluation of Num1 might appear as:

    IF Num1 > 0
    THEN GOSUB EVAL ;The subroutine does something
    ELSE Flag 1 = 0 ;Flag 1 at 0 means Num1 is not the largest

    I might also expect that some register be explicitly loaded with the value of Num1, which would be the label for a memory storage location. That is the fun part of not having the instruction set of MARIE, but knowing how high level languages get coded.
     
  3. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    I am unfamiliar with MARIE Assembly Language.

    However, in most other assembly languages, labels begin in column 1 (ie: no space before the label).

    Since your If, Then, and Else statements begin in column 1, the Assembler is interpreting them as labels rather than program statements.

    I'll bet that if you insert at least one space before those statements, the Assembler will no longer complain about non-unique labels.

    Hint:
    Initialize the variable "Lowest" to the highest value possible, and "Highest" to the lowest possible value. IE: if Marie uses 8-bit signed integers, initialize Lowest to 32767 dec, and Highest to -32768 dec.
     
  4. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    I haven't been able to find a language reference for it either; it appears to only be published in certain textbooks.

    This would have to be something that someone with the language reference material would have to research. I feel that it's likely with no operand specified, the input is from the keyboard by default, with the result being placed in the accumulator.

    Actually, I believe that by the instruction:
    " STORE num1"
    ...that the contents of the accumulator are placed into the memory location(s) labeled "num1"

    It's difficult to know offhand precisely what the "Skipcond" statement does without the language reference, but if anything like PIC assembly, it simply skips over the next single instruction, depending upon the last arithmetic operation result that set condition codes, and the condition codes specified.

    I read you 5x5. ;)
    Since Num1 is defined at the end of the program as a type decimal with a value of zero, the assembler is very likely "smart enough" to handle the offset from program start (by default ORG 000h) to the label Num1 and the length of Num1. But I don't want to confuse our OP with the facts. ;)

    When I was writing Assembler code on IBM mainframes, labels started in column 1, opcodes started in column 10, single operands started in column 20, and comments started in column 40. That's why old programmers have a hard time spelling anything over 8 characters long. :D However, it made the source code neat, easy to read, and it was very easy to find opcodes/mnemonics and labels that were in the wrong columns.
     
  5. bertus

    Administrator

    Apr 5, 2008
    15,649
    2,348
    Hello,

    Here I found two PDF's on the net about MARIE assembly.

    Greetings,
    Bertus
     
  6. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
  7. Evilsithgirl

    Thread Starter New Member

    Nov 8, 2009
    3
    0
    thanks for all your helpful tips everybody. my program is working :)
     
Loading...