mirror of
https://github.com/foxsen/archbase.git
synced 2026-11-03 22:24:53 +08:00
initial import to public repository
This commit is contained in:
13
materials/chapter2/add_and_ref.S
Normal file
13
materials/chapter2/add_and_ref.S
Normal file
@@ -0,0 +1,13 @@
|
||||
add:
|
||||
add.w $a0, $a0, $a1 //a+b
|
||||
jr $ra //return
|
||||
ref:
|
||||
addi.d $sp, $sp, -16 //stack allocate
|
||||
addi.w $a1, $r0, 34 //t2=34
|
||||
addi.w $a0, $r0, 12 //t1=12
|
||||
st.d $ra, $sp, 8 //save $ra
|
||||
bl add //call add()
|
||||
ld.d $ra, $sp, 8 //restore $ra
|
||||
addi.d $sp, $sp, 16 //stack release
|
||||
jr $ra //return
|
||||
|
||||
13
materials/chapter2/add_and_ref.c
Normal file
13
materials/chapter2/add_and_ref.c
Normal file
@@ -0,0 +1,13 @@
|
||||
int add(int a,int b)
|
||||
{
|
||||
return a+b;
|
||||
}
|
||||
|
||||
int ref(void)
|
||||
{
|
||||
|
||||
int t1 = 12;
|
||||
int t2 = 34;
|
||||
|
||||
return add(t1,t2);
|
||||
}
|
||||
8
materials/chapter2/addr_compare.csv
Normal file
8
materials/chapter2/addr_compare.csv
Normal file
@@ -0,0 +1,8 @@
|
||||
寻址方式,MIPS,PowerPC,PA-RISC,SPARC,LoongArch
|
||||
寄存器寻址,Y,Y,Y,Y,Y
|
||||
立即数寻址,Y,Y,Y,Y,Y
|
||||
偏移量寻址,Y,Y,Y,Y,Y
|
||||
变址寻址,Y(仅浮点),Y,Y,Y,Y
|
||||
比例变址寻址,,,Y,,
|
||||
自增/自减+偏移量寻址,,Y,Y,,
|
||||
自增/自减+变址寻址,,Y,Y,,
|
||||
|
11
materials/chapter2/addressing.csv
Normal file
11
materials/chapter2/addressing.csv
Normal file
@@ -0,0 +1,11 @@
|
||||
寻址方式,格式,含义
|
||||
寄存器寻址(Register),"ADD R1,R2",regs[R1]=regs[R1]+regs[R2]
|
||||
立即数寻址(Immediate),"ADD R1,#2",regs[R1]=regs[R1]+2
|
||||
偏移量寻址(Displacement),"ADD R1,100(R2)",regs[R1]=regs[R1]+mem[100+regs[R2]]
|
||||
寄存器间接寻址(Reg.Indirect),"ADD R1,(R2)",regs[R1]=regs[R1]+mem[regs[R2]]
|
||||
变址寻址(Indexed),"ADD R1,(R2+R3)",regs[R1]=regs[R1]+mem[regs[R2]+regs[R3]]
|
||||
绝对寻址(Absolute),"ADD R1,(100)",regs[R1]=regs[R1]+mem[100]
|
||||
存储器间接寻址(Mem.Indirect),"ADD R1,@(R2)",regs[R1]=regs[R1]+mem[mem[regs[R2]]]
|
||||
自增量寻址(Autoincrement),"ADD R1,(R2)+","regs[R1]=regs[R1]+mem[regs[R2]],regs[R2]=regs[R2]+d"
|
||||
自减量寻址(Autodecrement),"ADD R1,-(R2)","regs[R2]=regs[R2]-d,regs[R1]=regs[R1]+mem[regs[R2]]"
|
||||
比例变址寻址(Scaled),"ADD R1,100(R2)(R3)",regs[R1]=regs[R1]+mem[100+regs[R2]+regs[R3]*d]
|
||||
|
11
materials/chapter2/alpha.S
Normal file
11
materials/chapter2/alpha.S
Normal file
@@ -0,0 +1,11 @@
|
||||
LOOP:
|
||||
LDT fp3=y(r2,0)
|
||||
LDT fp1=x(r1,0)
|
||||
MULT fp3=fp3,fp2
|
||||
ADDQ r2=r2,8
|
||||
MULT fp1=fp1,fp4
|
||||
SUBQ r4=r2,r6
|
||||
ADDT fp1=fp3,fp1
|
||||
STT x(r1,0)=fp1
|
||||
ADDQ r1=r1,8
|
||||
BNE r4,LOOP
|
||||
5
materials/chapter2/alpha_note.txt
Normal file
5
materials/chapter2/alpha_note.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
r1指向x
|
||||
r2指向y
|
||||
r6指向y的结尾
|
||||
fp2内容为t
|
||||
fp4内容为r
|
||||
45
materials/chapter2/alu_inst.csv
Normal file
45
materials/chapter2/alu_inst.csv
Normal file
@@ -0,0 +1,45 @@
|
||||
指令,指令功能
|
||||
ADD.W,字加
|
||||
ADDI.W,字加立即数
|
||||
SUB.W,字减
|
||||
ADD.D,双字加
|
||||
ADDI.D,双字加立即数
|
||||
SUB.D,双字减
|
||||
SLT,有符号数比较小于置1
|
||||
SLTI,有符号数立即数比较小于置1
|
||||
SLTU,无符号数比较小于置1
|
||||
SLTUI,无符号数立即数比较小于置1
|
||||
AND,与
|
||||
OR,或
|
||||
XOR,异或
|
||||
NOR,或非
|
||||
ANDI,与立即数
|
||||
ORI,或立即数
|
||||
XORI,异或立即数
|
||||
LU12I.W,加载20位立即数到高位
|
||||
SLL.W,字逻辑左移变量位
|
||||
SRL.W,字逻辑右移变量位
|
||||
SRA.W,字算术右移变量位
|
||||
SLLI.W,字逻辑左移常量位
|
||||
SRLI.W,字逻辑右移常量位
|
||||
SRAI.W,字算术右移常量位
|
||||
SLL.D,双字逻辑左移变量位
|
||||
SRL.D,双字逻辑右移变量位
|
||||
SRA.D,双字算术右移变量位
|
||||
SLLI.D,双字逻辑左移常量位
|
||||
SRLI.D,双字逻辑右移常量位
|
||||
SRAI.D,双字算术右移常量位
|
||||
MUL.W,字乘取低半部分
|
||||
MULH.W,有符号字乘取高半部分
|
||||
MULH.WU,无符号字乘取高半部分
|
||||
MUL.D,双字乘取低半部分
|
||||
MULH.D,有符号双字乘取高半部分
|
||||
MULH.DU,无符号双字乘取高半部分
|
||||
DIV.W,有符号字除取商
|
||||
DIV.WU,无符号字除取商
|
||||
MOD.W,有符号字除取余
|
||||
MOD.WU,无符号字除取余
|
||||
DIV.D,有符号双字除取商
|
||||
DIV.DU,无符号双字除取商
|
||||
MOD.D,有符号双字除取余
|
||||
MOD.DU,无符号双字除取余
|
||||
|
12
materials/chapter2/control_inst.csv
Normal file
12
materials/chapter2/control_inst.csv
Normal file
@@ -0,0 +1,12 @@
|
||||
指令,指令功能
|
||||
JIRL,相对寄存器偏移跳转并链接
|
||||
B,无条件相对转移
|
||||
BL,无条件相对转移并链接
|
||||
BEQ,等于时相对转移
|
||||
BNE,不等时相对转移
|
||||
BLT,有符号比较小于时相对转移
|
||||
BGE,有符号比较大于等于时相对转移
|
||||
BLTU,无符号比较小于时相对转移
|
||||
BGEU,无符号比较大于等于时相对转移
|
||||
BEQZ,等于0相对转移
|
||||
BNEZ,不等于0时相对转移
|
||||
|
8
materials/chapter2/if_else.S
Normal file
8
materials/chapter2/if_else.S
Normal file
@@ -0,0 +1,8 @@
|
||||
move $t0, cond_exp
|
||||
beqz $t0, .L1
|
||||
<then_statement>
|
||||
b .L2
|
||||
.L1:
|
||||
<else_statement>
|
||||
.L2:
|
||||
|
||||
5
materials/chapter2/if_else.c
Normal file
5
materials/chapter2/if_else.c
Normal file
@@ -0,0 +1,5 @@
|
||||
if (cond_exp)
|
||||
then_statement
|
||||
else
|
||||
else_statement
|
||||
|
||||
6
materials/chapter2/int_type.csv
Normal file
6
materials/chapter2/int_type.csv
Normal file
@@ -0,0 +1,6 @@
|
||||
C语言名称,LA32名称/数据长度,LA64名称/数据长度,X86名称/数据长度,X86-64名称/数据长度
|
||||
char,Byte/1,Byte/1,Byte/1,Byte/1
|
||||
short,Halfword/2,Halfword/2,Word/2,Word/2
|
||||
int,Word/4,Word/4,Dword/4,Dword/4
|
||||
long,Word/4,Dword/8,Dword/4,Qword/8
|
||||
long long,Dword/8,Dword/8,Qword/8,Qword/8
|
||||
|
5
materials/chapter2/isatype.csv
Normal file
5
materials/chapter2/isatype.csv
Normal file
@@ -0,0 +1,5 @@
|
||||
堆栈型,累加器型,寄存器-存储器型,寄存器-寄存器型
|
||||
PUSH A,LOAD A,"LOAD R1,A","LOAD R1,A"
|
||||
PUSH B,ADD B,"ADD R1,B","LOAD R2,B"
|
||||
ADD,STORE C,"STORE C,R1","ADD R3,R1,R2"
|
||||
POP C,,,"STORE C,R3"
|
||||
|
38
materials/chapter2/loop.S
Normal file
38
materials/chapter2/loop.S
Normal file
@@ -0,0 +1,38 @@
|
||||
test_for:
|
||||
or $t0,$r0,$r0
|
||||
or $t1,$r0,$r0
|
||||
.L2:
|
||||
blt $t0,$a0,.L3
|
||||
or $a0,$t1,$r0
|
||||
jr $ra
|
||||
.L3:
|
||||
add.w $t1,$t1,$t0
|
||||
addi.w $t0,$t0,1
|
||||
b .L2
|
||||
|
||||
|
||||
test_while:
|
||||
or $t0,$r0,$r0
|
||||
or $t1,$r0,$r0
|
||||
.L2:
|
||||
blt $t0,$a0,.L3
|
||||
or $a0,$t1,$r0
|
||||
jr $ra
|
||||
.L3:
|
||||
add.w $t1,$t1,$t0
|
||||
addi.w $t0,$t0,1
|
||||
b .L2
|
||||
|
||||
|
||||
test_dowhile:
|
||||
or $t0,$r0,$r0
|
||||
or $t3,$r0,$r0
|
||||
.L2:
|
||||
add.w $t1,$t3,$t0
|
||||
addi.w $t2,$t0,1
|
||||
or $t3,$t1,$r0
|
||||
or $t0,$t2,$r0
|
||||
blt $t2,$a0,.L2
|
||||
or $a0,$t1,$r0
|
||||
jr $ra
|
||||
|
||||
36
materials/chapter2/loop.c
Normal file
36
materials/chapter2/loop.c
Normal file
@@ -0,0 +1,36 @@
|
||||
int test_for(int a) {
|
||||
int sum = 0;
|
||||
int i = 0;
|
||||
|
||||
for (i = 0; i < a; i++) {
|
||||
sum += i;
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
|
||||
int test_while(int a) {
|
||||
int sum = 0;
|
||||
int i = 0;
|
||||
|
||||
while (i < a) {
|
||||
sum += i;
|
||||
i++;
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
|
||||
int test_dowhile(int a) {
|
||||
int sum = 0;
|
||||
int i = 0;
|
||||
|
||||
do {
|
||||
sum += i;
|
||||
i++;
|
||||
} while (i < a);
|
||||
|
||||
return sum;
|
||||
}
|
||||
12
materials/chapter2/mem_inst.csv
Normal file
12
materials/chapter2/mem_inst.csv
Normal file
@@ -0,0 +1,12 @@
|
||||
指令,指令功能
|
||||
LD.B,取字节
|
||||
LD.BU,取字节,无符号扩展
|
||||
LD.H,取半字
|
||||
LD.HU,取半字,无符号扩展
|
||||
LD.W,取字
|
||||
LD.WU,取字,无符号扩展
|
||||
LD.D,取双字
|
||||
ST.B,存字节
|
||||
ST.H,存半字
|
||||
ST.W,存字
|
||||
ST.D,存双字
|
||||
|
7
materials/chapter2/ppc.S
Normal file
7
materials/chapter2/ppc.S
Normal file
@@ -0,0 +1,7 @@
|
||||
LOOP:
|
||||
LFU fp0=y(r4=r4+8)
|
||||
FMUL fp0=fp0,fp1
|
||||
LF fp2=x(r3,8)
|
||||
FMADD fp0=fp0,fp2,fp3
|
||||
STFU x(r3=r3+8)=fp0
|
||||
BC LOOP,CTR>0
|
||||
5
materials/chapter2/ppc_note.txt
Normal file
5
materials/chapter2/ppc_note.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
r3+8指向x
|
||||
r4+8指向y
|
||||
fp1内容为t
|
||||
fp3内容为r
|
||||
CTR内容为512
|
||||
11
materials/chapter2/regnum.csv
Normal file
11
materials/chapter2/regnum.csv
Normal file
@@ -0,0 +1,11 @@
|
||||
指令集,整数通用寄存器数
|
||||
Itanium,128
|
||||
VAX,16
|
||||
ARMv8,31
|
||||
PowerPC,32
|
||||
Alpha,32(包括“zero”)
|
||||
SPARC,32(包括“zero”)
|
||||
MIPS,在mips16模式下为8,在32/64位模式下为32(包括“zero”)
|
||||
ARMv7,在16位Thumb 模式下为7,在32位模式下为14
|
||||
X86,"16/32位时为8, 64位时为16"
|
||||
LoongArch,32(包括“zero”)
|
||||
|
36
materials/chapter2/switch_case.S
Normal file
36
materials/chapter2/switch_case.S
Normal file
@@ -0,0 +1,36 @@
|
||||
st:
|
||||
addi.w $t0,$a0, -10 //a-10
|
||||
sltiu $t1,$t0, 8
|
||||
beqz $t1, default //if (a-10)>=8
|
||||
//goto default
|
||||
la $t2, jr_table
|
||||
alsl.d $t1, $t1, $t2, 3
|
||||
//(a-10)*8+jr_table
|
||||
ld.d $t0, $t1, 0
|
||||
jr $t0
|
||||
default:
|
||||
or $a1,$a0,$r0
|
||||
case_14:
|
||||
or $a0,$a1,$r0
|
||||
jr $ra //return b for case_14,
|
||||
//return a for default
|
||||
case_15:
|
||||
andi $a2,$a1,0xf //b & 0xf
|
||||
case_10:
|
||||
addi.w $a1,$a2,50 //c+50
|
||||
b case_14
|
||||
case_12_17:
|
||||
addi.w $a1,$a1,50 //b+50
|
||||
b case_14
|
||||
# jump table
|
||||
.section .rodata
|
||||
.align 3
|
||||
jr_table:
|
||||
.dword case_10
|
||||
.dword default
|
||||
.dword case_12_17
|
||||
.dword default
|
||||
.dword case_14
|
||||
.dword case_15
|
||||
.dword default
|
||||
.dword case_12_17
|
||||
17
materials/chapter2/switch_case.c
Normal file
17
materials/chapter2/switch_case.c
Normal file
@@ -0,0 +1,17 @@
|
||||
int st(int a, int b, int c)
|
||||
{
|
||||
switch (a) {
|
||||
case 15:
|
||||
c = b & 0xf;
|
||||
case 10:
|
||||
return c + 50;
|
||||
case 12:
|
||||
case 17:
|
||||
return b + 50;
|
||||
case 14:
|
||||
return b;
|
||||
default:
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
26
materials/chapter2/switch_case_chain.S
Normal file
26
materials/chapter2/switch_case_chain.S
Normal file
@@ -0,0 +1,26 @@
|
||||
st:
|
||||
addi.w $t0,$r0,14
|
||||
beq $a0,$t0,.L7 //(a==14)?
|
||||
blt $t0,$a0,.L3 //(a>14)?
|
||||
addi.w $t0,$r0,10
|
||||
beq $a0,$t0,.L4 //(a==10)?
|
||||
addi.w $t0,$r0,12
|
||||
beq $a0,$t0,.L5 //(a==12)?
|
||||
jr $ra //return a
|
||||
.L3:
|
||||
addi.w $t0,$r0,15
|
||||
beq $a0,$t0,.L6 //(a==15)?
|
||||
addi.w $t0,$r0,17
|
||||
beq $a0,$t0,.L5 //(a==17)?
|
||||
jr $ra //return a
|
||||
.L6:
|
||||
andi $a2,$a1,0xf //b & 0xf
|
||||
.L4:
|
||||
addi.w $a0,$a2,50 //c + 50
|
||||
jr $ra
|
||||
.L5:
|
||||
addi.w $a0,$a1,50 //b + 50
|
||||
jr $ra
|
||||
.L7:
|
||||
or $a0,$a1,$r0 //return b
|
||||
jr $ra
|
||||
6
materials/chapter2/vax_addressing.csv
Normal file
6
materials/chapter2/vax_addressing.csv
Normal file
@@ -0,0 +1,6 @@
|
||||
寻址方式,tex,spice,gcc
|
||||
偏移量寻址,32%,55%,40%
|
||||
立即数寻址,43%,17%,39%
|
||||
寄存器间接寻址,24%,3%,11%
|
||||
自增量寻址,0%,16%,6%
|
||||
存储器间接寻址,1%,6%,1%
|
||||
|
Reference in New Issue
Block a user