My dream CPU

VIII. Program structure

A program for RCPU is just a XML file with these tags:
InitCPU contain processor init data.
Info show what the program is doing. This is not executable part, it is only for information.
PrgCode tag contain the same program. The instructions in it are to XML tags.
Data tag contain the working data, this are integer or float numbers.

Listing 1. RCPU program structure

		<IP value="100"/>
		<SP value="1023"/>
		<memory value="2"/>

	<info>Type the program description here.</info>


	<data startadr="0"/>


The initCPU tag.

The value of "value" attribute from IP tag will be assign the IP in the CPU. In this address will be loaded the program.

The value of "value" attribute from SP tag will be assign the SP in the CPU.

The value of "value" attribute from memory tag is the memory amount in kB.

The Data tag.

The data part is in "Data" tag. It contains "linedt" tags, in it are integer or float numbers which will be in memory when program is loaded. The "startadr" attribute in "data" tag is start address for data loading. Change its value to change all data place. In program loading its value is added to "adr" value on every "linedt" tag.

"linedt" tags from "Data" tag.
Example for "linedt" tag.
<linedt label="arraySize" adr="300" value="39" comment="array size"/>

The attribute "label" is label. The label can be used from a instruction. When a program is loaded this label is replaced with its address.

The attribute "adr" is address. Sum "adr" with "startadr" to calc real address.

The attribute "value" is the number which will be loaded in the memory. If it is without '.' or "," it is a integer. otherwise it is floating point number. Floating point numbers are on 2 serial addresses. Both are with "." . From first number we take integer part, from second float part. This is to simulate reading from 2 serial addresses. All we know the real data format for floating point numbers is different, this is for test and simulating purpose only.

The attribute "comment" is comment

The prgcode tag

The most important part is "prgcode" tag. Here is the same program. It is line tags.
Attribute list for line tag:

lnNmbr - line number
adr - Instruction address.
Tp - line type. Accept 2 values "dt" or "move". If it is "dt" it is instruction operand. If it is "move" it is instruction. Every instruction is just a move, data move
Value - If type is "dt" here is operand value. If tp = move there is not "value" attribute.
the following tag are available only for instructions (tp = move).
Rmr - The same instruction, the data sign. Values: MR memory – register, RM register-memory, RR register - register. Could be to push, pop, mrIncX, mrIfMaxX, mrSort, call, ret.
Pipeline - Instruction pipeline about it is – I, D , A
r - register
rBs - Base register. Could be rBs1, rBs2, rBs3, #
rX - Index register. Could be rX1, rX2, rX3
condition - condition.
label - line label.
Comment - comment

How a RCPU program is loaded

After a program file is opened, emulator read first initCPU part. Initialize IP, SP and program size. Next is loaded data part and replace labels with real values. Next start loading the same program and replace the labels with real values. Program is ready to be executed.