Files
risc-v-cpu/testbench/programs/lui_test.asm
T
Anccend ccd1b917d0 新增 ISA 验证资产:迷你汇编器 + 指令测试程序
tools/rv_asm.py
- 极简 RISC-V 汇编器(Python 3,无第三方依赖),支持
  add/sub/and/or/xor/sll/srl/sra/slt/sltu、mul/mulh/mulhsu/mulhu、
  addi/slti/sltiu/xori/ori/andi、slli/srli/srai、lw/sw、
  beq/bne/blt/bge/bltu/bgeu、lui、jal/jalr、ecall、标签与 # 注释;
- 提供 print / halt 两条双字伪指令(分别等价于 addi a7,zero,34 + ecall、
  addi a7,zero,10 + ecall);
- I 型与访存立即数做 12 位有符号范围检查,越界直接报错,避免静默截断;
- 除 hex 外同时输出 .lst 编码清单,便于与 .asm 逐行核对。

testbench/programs/isa_test.asm + isa_test.expected
- 指令扩展验证程序:sltiu(两个方向)、xor/sll/srl/sra、mul/mulh/mulhu/mulhsu、
  bltu/bge/bgeu 的有符号与无符号区分,以及 bge/bgeu/bltu 三个循环,
  共 24 项 LED 输出,期望值逐行保存在 isa_test.expected。

testbench/programs/lui_test.asm
- LUI 验证程序:0x12345 / 0xfffff / 0x80000 与 lui+addi 组合,共 4 项输出。

另外包含编辑器/格式化工具对 cpu21_riscv_alu.v、cpu21_riscv_branch_unit.v、
cpu21_riscv_decoder.v 的重排(纯格式,语义等价)。

验证(xsim + testbench/tb_no_intr.v,按提交后的正式路径生成 hex)
- isa_test:24 项 LED 输出与 isa_test.expected 逐项一致,143 周期后 halt 停机;
- lui_test:12345000 / fffff000 / 80000000 / 12345678,21 周期后停机;
- 重新编译无 error / warning。
2026-09-12 19:10:24 +08:00

27 lines
786 B
NASM
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# LUI 指令测试:依次打印 lui 的结果,最后停机。
# 期望输出:12345000 / fffff000 / 80000000 / 12345678,随后停机(halted=1)。
# 用法:python tools/rv_asm.py testbench/programs/lui_test.asm <仿真工作目录>/risc-v-benchmark_ccab.hex
lui t0, 0x12345 # t0 = 0x12345000
add a0, zero, t0
addi a7, zero, 34
ecall
lui t0, 0xfffff # t0 = 0xfffff000
add a0, zero, t0
addi a7, zero, 34
ecall
lui t0, 0x80000 # t0 = 0x80000000
add a0, zero, t0
addi a7, zero, 34
ecall
lui t0, 0x12345 # 常见用法 lui+addi:0x12345678
addi t0, t0, 0x678
add a0, zero, t0
addi a7, zero, 34
ecall
addi a7, zero, 10 # a7=10 -> 停机
ecall