Add insn examples.

This commit is contained in:
John Winans 2018-05-19 15:23:00 -05:00
parent 27e5dd4f94
commit 3fbb8f9642
26 changed files with 330 additions and 4 deletions

View File

@ -1,5 +1,7 @@
SUBDIRS=\
nop\
li\
ebreak
TOP=.

View File

@ -1,8 +1,4 @@
ebreak: file format elf32-littleriscv
Disassembly of section .text:
00000000 <_start>:
0: 00100073 ebreak

1
book/programs/src/li/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
li

View File

@ -0,0 +1,18 @@
PROG=li
all:: $(PROG).out $(PROG).lst
$(PROG).out:: $(PROG).bin
./run.sh > $@ 2>&1
$(PROG).bin:: $(PROG)
clean::
rm -f $(PROG) *.o *.lst *.bin *.srec *.out
TOP=..
include $(TOP)/Make.rules

12
book/programs/src/li/li.S Normal file
View File

@ -0,0 +1,12 @@
.text # put this into the text section
.align 2 # align to a multiple of 4
.globl _start
_start:
li t0, 0x12345678
li t1, 0x11111fff
li t1, 0
li t1, -1
li t1, 1
li t1, 0xf1f1f1f1
ebreak

View File

@ -0,0 +1,13 @@
li: file format elf32-littleriscv
Disassembly of section .text:
00000000 <_start>:
0: 123452b7 lui t0,0x12345
4: 67828293 addi t0,t0,1656 # 12345678 <__global_pointer$+0x12343e50>
8: 11112337 lui t1,0x11112
c: fff30313 addi t1,t1,-1 # 11111fff <__global_pointer$+0x111107d7>
10: 00000313 li t1,0
14: fff00313 li t1,-1
18: 00100313 li t1,1
1c: f1f1f337 lui t1,0xf1f1f
20: 1f130313 addi t1,t1,497 # f1f1f1f1 <__global_pointer$+0xf1f1d9c9>
24: 00100073 ebreak

View File

@ -0,0 +1,68 @@
$ rvddt -f li.bin
sp initialized to top of memory: 0x0000fff0
Loading 'li.bin' to 0x0
This is rvddt. Enter ? for help.
ddt> d 0 16
00000000: b7 52 34 12 93 82 82 67-37 23 11 11 13 03 f3 ff *.R4....g7#......*
ddt> t 0 1000
x0 00000000 f0f0f0f0 0000fff0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x8 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x16 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x24 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
pc 00000000
00000000: 123452b7 lui x5, 0x12345 # x5 = 0x12345000
x0 00000000 f0f0f0f0 0000fff0 f0f0f0f0-f0f0f0f0 12345000 f0f0f0f0 f0f0f0f0
x8 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x16 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x24 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
pc 00000004
00000004: 67828293 addi x5, x5, 1656 # x5 = 0x12345678 = 0x12345000 + 0x00000678
x0 00000000 f0f0f0f0 0000fff0 f0f0f0f0-f0f0f0f0 12345678 f0f0f0f0 f0f0f0f0
x8 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x16 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x24 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
pc 00000008
00000008: 11112337 lui x6, 0x11112 # x6 = 0x11112000
x0 00000000 f0f0f0f0 0000fff0 f0f0f0f0-f0f0f0f0 12345678 11112000 f0f0f0f0
x8 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x16 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x24 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
pc 0000000c
0000000c: fff30313 addi x6, x6, -1 # x6 = 0x11111fff = 0x11112000 + 0xffffffff
x0 00000000 f0f0f0f0 0000fff0 f0f0f0f0-f0f0f0f0 12345678 11111fff f0f0f0f0
x8 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x16 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x24 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
pc 00000010
00000010: 00000313 addi x6, x0, 0 # x6 = 0x00000000 = 0x00000000 + 0x00000000
x0 00000000 f0f0f0f0 0000fff0 f0f0f0f0-f0f0f0f0 12345678 00000000 f0f0f0f0
x8 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x16 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x24 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
pc 00000014
00000014: fff00313 addi x6, x0, -1 # x6 = 0xffffffff = 0x00000000 + 0xffffffff
x0 00000000 f0f0f0f0 0000fff0 f0f0f0f0-f0f0f0f0 12345678 ffffffff f0f0f0f0
x8 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x16 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x24 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
pc 00000018
00000018: 00100313 addi x6, x0, 1 # x6 = 0x00000001 = 0x00000000 + 0x00000001
x0 00000000 f0f0f0f0 0000fff0 f0f0f0f0-f0f0f0f0 12345678 00000001 f0f0f0f0
x8 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x16 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x24 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
pc 0000001c
0000001c: f1f1f337 lui x6, 0xf1f1f # x6 = 0xf1f1f000
x0 00000000 f0f0f0f0 0000fff0 f0f0f0f0-f0f0f0f0 12345678 f1f1f000 f0f0f0f0
x8 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x16 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x24 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
pc 00000020
00000020: 1f130313 addi x6, x6, 497 # x6 = 0xf1f1f1f1 = 0xf1f1f000 + 0x000001f1
x0 00000000 f0f0f0f0 0000fff0 f0f0f0f0-f0f0f0f0 12345678 f1f1f1f1 f0f0f0f0
x8 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x16 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x24 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
pc 00000024
00000024: ebreak
ddt> x

