All About Circuits Forum  

Go Back   All About Circuits Forum > Electronics Forums > Homework Help

Homework Help Stuck on a textbook question or coursework? Cramming for a test and need help understanding something? Post your questions and attempts here and let others help.

Reply   Post New Thread
 
Thread Tools Display Modes
  #1  
Old 11-08-2009, 03:51 PM
Evilsithgirl Evilsithgirl is offline
New Member
 
Join Date: Nov 2009
Posts: 3
Default Help with program in MARIE assemby

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:
 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
Reply With Quote
  #2  
Old 11-08-2009, 04:21 PM
beenthere's Avatar
beenthere beenthere is offline
Super Moderator
 
Join Date: Apr 2004
Location: Missouri, USA (GMT -6)
Posts: 10,198
Blog Entries: 10
Default

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.
__________________
First comes the hardware, then the software.
Reply With Quote
  #3  
Old 11-08-2009, 04:32 PM
SgtWookie's Avatar
SgtWookie SgtWookie is online now
Senior Member
 
Join Date: Jul 2007
Location: Orlando, FL USA
Posts: 8,375
Default

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.
Reply With Quote
  #4  
Old 11-08-2009, 05:45 PM
SgtWookie's Avatar
SgtWookie SgtWookie is online now
Senior Member
 
Join Date: Jul 2007
Location: Orlando, FL USA
Posts: 8,375
Default

Quote:
Originally Posted by beenthere View Post
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.

Quote:
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.

Quote:
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"

Quote:
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.

Quote:
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. 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.
Reply With Quote
  #5  
Old 11-08-2009, 05:51 PM
bertus's Avatar
bertus bertus is offline
Senior Member
 
Join Date: Apr 2008
Location: Amsterdam,Holland (GMT + 1)
Posts: 3,397
Default

Hello,

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

Greetings,
Bertus
Attached Files
File Type: pdf lec16_Marie_ISA.pdf (7.5 KB, 8 views)
File Type: pdf marie.guide.pdf (273.6 KB, 7 views)
__________________
You don't have to know everything, if you know where to find it.
When you do ask questions, you may look stupid.
When you do NOT ask questions, you will STAY stupid.

It would be nice to have the Timezone ( GMT +/- x ) in the location field in the profile.(User CP -> Edit Your Details)
Reply With Quote
  #6  
Old 11-08-2009, 06:32 PM
SgtWookie's Avatar
SgtWookie SgtWookie is online now
Senior Member
 
Join Date: Jul 2007
Location: Orlando, FL USA
Posts: 8,375
Default

Thanks, Bertus - that helped a good bit.

I see in the example provided in: http://forum.allaboutcircuits.com/at...0&d=1257702689

...that IF, THEN, ELSE are not valid opcodes in Marie; they are labels.
However, labels must be unique; and Evilsithgirl has used multiple occurrences of IF, THEN, and ELSE as labels.

Apparently, labels must have a comma after them.
Reply With Quote
  #7  
Old 11-08-2009, 07:59 PM
Evilsithgirl Evilsithgirl is offline
New Member
 
Join Date: Nov 2009
Posts: 3
Default

thanks for all your helpful tips everybody. my program is working
Reply With Quote
Reply   Post New Thread

Bookmarks

Tags
, ,

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Matlab loops...help! natashakhan Programmer's Corner 1 05-10-2009 08:39 PM
Working out delay loops vk4tec Embedded Systems and Microcontrollers 10 02-21-2009 03:18 PM


All times are GMT. The time now is 06:54 AM.


User-posted content, unless source quoted, is licensed under a Creative Commons Public Domain License.
Copyright © 2009, All About Circuits. All Rights Reserved.