Wondering what exactly is wrong with this MARIE assembly code? (Calculator) - marie

ORG 100 /Start Here
INPUT
Store X /Store 1st input value in X
INPUT
Store Y / Store 2nd input value in Y
choice, INPUT
Store C /Store choice in C
if, Load C
Subt A
Skipcond 400
Jump elseif1
JnS ADDITION /Call subroutine
Jump end
elseif1, Load C
Subt S
Skipcond 400
Jump elseif2
JnS SUBTRACT /Call subroutine
Jump end
elseif2, Load C
Subt M
Skipcond 400
Jump elseif3
JnS MULTIPLY /Call subroutine
Jump end
elseif3, Load C
Subt D
Skipcond 400
Jump elseif4
JnS DIVISION /Call subroutine
Jump end
elseif4, Load C
Subt Q
Skipcond 400
Jump choice /re-enter choice
Halt /stop the program
end, Output /Display the value
Halt /Stop
X, DEC 0
Y, DEC 0
C, DEC 0
/add two numbers
ADDITION Load X
Add Y
JumpI ADDITION / Indirect jump to return.
/subtract two numbers
SUBTRACT Load X
Subt Y
JumpI SUBTRACT / Indirect jump to return.
/multiply two numbers using continuous add loop
MULTIPLY loop, Load num
Add X
Store num
Load Y
Subt one
Store Y
Skipcond 400
Jump loop
Load num
JumpI MULTIPLY / Indirect jump to return.
/divide two numbers and return the quotient
DIVIDE If, Load X
Subt Y
Skipcond 800
Jump EndIf
Store X
Load quo
Add one
Store quo
Jump If
EndIf, Load quo
JumpI DIVIDE / Indirect jump to return.
/constants values
one, DEC 1
num, DEC 0
rem, DEC 0
quo, DEC 0
A, DEC 97 /a
M, DEC 109 /m
S, DEC 115 /s
D, DEC 100 /d
Q, DEC 113 /q
This is a calculator that is supposed to add, subtract, multiply, and divide. Once the user is done with an operand it is supposed to directly go to the next one as well, but it is giving me errors and I can't seem to fix them. Everything looks fine to me but it keeps saying "Operand undefined." I'm sure this is an obvious error to others but I can't seem to fix it. Was hoping someone can help me with this! Thanks!

Related

How to read a grid from $0200 to $05ff in 6502 Assembly

So I've been given an assignment where we have to make a symbol using colored pixels using an 6502 assembly emulator. I don't quite understand how this grid works. Could someone please explain how this grid works and maybe give and example?
here is the link to the emulator: https://skilldrick.github.io/easy6502/#first-program
and the grid I'm to work with: https://i.stack.imgur.com/QuqPi.png
I think Michael's command is correct; avoiding use of 'x' and 'y' for potential register ambiguity reasons, address $0200 + (q*32) + p contains the pixel at (p, q) for p and q in the range 0 to 31, and in each byte the low four bits determine the pixel colour.
So e.g. $0200 is the pixel in the top left, $0201 is the pixel one to the right of the top left, and $0220 is the pixel one below the top left.
In 6502 terms one possible straightforward implementation of a generic plot subroutine could use indexed indirect addressing, storing $0200 + (q*32) into a zero-page location and then indexing by p to hit a particular horizontal position within that row. Off the top of my head, and without having checked exactly what syntax that assembler uses and hard-coding the use of zero-page addresses $80 and $81:
;
; Plot; stores the colour in A to the pixel at (y, x).
; So, yes: x and y are backwards.
;
; Clobbers x.
;
Plot:
; Arbitrarily, this adds x to ($200 >> 5) and
; then shifts the whole lot left by 5. That's
; rather than shifting x by 5 and then doing a
; one-byte add to the upper byte, I guess.
pha
txa
clc
adc #$10 ; $10 = $200 >> 5
sta $80
lda #$00
sta $81
; Multiply by 32. You could unroll this if
; that's what your priorities imply.
ldx #5
.rollLoop
asl $80
rol $81
dex
bne rollLoop
pla
sta ($80), y
rts

Marie JS to the power of

I need to write a code for raising x to the power of y in Marie.js. That's what I have for now, however it spits out an error SyntaxError:L41 - Unknown label Loop.
Input
Subt One
Store Count
Input
Store x
Store y
Jns Exp
Load Wyn
Output
End, Halt
Exp, Hex 0
Loop2, Load Count
Skipcond 800
JumpI Exp
JnS Multi
Load Wyn
Store x
Load Count
Subt One
Store Count
Jump Loop2
Multi, Hex 0
Load Zero
Store Wyn
Loop, Load x
Skipcond 800
JumpI Multi
Load Wyn
Add y
Store Wyn
Load x
Subt One
Store x
Jump Loop
x, Dec 2
y, Dec 3
Zero, Dec 0
One, Dec 1
Wyn, Dec 0
Count, Dec 0
I understand the necessity for 2 loops, which execute y-1 times, however Im completely clueless what I'm doing wrong.
You have to define a label before you can Jump to it; you have not defined the label Loop. You have defined a label named Loop2.

Marie Simulator- How to use MarieSim?

I am very new to using Marie simulator, and if anyone could help, it would be great.
the following program:
ORG 200
If, Load X
Subt Y
Skipcond 400
Jump Else
Then, Load Y
Store X
Jump Endif
Else, Load Y
add X
Store Y
Endif, Output
Halt
Two, Dec 2
X, Dec 10
Y, Dec 10
END
From this code, what does this particular part mean? And how do I input a new value to Y? Also, what does first load instruction mean?
Two, Dec 2
X, Dec 10
Y, Dec 10
I am trying to figure this MarieSim out, I would really appreciate it if anyone could help out. thank u.

MARIE simulator: multiplication of two numbers using addition

multiplication of two numbers 6 and 3 by, repeatedly addition of 3 six times,using a loop that will add 3 six times and store the result into accumulator.
INPUT
STORE x
INPUT
STORE y
loop, LOAD x
ADD multiply
STORE multiply
LOAD y
SUBT one
STORE y
SKIPCOND 400
JUMP loop
LOAD multiply
OUTPUT
HALT
x, Dec 0
y, Dec 0
one, Dec 1
multiply, Dec 0

Need a Maple program,

I am New in Maple and have heard that, this maths software is powerful in symbolic calculation. S assume that we have a set of elements like
A:={a, aab, b, aba, abbb, abab...}
such that #A=20 and moreover, we know that some of these elements satisfy an equation, for example a^k=(ab)^2 for some positive integers k. I have written some loops including for and if and assuming A is a set of numbers, but I have exhausted. I see, I can’t arrange and link these functions together properly.
May I ask someone hint me, how maple can help me find the values of k for example in a finite range [1..10] satisfying the relation above?
I this you could do something like this:
restart:
A:={a,b,1000*a+111*b,101*b+1010*a,110*a+b};
A := {a, b, 110 a + b, 1000 a + 111 b, 101 b + 1010 a}
for i from 1 to 9 do
for j from 1 to 9 do
As:=subs(a=i,b=j,A);
for e in As do
for ee in As do
if((ee<>e) and (e<=ee^2)) then
for k from 1 to 10 while (e^k<ee^2) do
od;
if(e^k=ee^2) then
print(e,"^",k,"=",ee,"^2");
fi;
fi;
od;
od;
od;
od;
Just fill in the elements of your set and let it calculate. You could go slightly faster if you sort your set first (so you have A=[1,6,16,61]) and calculate all squared numbers. Then loop over the entries but only looking at those that are bigger (but that might not be what you are looking for)