7
book/programs/src/li/run.sh Executable file
View File

@ -0,0 +1,7 @@
prompt="$"
cmd="rvddt -f li.bin"
echo "$prompt $cmd"
$cmd <<!
d 0 16
t 0 1000
!

1
book/programs/src/mv/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
mv

View File

@ -0,0 +1,18 @@
PROG=mv
all:: $(PROG).out $(PROG).lst
$(PROG).out:: $(PROG).bin
./run.sh > $@ 2>&1
$(PROG).bin:: $(PROG)
clean::
rm -f $(PROG) *.o *.lst *.bin *.srec *.out
TOP=..
include $(TOP)/Make.rules

View File

@ -0,0 +1,9 @@
.text # put this into the text section
.align 2 # align to a multiple of 4
.globl _start
_start:
addi t3, t4, 0 # t3 = t4
mv t3, t4 # t3 = t4
ebreak

View File

@ -0,0 +1,6 @@
mv: file format elf32-littleriscv
Disassembly of section .text:
00000000 <_start>:
0: 000e8e13 mv t3,t4
4: 000e8e13 mv t3,t4
8: 00100073 ebreak

View File

@ -0,0 +1,26 @@
$ rvddt -f mv.bin
sp initialized to top of memory: 0x0000fff0
Loading 'mv.bin' to 0x0
This is rvddt. Enter ? for help.
ddt> d 0 16
00000000: 13 8e 0e 00 13 8e 0e 00-73 00 10 00 a5 a5 a5 a5 *........s.......*
ddt> t 0 1000
x0 00000000 f0f0f0f0 0000fff0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x8 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x16 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x24 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
pc 00000000
00000000: 000e8e13 addi x28, x29, 0 # x28 = 0xf0f0f0f0 = 0xf0f0f0f0 + 0x00000000
x0 00000000 f0f0f0f0 0000fff0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x8 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x16 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x24 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
pc 00000004
00000004: 000e8e13 addi x28, x29, 0 # x28 = 0xf0f0f0f0 = 0xf0f0f0f0 + 0x00000000
x0 00000000 f0f0f0f0 0000fff0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x8 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x16 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x24 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
pc 00000008
00000008: ebreak
ddt> x

7
book/programs/src/mv/run.sh Executable file
View File

@ -0,0 +1,7 @@
prompt="$"
cmd="rvddt -f mv.bin"
echo "$prompt $cmd"
$cmd <<!
d 0 16
t 0 1000
!

1
book/programs/src/mvzero/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
mv

View File

@ -0,0 +1,18 @@
PROG=mv
all:: $(PROG).out $(PROG).lst
$(PROG).out:: $(PROG).bin
./run.sh > $@ 2>&1
$(PROG).bin:: $(PROG)
clean::
rm -f $(PROG) *.o *.lst *.bin *.srec *.out
TOP=..
include $(TOP)/Make.rules

View File

@ -0,0 +1,8 @@
.text # put this into the text section
.align 2 # align to a multiple of 4
.globl _start
_start:
mv t3, x0 # t3 = 0
ebreak

View File

@ -0,0 +1,5 @@
mv: file format elf32-littleriscv
Disassembly of section .text:
00000000 <_start>:
0: 00000e13 li t3,0
4: 00100073 ebreak

View File

