Content |
ULM Simulator
The ULM simulator is written in C++. The following steps are required for using it:
-
Use the wget command to download the C++ source code
wget http://www.mathematik.uni-ulm.de/~lehn/ulm.cc
-
Compile it with the GNU C++ compiler:
g++ -Wall -std=c++11 -o ulm ulm.cc
-
Test the ULM simulator:
-
File example.ulm contains a program in machine code for the ULM. You can get it with:
wget http://www.mathematik.uni-ulm.de/~lehn/example.ulm
-
With the following command you can start the ULM with the code from example.ulm loaded into memory:
ulm example.ulm
-
Demo for downloading and compiling the ULM simulator
$shell> wget http://www.mathematik.uni-ulm.de/~lehn/ulm.cc --2017-04-28 13:53:48-- http://www.mathematik.uni-ulm.de/~lehn/ulm.cc Resolving www-proxy.uni-ulm.de... 134.60.1.151 Connecting to www-proxy.uni-ulm.de|134.60.1.151|:3128... connected. Proxy request sent, awaiting response... 200 OK Length: 21693 (21K) Saving to: 'ulm.cc' 0K .......... .......... . 100% 16.2M=0.001s 2017-04-28 13:53:48 (16.2 MB/s) - 'ulm.cc' saved [21693/21693] $shell> g++ -Wall -std=c++11 -o ulm ulm.cc $shell> ls ulm ulm.cc $shell>
File format for a program in machine code
-
The code must be represented as a sequence of hex digits
-
Spaces and newlines in the file are ignored
-
The character # is ignored as well as all following characters until the next newline. This is used for having human readable comments embedded in the machine code.
Here the content of the example program:
81 20 00 05 # orq $32, %0, %5 11 05 F8 0A # movq -8(%5), %10 00 00 00 00 # halt 00 00 00 00 # halt 00 00 00 00 # halt 00 00 00 00 # halt FF FF FF FF # .quad -1 FF FF FF FF #
Demo for testing the simulator
First download the demo (in case you haven't done already):
$shell> wget http://www.mathematik.uni-ulm.de/~lehn/example.ulm --2017-04-28 13:53:50-- http://www.mathematik.uni-ulm.de/~lehn/example.ulm Resolving www-proxy.uni-ulm.de... 134.60.1.151 Connecting to www-proxy.uni-ulm.de|134.60.1.151|:3128... connected. Proxy request sent, awaiting response... 200 OK Length: 213 Saving to: 'example.ulm.5' 0K 100% 36.0M=0s 2017-04-28 13:53:50 (36.0 MB/s) - 'example.ulm.5' saved [213/213] $shell>
Then simple run the simulator ulm as follows:
ulm example.ulm
By default the simulator runs in interactive mode. So it only executes an instruction if you hit the enter-key.
With the option -r (run) you can run the code in non-interactive mode. For example:
$shell> ulm -r example.ulm CPU cycles done 0 --------------------------------------------------------------------------------------------------------------------------- 81 20 00 05 11 05 f8 0a 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff ff ff ff ff ff 00 00 00 00 00 00 00 00 00 --------------------------------------------------------------------------------------------------------------------------- |0 |8 |16 |24 |32 |40 |0x0 |0x8 |0x10 |0x18 |0x20 |0x28 --------------------------------------------------------------------------------------------------------------------------- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 --------------------------------------------------------------------------------------------------------------------------- |40 |48 |56 |64 |72 |80 |0x28 |0x30 |0x38 |0x40 |0x48 |0x50 --------------------------------------------------------------------------------------------------------------------------- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 --------------------------------------------------------------------------------------------------------------------------- |80 |88 |96 |104 |112 |120 |0x50 |0x58 |0x60 |0x68 |0x70 |0x78 --------------------------------------------------------------------------------------------------------------------------- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 --------------------------------------------------------------------------------------------------------------------------- |120 |128 |136 |144 |152 |160 |0x78 |0x80 |0x88 |0x90 |0x98 |0xa0 Reg0 0x0000000000000000 Reg1 0x0000000000000000 IP: 0 Reg2 0x0000000000000000 IR: halt Reg3 0x00000000000000a0 Reg4 0xfeffa910fef90a10 Reg5 0xfefe210efec2c720 Reg6 0x0000075e000000a2 Reg7 0x705f5f00feffa910 Reg8 0xfec287d0fef90a10 Reg9 0xfefe210efef90b00 Reg10 0x000011af000006fb Reg11 0x3774534efeffa910 Reg12 0x08046ad43874534e Reg13 0xfee2e41dfefc7976 Reg14 0x08046b28fee2e41d Reg15 0xfeffa910fef903a8 ZF = 0, OF = 0, SF = 0, CF = 0 Terminal: CPU cycles done 1 --------------------------------------------------------------------------------------------------------------------------- 81 20 00 05 11 05 f8 0a 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff ff ff ff ff ff 00 00 00 00 00 00 00 00 00 --------------------------------------------------------------------------------------------------------------------------- |0 |8 |16 |24 |32 |40 |0x0 |0x8 |0x10 |0x18 |0x20 |0x28 --------------------------------------------------------------------------------------------------------------------------- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 --------------------------------------------------------------------------------------------------------------------------- |40 |48 |56 |64 |72 |80 |0x28 |0x30 |0x38 |0x40 |0x48 |0x50 --------------------------------------------------------------------------------------------------------------------------- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 --------------------------------------------------------------------------------------------------------------------------- |80 |88 |96 |104 |112 |120 |0x50 |0x58 |0x60 |0x68 |0x70 |0x78 --------------------------------------------------------------------------------------------------------------------------- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 --------------------------------------------------------------------------------------------------------------------------- |120 |128 |136 |144 |152 |160 |0x78 |0x80 |0x88 |0x90 |0x98 |0xa0 Reg0 0x0000000000000000 Reg1 0x0000000000000004 IP: 4 Reg2 0x0000000081200005 IR: orq $32, %0, %5 Reg3 0x00000000000000a0 Reg4 0xfeffa910fef90a10 Reg5 0x0000000000000020 Reg6 0x0000075e000000a2 Reg7 0x705f5f00feffa910 Reg8 0xfec287d0fef90a10 Reg9 0xfefe210efef90b00 Reg10 0x000011af000006fb Reg11 0x3774534efeffa910 Reg12 0x08046ad43874534e Reg13 0xfee2e41dfefc7976 Reg14 0x08046b28fee2e41d Reg15 0xfeffa910fef903a8 ZF = 0, OF = 0, SF = 0, CF = 0 Terminal: CPU cycles done 2 --------------------------------------------------------------------------------------------------------------------------- 81 20 00 05 11 05 f8 0a 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff ff ff ff ff ff 00 00 00 00 00 00 00 00 00 --------------------------------------------------------------------------------------------------------------------------- |0 |8 |16 |24 |32 |40 |0x0 |0x8 |0x10 |0x18 |0x20 |0x28 --------------------------------------------------------------------------------------------------------------------------- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 --------------------------------------------------------------------------------------------------------------------------- |40 |48 |56 |64 |72 |80 |0x28 |0x30 |0x38 |0x40 |0x48 |0x50 --------------------------------------------------------------------------------------------------------------------------- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 --------------------------------------------------------------------------------------------------------------------------- |80 |88 |96 |104 |112 |120 |0x50 |0x58 |0x60 |0x68 |0x70 |0x78 --------------------------------------------------------------------------------------------------------------------------- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 --------------------------------------------------------------------------------------------------------------------------- |120 |128 |136 |144 |152 |160 |0x78 |0x80 |0x88 |0x90 |0x98 |0xa0 Reg0 0x0000000000000000 Reg1 0x0000000000000008 IP: 8 Reg2 0x000000001105f80a IR: movq -8(%5), %10 Reg3 0x00000000000000a0 Reg4 0xfeffa910fef90a10 Reg5 0x0000000000000020 Reg6 0x0000075e000000a2 Reg7 0x705f5f00feffa910 Reg8 0xfec287d0fef90a10 Reg9 0xfefe210efef90b00 Reg10 0xffffffffffffffff Reg11 0x3774534efeffa910 Reg12 0x08046ad43874534e Reg13 0xfee2e41dfefc7976 Reg14 0x08046b28fee2e41d Reg15 0xfeffa910fef903a8 ZF = 0, OF = 0, SF = 0, CF = 0 Terminal: CPU cycles done 3 --------------------------------------------------------------------------------------------------------------------------- 81 20 00 05 11 05 f8 0a 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff ff ff ff ff ff 00 00 00 00 00 00 00 00 00 --------------------------------------------------------------------------------------------------------------------------- |0 |8 |16 |24 |32 |40 |0x0 |0x8 |0x10 |0x18 |0x20 |0x28 --------------------------------------------------------------------------------------------------------------------------- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 --------------------------------------------------------------------------------------------------------------------------- |40 |48 |56 |64 |72 |80 |0x28 |0x30 |0x38 |0x40 |0x48 |0x50 --------------------------------------------------------------------------------------------------------------------------- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 --------------------------------------------------------------------------------------------------------------------------- |80 |88 |96 |104 |112 |120 |0x50 |0x58 |0x60 |0x68 |0x70 |0x78 --------------------------------------------------------------------------------------------------------------------------- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 --------------------------------------------------------------------------------------------------------------------------- |120 |128 |136 |144 |152 |160 |0x78 |0x80 |0x88 |0x90 |0x98 |0xa0 Reg0 0x0000000000000000 Reg1 0x000000000000000c IP: 12 Reg2 0x0000000000000000 IR: halt Reg3 0x00000000000000a0 Reg4 0xfeffa910fef90a10 Reg5 0x0000000000000020 Reg6 0x0000075e000000a2 Reg7 0x705f5f00feffa910 Reg8 0xfec287d0fef90a10 Reg9 0xfefe210efef90b00 Reg10 0xffffffffffffffff Reg11 0x3774534efeffa910 Reg12 0x08046ad43874534e Reg13 0xfee2e41dfefc7976 Reg14 0x08046b28fee2e41d Reg15 0xfeffa910fef903a8 ZF = 0, OF = 0, SF = 0, CF = 0 Terminal: $shell>
Exercise
Download the following code with wget http://www.mathematik.uni-ulm.de/~lehn/exercise1.ulm:
81 28 00 05 11 05 00 05 81 01 00 06 9A 00 00 03 70 05 06 06 63 01 05 05 63 01 05 00 95 FF FF FD 41 06 01 08 00 00 00 00 00 00 00 00 00 00 00 00
Add brief comments to each line that describes what the machine instruction is supposed to do.
Exercise
You should have simulated by hand what happens when you run exercise1.ulm on the ULM. Validate your result with the simulator.
Exercise
What does the program compute? Describe its algorithm with a graph.