tanx dear Mats, as you may know, i started coding the Dietels exercise "The simpletron computer emulation " its ok now , a nice console app that serves that exercise .
after that , it made me write an emulator for other lets say "Abstract" or conceptual Computer Systems, such as CLA, (a single adressed computer with octal base ,featuring a 16 bit Accumulator,a 9 bit programer Conter, 512 memory lines(each 16 bits), a 2^4 or 16 instructions, 2 flags of z and n (representing Zero and Negetive flag),and a 9 bit address line)
Code:
_________________________
| Opcode | Address |
|___________|_____________|
4 bit 9 bit
______________________________
| Opcode| M| I|X| Address |
|________|__|__|_|___________|
0 0 0
MIX=000
Code:
HLT //halt the program , used to state the end of the program!. only one instance is allowed( you cant use halt twice!)
LDA M //Loades value from M
STA Y//Store the Accumultor value to Y
SBA Y //subtracts Accumultor value from Y
ORA Y //Ors the value of y with the value stored in accumultor and places the result in acumultor
ANA Y //Ands the value of y with the value stored in accumultor and places the result in acumultor
JMP Y //jump to Y
JNG Y //if the value stored in acumultor is negetive then jump to Y
JZR Y //if the value stored in acumultor is zero then jump to Y
CLA //zeros the accumulator
INC //increments the value stored in accumulator
DEC //decrements as above
ADA Y //Adds the value of Y with the value of accumulator
RED Y //Reads users input and places it in Y
WRI Y //print s the value of Y
a sample code which can be executed on a CLA computer is as follows:
//simple mode of addressing
Code:
ORG 9 //stating where to start
9. RED 5
10. RED 6
11. LDA 5
12. SBA 6
13. JNG 17
14. WRI 5
15. JMP 20
17. WRI 6
20. HLT
-----------------
Machine Language
1110 000 000 000 101
1110 000 000 000 110
0001 000 000 000 101
0100 000 000 000 110
1000 000 000 001 111
1111 000 000 000 101
0111 000 000 010 000
1111 000 000 000 110
0000 000 000 000 000
----------------------------------------
//Symbolic mode of addressing
Code:
ORG 100
L1:LDA 1
ANA Mask
DEC
JNG L3
L2:LDA 1
ADA sum
STA sum
LDA count
DEC
JZR stop
STA count
LDA L1
INC
STA L1
STA L2
JMP L1
stop:WRI sum
HLT
sum:000
count:007
Mask:001
---------------------------
//Index-Indirect mode of addressing
MIX
0 1 1 == LDA IX 10 //loads a memory location which XR+10 points to
and etc...(a couple of other addressing modes )
-----------------------------
"pretty much like simpletron" but this one has more stuffs such as: labels,different modes of addressng ( immediate /indirect modes,...) & alot more! (its like Assembly language to some extend ! .)
so thats what im planing to code ! , at first i thought i could be accomplished by using if , and loops , ( it is possible i think)but using parsing would make it rather easy and also look professional and debuging the app could be more conviniet too
so thats all .