pseudocodemarie

In Marie.js how would I go about doing an if statement and loop for the following pseudocode?


max = 0
value = 0

LOOP
    INPUT value

    IF (value == 0)
    EXIT LOOP
    ENDIF

    IF (value > max)
           max = value
    ENDIF
ENDLOOP

PRINT max
STOP

I am using https://marie.js.org/ but i'm having a lot of trouble trying to figure out how to do an if statement. I've attempted to use skipcond. I'm also struggling a bit with the endless loop. Any help to get me started off would be really appreciated.


Solution

  • First, convert the pseudo code to the if-goto style of assembly language & machine code.

    if a then
       b
    endif
    

    translates into

        if !a then goto endif1
        b
    endif1,
    

    Second, translate your pseudo code variables into Marie assembly language/machine code variables.

    For example, you have an integer max in the pseudo code, so in the data area put:

    max, dec 0
    

    Finally, translate each line of if-goto code into assembly.


    Conditional tests if a < b goto are done by comparison using subtraction.  So, load a into the accumulator, subtract b, which sets the condition codes, and then do a SkipCond and goto to skip or not skip code you want to execute.


    Marie.js has a number of simple examples.  Look at the multiplication example, to see data/variable declarations, conditional branches, loops, input, output.