Part I. Nanoprocessor parameters (interpreter options)
In real applications we often develop nanoprocessors whose execution can be influenced by many parameters. How to perform an interpretation of the nanoprocessor with specific parameters?
Nsim provides the `-i' parameter which instructs nsim to interpret the given nanoprogram. Note anything that follows the `-i' is given to the nanoprocessor as its own command line.
nsim sample_nanoprogram2 -n -i <area of nanoprocessor parameters>
In this tutorial we will use the same nanoprocessor as in Tutorial 1 and Tutorial 3. For its description, refer to Tutorial 1 (simple description) or Tutorial 3 (advanced description).
The instruction set includes IN, OUT instructions. The instruction IN reads a number from a given input stream. The instruction OUT writes the content of the accumulator into a given output stream.
The input stream of the sample nanoprocessor may be specified by the parameter `-i input_file'. Similarly, the output stream may be defined by the parameter `-o output_file'. These two parameters and their processing as well as I/O handling are specified in the file
liberouter/sys_sw/nsim/doc/instruction.def
The help on nanoprocessor parameters can be obtained by
nsim sample_nanoprogram2 -i -h
Therefore, we can execute the nanoprogram by typing
nsim sample_nanoprogram2 -n -i -i number.txt -o xor_numbers.txt
This command causes that the instruction IN reads numbers from the file `number.txt' and output numbers are written into the file `xor_numbers.txt' (by the instruction OUT). The `-n' parameter causes nsim not to invoke the debugger but to transform inputs to outputs only. If we want to process the standard input, we type
nsim sample_nanoprogram2 -n -i -o xor_numbers.txt
Similarly, output the sample nanoprocessor is redirected to standard output when `-o' parameter is not specified.
NOTE: Processing of nanoprocessor parameters is not the task of nsim, but the task of the initial part of the interpreter that is specified in the nanoassebler source (see Tutorial 3).
Part II.---Labels
Nsim provides the possibility to define labels in nanoprograms. Label is an unique identifier pointing to the next instruction Let us look at the sample nanoprogram.
liberouter/sys_nsim/nsim/doc/sample_nanoprogram2
There is a label `block' and `jmp' instruction performing jump to the instruction IN, located at the line that follows the `block' label.
#include "instruction.def"
#define A 100
#define B 101
block:
in
sta A
in
sta B
xor A, B
out
jmp block
Sometimes we need to place a block of instructions at a specific address. This goal is achieved by the `#ORG' directive. An example follows
#ORG 0x1ff
xor A, B
out
jmp block
`#ORG 0x1ff' directive ensures, that the instruction `xor A, B' will be located at the address 0x1ff, `out' at the address 0x200, `jmp block' at the address 0x201 and so forth until the next #ORG. If no #ORG is defined at the beginning of a program, the instruction pointer starts from zero.


