Installation und Verwendung des ULM-Assembler
Der ULM-Assembler besteht aus drei Gnu-AWK Skripten, die ihr mit wget laden könnt:
$shell> pwd /home/numerik/hpc/ss16/session02/demo $shell> wget http://www.mathematik.uni-ulm.de/~lehn/ulmas1.awk --2016-04-29 13:49:28-- http://www.mathematik.uni-ulm.de/~lehn/ulmas1.awk 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: 1409 (1.4K) Saving to: 'ulmas1.awk.6' 0K . 100% 207M=0s 2016-04-29 13:49:28 (207 MB/s) - 'ulmas1.awk.6' saved [1409/1409] $shell> wget http://www.mathematik.uni-ulm.de/~lehn/ulmas2.awk --2016-04-29 13:49:28-- http://www.mathematik.uni-ulm.de/~lehn/ulmas2.awk 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: 2216 (2.2K) Saving to: 'ulmas2.awk.6' 0K .. 100% 331M=0s 2016-04-29 13:49:28 (331 MB/s) - 'ulmas2.awk.6' saved [2216/2216] $shell> wget http://www.mathematik.uni-ulm.de/~lehn/ulmas3.awk --2016-04-29 13:49:28-- http://www.mathematik.uni-ulm.de/~lehn/ulmas3.awk 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: 4683 (4.6K) Saving to: 'ulmas3.awk.6' 0K .... 100% 620M=0s 2016-04-29 13:49:28 (620 MB/s) - 'ulmas3.awk.6' saved [4683/4683] $shell>
Beispiel für ein Assemblerprogramm
.equ ZERO, 0 .equ RIP, 1 .equ ERG, 6 .equ N, 5 .macro set VALUE, REGISTER orq \VALUE, %ZERO, \REGISTER .endm .text set $n, %N movq (%N), %N subq $0, %N, %ZERO jz isZero subq $1, %N, %N jmp endif isZero: addq $1, %N, %N endif: movq %N, n(%RIP) halt .data n: .quad 3
Verwendung des ULM-Assembler
Die drei Skripte können mit Hilfe von Pipelines verbunden werden:
$shell> cat example.s | gawk -f ulmas1.awk | gawk -f ulmas2.awk | gawk -f ulmas3.awk 81 28 00 05 # 0000 : orq $40, %0, %5 11 05 00 05 # 0004 : movq (%5), %5 63 00 05 00 # 0008 : subq $0, %5, %0 91 00 00 03 # 000C : jz $3 63 01 05 05 # 0010 : subq $1, %5, %5 90 00 00 02 # 0014 : jmp $2 61 01 05 05 # 0018 : addq $1, %5, %5 41 05 01 0C # 001C : movq %5, 12(%1) 00 00 00 00 # 0020 : halt FF FF FF FF # 0028 : (padding) 00 00 00 00 # 0028 00 00 00 03 # 002C $shell>
Man kann auch die Resultate der Zwischenschritte ausgegebn lassen:
-
Macros werden expandiert
$shell> cat example.s | gawk -f ulmas1.awk .text orq $n, %0, %5 movq (%5), %5 subq $0, %5, %0 jz isZero subq $1, %5, %5 jmp endif isZero: addq $1, %5, %5 endif: movq %5, n(%1) halt .data n: .quad 3 $shell>
-
Label werden aufgelöst
$shell> cat example.s | gawk -f ulmas1.awk | gawk -f ulmas2.awk orq $40, %0, %5 movq (%5), %5 subq $0, %5, %0 jz $3 subq $1, %5, %5 jmp $2 addq $1, %5, %5 movq %5, 12(%1) halt FF FF FF FF # 0028 : (padding) 00 00 00 00 # 0028 00 00 00 03 # 002C $shell>
-
Code wird generiert
$shell> cat example.s | gawk -f ulmas1.awk | gawk -f ulmas2.awk | gawk -f ulmas3.awk 81 28 00 05 # 0000 : orq $40, %0, %5 11 05 00 05 # 0004 : movq (%5), %5 63 00 05 00 # 0008 : subq $0, %5, %0 91 00 00 03 # 000C : jz $3 63 01 05 05 # 0010 : subq $1, %5, %5 90 00 00 02 # 0014 : jmp $2 61 01 05 05 # 0018 : addq $1, %5, %5 41 05 01 0C # 001C : movq %5, 12(%1) 00 00 00 00 # 0020 : halt FF FF FF FF # 0028 : (padding) 00 00 00 00 # 0028 00 00 00 03 # 002C $shell>
Das Ergebnis kann dann direkt in eine Datei (hier example.ulm) gelenkt werden:
$shell> cat example.s | gawk -f ulmas1.awk | gawk -f ulmas2.awk | gawk -f ulmas3.awk > example.ulm $shell>
Ausführen mit der ULM
$shell> ./ulm -r example.ulm CPU cycles done 0 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 81 28 00 05 11 05 00 05 63 00 05 00 91 00 00 03 63 01 05 05 90 00 00 02 61 01 05 05 41 05 01 0c 00 00 00 00 ff ff ff ff 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |0 |8 |16 |24 |32 |40 |48 |56 |0x0 |0x8 |0x10 |0x18 |0x20 |0x28 |0x30 |0x38 Reg0 0x0000000000000000 Reg1 0x0000000000000000 IP: 0 Reg2 0x0000000000000000 IR: halt Reg3 0x0000000001b3a570 Reg4 0x000000000000000a Reg5 0x00007f5700000000 Reg6 0x00007ffc8f0d5220 Reg7 0x00007ffc8f0d5570 Reg8 0x0000000000000000 Reg9 0x00007ffc8f0d5870 Reg10 0x00007ffc8f0d58e0 Reg11 0x00007f57e1b17028 Reg12 0x0000000000000000 Reg13 0x00007f57e10f1e4f Reg14 0x00007ffc8f0d5380 Reg15 0x00007f57e19261e2 ZF = 0, OF = 0, SF = 0, CF = 0 CPU cycles done 1 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 81 28 00 05 11 05 00 05 63 00 05 00 91 00 00 03 63 01 05 05 90 00 00 02 61 01 05 05 41 05 01 0c 00 00 00 00 ff ff ff ff 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |0 |8 |16 |24 |32 |40 |48 |56 |0x0 |0x8 |0x10 |0x18 |0x20 |0x28 |0x30 |0x38 Reg0 0x0000000000000000 Reg1 0x0000000000000004 IP: 4 Reg2 0x0000000081280005 IR: orq $40, %0, %5 Reg3 0x0000000001b3a570 Reg4 0x000000000000000a Reg5 0x0000000000000028 Reg6 0x00007ffc8f0d5220 Reg7 0x00007ffc8f0d5570 Reg8 0x0000000000000000 Reg9 0x00007ffc8f0d5870 Reg10 0x00007ffc8f0d58e0 Reg11 0x00007f57e1b17028 Reg12 0x0000000000000000 Reg13 0x00007f57e10f1e4f Reg14 0x00007ffc8f0d5380 Reg15 0x00007f57e19261e2 ZF = 0, OF = 0, SF = 0, CF = 0 CPU cycles done 2 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 81 28 00 05 11 05 00 05 63 00 05 00 91 00 00 03 63 01 05 05 90 00 00 02 61 01 05 05 41 05 01 0c 00 00 00 00 ff ff ff ff 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |0 |8 |16 |24 |32 |40 |48 |56 |0x0 |0x8 |0x10 |0x18 |0x20 |0x28 |0x30 |0x38 Reg0 0x0000000000000000 Reg1 0x0000000000000008 IP: 8 Reg2 0x0000000011050005 IR: movq 0(%5), %5 Reg3 0x0000000001b3a570 Reg4 0x000000000000000a Reg5 0x0000000000000003 Reg6 0x00007ffc8f0d5220 Reg7 0x00007ffc8f0d5570 Reg8 0x0000000000000000 Reg9 0x00007ffc8f0d5870 Reg10 0x00007ffc8f0d58e0 Reg11 0x00007f57e1b17028 Reg12 0x0000000000000000 Reg13 0x00007f57e10f1e4f Reg14 0x00007ffc8f0d5380 Reg15 0x00007f57e19261e2 ZF = 0, OF = 0, SF = 0, CF = 0 CPU cycles done 3 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 81 28 00 05 11 05 00 05 63 00 05 00 91 00 00 03 63 01 05 05 90 00 00 02 61 01 05 05 41 05 01 0c 00 00 00 00 ff ff ff ff 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |0 |8 |16 |24 |32 |40 |48 |56 |0x0 |0x8 |0x10 |0x18 |0x20 |0x28 |0x30 |0x38 Reg0 0x0000000000000003 Reg1 0x000000000000000c IP: 12 Reg2 0x0000000063000500 IR: subq $0, %5, %0 Reg3 0x0000000001b3a570 Reg4 0x000000000000000a Reg5 0x0000000000000003 Reg6 0x00007ffc8f0d5220 Reg7 0x00007ffc8f0d5570 Reg8 0x0000000000000000 Reg9 0x00007ffc8f0d5870 Reg10 0x00007ffc8f0d58e0 Reg11 0x00007f57e1b17028 Reg12 0x0000000000000000 Reg13 0x00007f57e10f1e4f Reg14 0x00007ffc8f0d5380 Reg15 0x00007f57e19261e2 ZF = 0, OF = 0, SF = 0, CF = 0 CPU cycles done 4 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 81 28 00 05 11 05 00 05 63 00 05 00 91 00 00 03 63 01 05 05 90 00 00 02 61 01 05 05 41 05 01 0c 00 00 00 00 ff ff ff ff 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |0 |8 |16 |24 |32 |40 |48 |56 |0x0 |0x8 |0x10 |0x18 |0x20 |0x28 |0x30 |0x38 Reg0 0x0000000000000003 Reg1 0x0000000000000010 IP: 16 Reg2 0x0000000091000003 IR: jz @+$3 Reg3 0x0000000001b3a570 Reg4 0x000000000000000a Reg5 0x0000000000000003 Reg6 0x00007ffc8f0d5220 Reg7 0x00007ffc8f0d5570 Reg8 0x0000000000000000 Reg9 0x00007ffc8f0d5870 Reg10 0x00007ffc8f0d58e0 Reg11 0x00007f57e1b17028 Reg12 0x0000000000000000 Reg13 0x00007f57e10f1e4f Reg14 0x00007ffc8f0d5380 Reg15 0x00007f57e19261e2 ZF = 0, OF = 0, SF = 0, CF = 0 CPU cycles done 5 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 81 28 00 05 11 05 00 05 63 00 05 00 91 00 00 03 63 01 05 05 90 00 00 02 61 01 05 05 41 05 01 0c 00 00 00 00 ff ff ff ff 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |0 |8 |16 |24 |32 |40 |48 |56 |0x0 |0x8 |0x10 |0x18 |0x20 |0x28 |0x30 |0x38 Reg0 0x0000000000000003 Reg1 0x0000000000000014 IP: 20 Reg2 0x0000000063010505 IR: subq $1, %5, %5 Reg3 0x0000000001b3a570 Reg4 0x000000000000000a Reg5 0x0000000000000002 Reg6 0x00007ffc8f0d5220 Reg7 0x00007ffc8f0d5570 Reg8 0x0000000000000000 Reg9 0x00007ffc8f0d5870 Reg10 0x00007ffc8f0d58e0 Reg11 0x00007f57e1b17028 Reg12 0x0000000000000000 Reg13 0x00007f57e10f1e4f Reg14 0x00007ffc8f0d5380 Reg15 0x00007f57e19261e2 ZF = 0, OF = 0, SF = 0, CF = 1 CPU cycles done 6 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 81 28 00 05 11 05 00 05 63 00 05 00 91 00 00 03 63 01 05 05 90 00 00 02 61 01 05 05 41 05 01 0c 00 00 00 00 ff ff ff ff 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |0 |8 |16 |24 |32 |40 |48 |56 |0x0 |0x8 |0x10 |0x18 |0x20 |0x28 |0x30 |0x38 Reg0 0x0000000000000003 Reg1 0x000000000000001c IP: 28 Reg2 0x0000000090000002 IR: jmp @+$2 Reg3 0x0000000001b3a570 Reg4 0x000000000000000a Reg5 0x0000000000000002 Reg6 0x00007ffc8f0d5220 Reg7 0x00007ffc8f0d5570 Reg8 0x0000000000000000 Reg9 0x00007ffc8f0d5870 Reg10 0x00007ffc8f0d58e0 Reg11 0x00007f57e1b17028 Reg12 0x0000000000000000 Reg13 0x00007f57e10f1e4f Reg14 0x00007ffc8f0d5380 Reg15 0x00007f57e19261e2 ZF = 0, OF = 0, SF = 0, CF = 1 CPU cycles done 7 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 81 28 00 05 11 05 00 05 63 00 05 00 91 00 00 03 63 01 05 05 90 00 00 02 61 01 05 05 41 05 01 0c 00 00 00 00 ff ff ff ff 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |0 |8 |16 |24 |32 |40 |48 |56 |0x0 |0x8 |0x10 |0x18 |0x20 |0x28 |0x30 |0x38 Reg0 0x0000000000000003 Reg1 0x0000000000000020 IP: 32 Reg2 0x000000004105010c IR: movq %5, 12(%1) Reg3 0x0000000001b3a570 Reg4 0x000000000000000a Reg5 0x0000000000000002 Reg6 0x00007ffc8f0d5220 Reg7 0x00007ffc8f0d5570 Reg8 0x0000000000000000 Reg9 0x00007ffc8f0d5870 Reg10 0x00007ffc8f0d58e0 Reg11 0x00007f57e1b17028 Reg12 0x0000000000000000 Reg13 0x00007f57e10f1e4f Reg14 0x00007ffc8f0d5380 Reg15 0x00007f57e19261e2 ZF = 0, OF = 0, SF = 0, CF = 1 CPU cycles done 8 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 81 28 00 05 11 05 00 05 63 00 05 00 91 00 00 03 63 01 05 05 90 00 00 02 61 01 05 05 41 05 01 0c 00 00 00 00 ff ff ff ff 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |0 |8 |16 |24 |32 |40 |48 |56 |0x0 |0x8 |0x10 |0x18 |0x20 |0x28 |0x30 |0x38 Reg0 0x0000000000000003 Reg1 0x0000000000000024 IP: 36 Reg2 0x0000000000000000 IR: halt Reg3 0x0000000001b3a570 Reg4 0x000000000000000a Reg5 0x0000000000000002 Reg6 0x00007ffc8f0d5220 Reg7 0x00007ffc8f0d5570 Reg8 0x0000000000000000 Reg9 0x00007ffc8f0d5870 Reg10 0x00007ffc8f0d58e0 Reg11 0x00007f57e1b17028 Reg12 0x0000000000000000 Reg13 0x00007f57e10f1e4f Reg14 0x00007ffc8f0d5380 Reg15 0x00007f57e19261e2 ZF = 0, OF = 0, SF = 0, CF = 1 $shell>