2

I am writing a code to multiply three numbers.

A x B x C = Z You have to input all the initial values. There is a detriment variable as well P. You input in this order A B C Z P... A B & C can be anything. Z is entered as 0 and P as 1. (If you can show me how to just set their initial values that would be great too.)

My real problem is when I go to output Z at the end of the program it either prints a blank space or an x. Any help would be greatly appreciated.

ORG 100
INPUT       /USER INPUT VARIABLE 
STORE   A   /STORE IN MEM LOCATION
OUTPUT      /SHOW WHAT USER ENTERED
INPUT       /USER INPUT VARIABLE            
STORE   B   /VARIABLE B
OUTPUT
INPUT       /VARIABLE C         
STORE   C
OUTPUT
INPUT
STORE   Z
OUTPUT
INPUT
STORE   P  
OUTPUT  
LOOP,   LOAD    Z   /START LOOP TO ACCUMULATE A  
    ADD A  
    STORE   Z  
    LOAD    B  
    SUBT    P   /DECRIMENT VARIABLE B  
    STORE   B  
    SKIPCOND    01  /CHECK IF B = 0  
    JUMP    LOOP    /REPEAT LOOP UNTIL B = 0  
LOOP2,  LOAD    Z  
    ADD A  
    STORE   Z  
    LOAD    C   
    SUBT    P   /DECRIMENT C  
    STORE   C  
    SKIPCOND    01  / CHECK IF C = 0  
    JUMP    LOOP2   /REPEAT LOOP UNTIL C = 0  
    CLEAR  
    LOAD    A  
    STORE   A  
    CLEAR  
    LOAD    Z  
    STORE   Z  
    OUTPUT      /DON'T KNOW WHY IT WON'T PRINT  
    HALT  

A, DEC 0

B, DEC 0

C, DEC 0

Z, DEC 0

P, DEC 0

Thomas
  • 1,445
  • 14
  • 30
Tzarl
  • 21
  • 2

1 Answers1

1

Unfortunately, I was over a month and a half late seeing this question, so you may not need help anymore, but I believe your problem is actually rather simple. It sounds like you likely have the output mode set to ASCII (default) instead decimal (Dec). See screenshots below:

combobox for output in MARIE Simulator

Also, make sure you have selected the correct input type, or your answers will likely come out incorrect:

combobox for input in MARIE Simulator

As for how you can set their initial values, you are actually already doing that by including the following:

A, DEC 0
B, DEC 0
C, DEC 0
Z, DEC 0
P, DEC 0

These lines initialize the values to zero initially. Therefore, if P and Z should be zero and do not actually need user input, you can just skip getting user input for them. However, if you ever want to reset the values, you can just do the following:

/ ... Some stuff going on before you want to reset the values...
Clear / This will reset the value in AC to 0.
Store P  / Store current AC Value (0) in memory at P
Store Z  / Store current AC Value (0) in memory at Z
/ ... Store it wherever you want to reset values to Zero
/ Proceed with the rest of your program now that the values are reset.

/ And down at the bottom like normal:
A, DEC 0
B, DEC 0
C, DEC 0
Z, DEC 0
P, DEC 0

One thing I typically like to do is set up a subroutine for resetting all memory. So, I would create something like the following:

TempAcValStorage, Dec 0 / Used to preserve value on AC so it is not lost when clearing
InitializeVals, HEX 0
    Store TempAcValStorage / Store current AC val
    CLEAR    / Set value of AC to 0
    STORE A  / Store 0 in variable
    STORE B  / Store 0 in next variable
    STORE C  / ...
    STORE Z
    STORE P  / Store 0 in last variable
    Load TempAcValStorage / Restore whatever was on AC
    JumpI InitializeVals


/ ... Futher down in my code when I need to initialize or reset my
/ values, I just execute a Jump-and-Store for InitializeVals:
    JnS InitializeVals

A benefit of this routine is that it preserves the value on the AC so you do not lose it while resetting the values of all your stored variables.

Spencer D
  • 3,376
  • 2
  • 27
  • 43