I have made an assembler and simulator in Javascript, (I modified the assembler-simulator from Marco Schweighauser).
The simulator includes a calculator display and keys. You can download it from the file list, or try it online at: www.enscope.nl/rrca
The first program is a 8-digit calculator that can only add. You can paste the following code in the online assembler, assemble it and start the simulator.
; CPU simulator test. ; Only calculates: A + B = NOP ;first instruction is skipped ! clr: plus: LDL Y,X ; save X in Y (32 bit) SUBL X,X ; clr X (32 bit) waitkey: HLT ; wait for button press ; HLT ; option for switching to single step TEQ CL,'+' BRZ plus TEQ CL,'=' BRZ result TEQ CL,' ' ; CLR pressed ? BRZ clr ADD CL,0xffd0 ; keep digit code (subtr 0x30) ADDL X,X ; shift X one digit left ADDL X,X ADDL X,X ADDL X,X ADD XL,CL ; add new digit at the right side BR waitkey NOP ; delay slot: the instruction after BR is also executed ! result: DADDL X,Y ; 32-bit decimal add (Decimal ADD Long) BR waitkey
The architecture document was changed on a few minor points: The name of a few instructions changed, and the position of some bits in the opcode changed. There are a few new instructions in the above code that are not yet in the documentation: HLT and NOP.
After a calculation, press the "clr" button before a new calculation is started.
Change the code and build your own calculator online ! You can also use scientific notation: two digits of CL are displayed as exponent, and the upper bits in CL control minus-signs and a decimal point after the first digit.
The page does not save your modified code, so you have to do some copying.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.