2

I am writing a program that will evaluate the statement below, but I have to do it with a stack organized computer. This means that only pop and push can access memory.

enter image description here

How would I do this while using this program as a sample for my program?:

    Load    A           
    Store   Stack0      
    JnS Push        
    Load    B       
    Store   Stack0      
    JnS Push        
    JnS PopS        
    Load    C       
    Store   Stack0      
    JnS Push        
    Load    D       
    Store   Stack0      
    JnS Push        
    Load    E       
    Store   Stack0      
    JnS Push        
    JnS PopM        
    Load    F       
    Store   Stack0      
    JnS Push        
    JnS PopS        
    JnS PopM        
    JnS PopA        
    Load    G       
    Store   Stack0      
    JnS Push        
    Load    H       
    Store   Stack0      
    JnS Push        
    Load    K       
    Store   Stack0      
    JnS Push        
    JnS PopM        
    JnS PopA        
    JnS PopD        
    JnS Pop     
    Halt            
Push,   Hex 0       
    Load    Stack4      
    Store   Stack5      
    Load    Stack3
    Store   Stack4
    Load    Stack2
    Store   Stack3
    Load    Stack1
    Store   Stack2
    Load    Stack0
    Store   Stack1
    JumpI   Push
Pop,    Hex 0       
    Load    Stack1      
    Store   Stack0      
    Load    Stack2      
    Store   Stack1
    Load    Stack3
    Store   Stack2
    Load    Stack4
    Store   Stack3
    Load    Stack5
    Store   Stack4
    Load    Zero
    Store   Stack5
    Load    Stack0
    JumpI   Pop
PopA,   Hex 0       
    JnS Pop     
    Add Stack1      
    Store   Stack1      
    JumpI   PopA
PopS,   Hex 0       
    JnS Pop
    Load    Stack1      
    Subt    Stack0      
    Store   Stack1      
    JumpI   PopS
PopM,   Hex 0       
    JnS Pop
    Store   Calc1       
    Store   Calc3       
    JnS Pop
    Subt    One
    Store   Calc2
    Skipcond    400 
    JnS Mult        
    Store   Stack0
    JnS Push        
    JumpI   PopM
Mult,   Hex 0
LoopM,  Load    Calc3       
    Add Calc1
    Store   Calc3
    Load    Calc2
    Subt    One     
    Store   Calc2
    Skipcond    400 
    Jump    LoopM
    Load    Calc3       
    JumpI   Mult
PopD,   Hex 0       
    JnS Pop
    Store   Calc2       
    Load    Zero        
    Store   Calc3       
    JnS Pop
    Store   Calc1       
    Load    Calc2
    Skipcond    400 
    JnS Divs
    Store   Stack0
    Jns Push        
    JumpI   PopD
Divs,   Hex 0
LoopD,  Load    Calc1       
    Subt    Calc2       
    Store   Calc1       
    Load    Calc3
    Add One     
    Store   Calc3       
    Load    Calc1
    Skipcond    800 
    Jump    EndD
    Jump    LoopD
EndD,   Load    Calc3       
    JumpI   Divs
One,    Dec 1           
Zero,   Dec 0           
Calc1,  Dec 0           
Calc2,  Dec 0           
Calc3,  Dec 0
A,  Dec 9       
B,  Dec 8
C,  Dec 7
D,  Dec 6
E,  Dec 5
F,  Dec 4
G,  Dec 3
H,  Dec 2
K,  Dec 1
Stack0, Dec 0           
Stack1, Dec 0           
Stack2, Dec 0           
Stack3, Dec 0           
Stack4, Dec 0
Stack5, Dec 0

Any help would be appreciated. I am new to MARIE, and have received next to no help so far whatsoever. Thank you! =)

Eric after dark
  • 1,768
  • 4
  • 31
  • 79
  • So it's probably not very practical to use that as a starting point is it? What about my solution to this problem in this question?: http://stackoverflow.com/questions/23278596/why-wont-my-program-compile-in-the-marie-simulator – Eric after dark Apr 25 '14 at 22:18
  • For a stack machine, have a look at FORTH? – EOF Apr 25 '14 at 23:35
  • You could write that exactly as in http://stackoverflow.com/questions/23278596/why-wont-my-program-compile-in-the-marie-simulator in Forth, but MARIE does not support stack operations with data at all. I haven't got time to go through the stack simulation here though, but the use of 'Stack0', 'Stack1',... is not very convincing: the labels don't even have to be adjacent nor in order. Doing proper stack simulation with MARIE seems to require some thinking... With pretty much any arbitrary assemmbly it's a LOT easier. – turboscrew Apr 26 '14 at 23:17
  • The problem is indirect storing (or lack of it). – turboscrew Apr 26 '14 at 23:19

0 Answers0