LOOP LDA COUNT
SUB 1
STA COUNT
OUT
BRA PROGEND
HLT
COUNT DAT 11
ONE DAT 1
To me it seems pretty basic and simple and in my knowledge of maths, it should work: evidently it is not.
So help pls
LOOP LDA COUNT
SUB 1
STA COUNT
OUT
BRA PROGEND
HLT
COUNT DAT 11
ONE DAT 1
To me it seems pretty basic and simple and in my knowledge of maths, it should work: evidently it is not.
So help pls
There are several issues with this code:
SUB does not accept a literal number as argument. The argument is an address, and so in your case it should read SUB ONE instead of SUB 1.
The label PROGEND is not defined, so this code should not even assemble. Given the meaning of the label, the label should be defined in the line with HLT, but that does not make sense, as HLT is anyway the next instruction, making the BRA obsolete.
The label LOOP is never referenced.
If BRA was intended to refer to the LOOP label, then your code would be in for an infinite loop, as BRA jumps unconditionally. Your code should have a conditional branch instruction somewhere (either BRP or BRZ), so there is a way to either repeat the loop or to end it.
Here is how it could work:
LOOP LDA COUNT
OUT
SUB ONE
STA COUNT
BRP LOOP
HLT
COUNT DAT 10
ONE DAT 1
<script src="https://cdn.jsdelivr.net/gh/trincot/lmc@v0.6/lmc.js"></script>