1

I am new to MARIE. I am creating a Marie Code which will remove the "space" in between elements. For example. if it is ~~FIT ~ 1047~~~, it would remove the elements ~~~~.

Can anyone please take a look at my code and guide me?

I understand that when it reaches HEX 020, it jumps to end when it should delete it and add the next values to the string.

Load NameAddr
Store TrimStringAddr
JnS TrimString
Halt

NameAddr, ADR Name
Name, HEX 052 / R <--- this is where you add your name
      HEX 061 / A
      HEX 06e / N
      HEX 061 / A
      HEX 020 / SPACE
      HEX 041 / A 
      HEX 074 / T
      HEX 069 / I
      HEX 06e / N
      HEX 064 / D
      HEX 065 / E
      HEX 072 / R
      HEX 000 / END

TrimStringAddr, HEX 0    / address of string to trim
TrimString,     HEX 0 
StartTrim, LoadI TrimStringAddr
           Output
           Subt B
           Skipcond 800
           Jump End
           Subt B
           Load TrimStringAddr
           Add A
           Store TrimStringAddr
           Jump StartTrim

End, Halt

B, HEX 020
A, HEX 001

It is being loaded into the AC. However. The output I am getting is RANA when what I want to obtain is RANAATINDER

Rana
  • 11
  • 2
  • Please add comments to explain how each instruction in your code is *supposed* to work to implement your algorithm, as well as describing what actually happens. Can you see with your debugger whether you're even loading the characters of the string into the accumulator? – Peter Cordes Sep 04 '18 at 03:11
  • Yes it is being loaded into the AC. The out after I run this code is RANA when what I am trying to achieve is RANAATINDER – Rana Sep 04 '18 at 03:17
  • You should [edit] that comment into your question to make it a better [mcve] for other people that might want to answer your question. (I don't know Marie very well, so it would take me longer than I want to spend figuring out what bug your code has.) – Peter Cordes Sep 04 '18 at 03:24
  • Done. Thank you sir. – Rana Sep 04 '18 at 05:19
  • Instead of `Jump End`, wouldn't your program skip spaces if you just jumped to the `Add A` instruction? You'll need a different loop-exit condition. – Peter Cordes Sep 04 '18 at 05:21

1 Answers1

0

You're printing the output before checking it and ending the program when you do reach a space.

This can be rectified by checking for a space before using output and then using an adhoc IF by having a second option to loop through that prints the output like so:

StartTrim, LoadI TrimStringAddr
       Subt B
       Skipcond 400 / If not zero will Jump to process output
       Jump IsLetter
       Subt B
Load TrimStringAddr
       Add A
       Store TrimStringAddr
       Jump StartTrim
IsLetter,   LoadI TrimStringAddr
        Skipcond 800 / Check when empty to finish
        Jump End
        Output
        Subt C
        Load TrimStringAddr
        Add A
        Store TrimStringAddr
        Jump StartTrim

Complete code:

Load NameAddr
Store TrimStringAddr
JnS TrimString

NameAddr, ADD Name
Name, HEX 052 / R 
      HEX 061 / A
      HEX 06e / N
      HEX 061 / A
      HEX 020 / SPACE
      HEX 041 / A 
      HEX 074 / T
      HEX 069 / I
      HEX 06e / N
      HEX 064 / D
      HEX 065 / E
      HEX 072 / R
      HEX 000 / END

TrimStringAddr, HEX 0    / address of string to trim
TrimString,     HEX 0 

StartTrim, LoadI TrimStringAddr
       Subt B
       Skipcond 400
       Jump IsLetter
       Subt B
Load TrimStringAddr
       Add A
       Store TrimStringAddr
       Jump StartTrim
IsLetter,   LoadI TrimStringAddr
        Skipcond 800 / Check when empty to finish
        Jump End
        Output
        Subt C
        Load TrimStringAddr
        Add A
        Store TrimStringAddr
        Jump StartTrim

End, Halt

B, HEX 020
A, HEX 001
C, HEX 040