Help with program in MARIE assemby

Thread Starter

Evilsithgirl

Joined Nov 8, 2009
3
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:

Rich (BB code):
 Input
 Store  Num1
 Input
 Store  Num2
 Input
 Store  Num3
 Input
 Store  Num4
 Input
 Store  Num5
 Input
 Store  Num6
 Input
 Store  Num7
 Input
 Store  Num8
If, Load  Num1
 Subt  Num2
 Skipcond 800
 Jump  Else
Then, Load  Num1
 Store  Lowest
Else, Load  Num2
 Store  Lowest
If, Load  Lowest
 Subt  Num3
 Skipcond 800
 Jump  Else
Then, Load  Lowest
 Store  Lowest
Else, Load  Num3
 Store  Lowest
If, Load  Lowest
 Subt  Num4
 Skipcond 800
 Jump  Else
Then, Load  Lowest
 Store  Lowest
Else, Load  Num4
 Store  Lowest
If, Load  Lowest
 Subt  Num5
 Skipcond 800
 Jump  Else
Then, Load  Lowest
 Store  Lowest
Else, Load  Num5
 Store  Lowest
If, Load  Lowest
 Subt  Num6
 Skipcond 800
 Jump  Else
Then, Load  Lowest
 Store  Lowest
Else, Load  Num6
 Store  Lowest
If, Load  Lowest
 Subt  Num7
 Skipcond 800
 Jump  Else
Then, Load  Lowest
 Store  Lowest
Else, Load  Num7
 Store  Lowest
If, Load  Lowest
 Subt  Num8
 Skipcond 800
 Jump  Else
Then, Load  Lowest
 Store  Lowest
Else, Load  Num8
 Store  Lowest
If, Load  Num1
 Subt  Num2
 Skipcond 800
 Jump  Else
Then, Load  Num2
 Store  Highest
Else, Load  Num1
 Store  Highest
If, Load  Highest
 Subt  Num3
 Skipcond 800
 Jump  Else
Then, Load  Num3
 Store  Highest
Else, Load  Highest
 Store  Highest
If, Load  Highest
 Subt  Num4
 Skipcond 800
 Jump  Else
Then, Load  Num4
 Store  Highest
Else, Load  Highest
 Store  Highest
If, Load  Highest
 Subt  Num5
 Skipcond 800
 Jump  Else
Then, Load  Num5
 Store  Highest
Else, Load  Highest
 Store  Highest
If, Load  Highest
 Subt  Num6
 Skipcond 800
 Jump  Else
Then, Load  Num6
 Store  Highest
Else, Load  Highest
 Store  Highest
If, Load  Highest
 Subt  Num7
 Skipcond 800
 Jump  Else
Then, Load  Num7
 Store  Highest
Else, Load  Highest
 Store  Highest
 Halt
If, Load  Highest
 Subt  Num8
 Skipcond 800
 Jump  Else
Then, Load  Num8
 Store  Highest
Else, Load  Highest
 Store  Highest
 Load  Lowest
 Output
 Load  Highest
 Output
 Halt
Num1, Dec  0
Num2, Dec  0
Num3, Dec  0
Num4, Dec  0
Num5, Dec  0
Num6, Dec  0
Num7, Dec  0
Num8, Dec  0
Lowest, Dec  0
Highest, Dec  0
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
 

beenthere

Joined Apr 20, 2004
15,819
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.
 

SgtWookie

Joined Jul 17, 2007
22,230
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.
 

SgtWookie

Joined Jul 17, 2007
22,230
While the language, MARIE, is a mystery, it appears that you have made some fundamental errors (or they would be in every other language).
I haven't been able to find a language reference for it either; it appears to only be published in certain textbooks.

Your Input statement does not specify what to input, or from what source.
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.

You tell the simulator to Store the input, but do not specify a location.
Actually, I believe that by the instruction:
" STORE num1"
...that the contents of the accumulator are placed into the memory location(s) labeled "num1"

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
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 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.
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.
 
Top