Help with MARIE programming

Thread Starter

Bimali Abeysekara

Joined Aug 29, 2019
1
how can you write this into MARIE. Anyone help me. I beg your pardon.

Write a MARIE program that accepts an integer from the user, and if it is a prime number the program will output 1, otherwise, the program will output 0.
Examples:
If the user input is 17, the output would be 1
If the user input is 2, the output would be 1
If the user input is 15, the output would be 0
If the user input is -2, the output would be 0



You should write and run the program using MARIE simulator.
 

jpanhalt

Joined Jan 18, 2008
11,087
I do not do Marie, but I have a little experience with Microchip Assembly (MPASM). There are lots of ways to address that problem in MPASM. What have you tried for Marie?

Hints:
1) Can you use a look-up table? (fast, but uses lots of code space)
2) What value could you add to each entry that would cause a unique change for each pair of outputs?
3) Other?
 

joeyd999

Joined Jun 6, 2011
6,204
Break the big problem down into smaller -- easier to solve -- problems.

In this case, there are (at least) three "small" problems:

1. Accept integer input from the user
2. Determine whether the integer is prime or non-prime.
3. Output a 1 or 0 depending upon the result of (2).

I assume you know how to do (1) and (3), correct?

You need to develop an algorithm to determine primeness. What do you know about prime numbers?
 

Picbuster

Joined Dec 2, 2013
1,057
how can you write this into MARIE. Anyone help me. I beg your pardon.

Write a MARIE program that accepts an integer from the user, and if it is a prime number the program will output 1, otherwise, the program will output 0.
Examples:
If the user input is 17, the output would be 1
If the user input is 2, the output would be 1
If the user input is 15, the output would be 0
If the user input is -2, the output would be 0



You should write and run the program using MARIE simulator.
Marie is from the beginning of computers (50+ years ago) for hardware like the 4004 (4 bit cpu)
some information is still available.
http://www.edwardbosworth.com/CPSC2105/Lectures/Slides_05/Chapter_04/MARIE_AssemblyLanguage.htm

Forget about it when this is not a mandatory task!! (it's old and a museum item)
Start with modern common used stuff allowing you to earn money with the knowledge gained.

Picbuster
 

jpanhalt

Joined Jan 18, 2008
11,087
I assumed it was homework and MARIE is still used in schools to teach structures. Google turned up this book from a pair of Penn State authors (2014) :https://books.google.com/books?id=GKgxDwAAQBAJ&dq=Boolean+logical+operations+with+"Marie"

Before seeing that book, my knowledge of MARIE was that it was a simple language with up to 16 instructions. On the faulty assumption that Boolean operators would be included in any language, it was simple to come up with code in MPASM for the task:

Code:
     movlw     2      ;test input
     movwf     input  ;test input

Start
     movf      input,w
     addlw     2
     xorwf     input,w
     andlw     0xF0
 
     nop       ;test whether w=0
               ;if w=0, report 1
               ;else, report 0
In theory, that code would "only" need to be converted to MARIE.

Then I spent some time with that aforementioned book. Only 9 instructions are shown. Are there 7 more? The book mentions Boolean, rotations, and conditional jumps, but only illustrates the latter (as did every other source I looked at).

Since XOR is a bitwise add (no carry), if one could rotate out each bit, you could make a subroutine for XOR. AND can be done bitwise with rotations and conditionals, i.e., if either bit is 0, result is 0.

It appears the "theoretical" conversion to MARIE might not be so practical. Given that, a simple "add 3" (or 2) then a jump table may use less code than creating two subroutines for Boolean operators would.

I hope the TS responds with her progress.

EDIT: OOPS, I just re-read the question. I had missed the requirement to determine whether the entry was prime. Ignore everything I posted. I thought the requirement was just for those 4 entries. :oops:
 
Last edited:
Top