@ -0,0 +1,29 @@
$ rvddt -f mv.bin
sp initialized to top of memory: 0x0000fff0
Loading 'mv.bin' to 0x0
This is rvddt. Enter ? for help.
ddt> a
ddt> d 0 16
00000000: 13 0e 00 00 73 00 10 00-a5 a5 a5 a5 a5 a5 a5 a5 *....s...........*
ddt> t 0 1000
zero x0 00000000 ra x1 f0f0f0f0 sp x2 0000fff0 gp x3 f0f0f0f0
tp x4 f0f0f0f0 t0 x5 f0f0f0f0 t1 x6 f0f0f0f0 t2 x7 f0f0f0f0
s0 x8 f0f0f0f0 s1 x9 f0f0f0f0 a0 x10 f0f0f0f0 a1 x11 f0f0f0f0
a2 x12 f0f0f0f0 a3 x13 f0f0f0f0 a4 x14 f0f0f0f0 a5 x15 f0f0f0f0
a6 x16 f0f0f0f0 a7 x17 f0f0f0f0 s2 x18 f0f0f0f0 s3 x19 f0f0f0f0
s4 x20 f0f0f0f0 s5 x21 f0f0f0f0 s6 x22 f0f0f0f0 s7 x23 f0f0f0f0
s8 x24 f0f0f0f0 s9 x25 f0f0f0f0 s10 x26 f0f0f0f0 S11 x27 f0f0f0f0
t3 x28 f0f0f0f0 t4 x29 f0f0f0f0 t5 x30 f0f0f0f0 t6 x31 f0f0f0f0
pc 00000000
00000000: 00000e13 addi t3, zero, 0 # t3 = 0x00000000 = 0x00000000 + 0x00000000
zero x0 00000000 ra x1 f0f0f0f0 sp x2 0000fff0 gp x3 f0f0f0f0
tp x4 f0f0f0f0 t0 x5 f0f0f0f0 t1 x6 f0f0f0f0 t2 x7 f0f0f0f0
s0 x8 f0f0f0f0 s1 x9 f0f0f0f0 a0 x10 f0f0f0f0 a1 x11 f0f0f0f0
a2 x12 f0f0f0f0 a3 x13 f0f0f0f0 a4 x14 f0f0f0f0 a5 x15 f0f0f0f0
a6 x16 f0f0f0f0 a7 x17 f0f0f0f0 s2 x18 f0f0f0f0 s3 x19 f0f0f0f0
s4 x20 f0f0f0f0 s5 x21 f0f0f0f0 s6 x22 f0f0f0f0 s7 x23 f0f0f0f0
s8 x24 f0f0f0f0 s9 x25 f0f0f0f0 s10 x26 f0f0f0f0 S11 x27 f0f0f0f0
t3 x28 00000000 t4 x29 f0f0f0f0 t5 x30 f0f0f0f0 t6 x31 f0f0f0f0
pc 00000004
00000004: ebreak
ddt> x

View File

@ -0,0 +1,8 @@
prompt="$"
cmd="rvddt -f mv.bin"
echo "$prompt $cmd"
$cmd <<!
a
d 0 16
t 0 1000
!

1
book/programs/src/nop/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
nop

View File

@ -0,0 +1,18 @@
PROG=nop
all:: $(PROG).out $(PROG).lst
$(PROG).out:: $(PROG).bin
./run.sh > $@ 2>&1
$(PROG).bin:: $(PROG)
clean::
rm -f $(PROG) *.o *.lst *.bin *.srec *.out
TOP=..
include $(TOP)/Make.rules

View File

@ -0,0 +1,9 @@
.text # put this into the text section
.align 2 # align to a multiple of 4
.globl _start
_start:
addi x0, x0, 0 # these two instructions assemble into the same thing!
nop
ebreak

View File

@ -0,0 +1,6 @@
nop: file format elf32-littleriscv
Disassembly of section .text:
00000000 <_start>:
0: 00000013 nop
4: 00000013 nop
8: 00100073 ebreak

View File

@ -0,0 +1,32 @@
$ rvddt -f nop.bin
sp initialized to top of memory: 0x0000fff0
Loading 'nop.bin' to 0x0
This is rvddt. Enter ? for help.
ddt> d 0 16
00000000: 13 00 00 00 13 00 00 00-73 00 10 00 a5 a5 a5 a5 *........s.......*
ddt> t 0 1000
x0 00000000 f0f0f0f0 0000fff0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x8 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x16 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x24 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
pc 00000000
00000000: 00000013 addi x0, x0, 0 # x0 = 0x00000000 = 0x00000000 + 0x00000000
x0 00000000 f0f0f0f0 0000fff0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x8 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x16 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x24 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
pc 00000004
00000004: 00000013 addi x0, x0, 0 # x0 = 0x00000000 = 0x00000000 + 0x00000000
x0 00000000 f0f0f0f0 0000fff0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x8 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x16 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x24 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
pc 00000008
00000008: ebreak
ddt> r
x0 00000000 f0f0f0f0 0000fff0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x8 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x16 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
x24 f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0-f0f0f0f0 f0f0f0f0 f0f0f0f0 f0f0f0f0
pc 00000008
ddt> x

7
book/programs/src/nop/run.sh Executable file
View File

@ -0,0 +1,7 @@
prompt="$"
cmd="rvddt -f nop.bin"
echo "$prompt $cmd"
$cmd <<!
d 0 16
t 0 1000
!