如何在RISC-V Assembly中打印正数和负数的总和
How to print the total of positive and negative numbers in RISC-V Assembly
该程序存储一个包含 25 个整数(字)的数组。然后计算正数之和和负数之和,然后打印正数和负数之和。
错误信息:
Error in /Users/COD/subtractandadd.asm line 76 column 15: "v0": operand is of incorrect type
Error in /Users/COD/subtractandadd.asm line 80 column 15: "v0": operand is of incorrect type
Error in /Users/COD/subtractandadd.asm line 81 column 12: "la": Too many or incorrectly formatted operands. Expected: la t1,label
Error in /Users/COD/subtractandadd.asm line 85 column 15: "v0": operand is of incorrect type
Error in /Users/COD/subtractandadd.asm line 89 column 15: "v0": operand is of incorrect type
Error in /Users/COD/subtractandadd.asm line 90 column 12: "la": Too many or incorrectly formatted operands. Expected: la t1,label
Error in /Users/COD/subtractandadd.asm line 92 column 11: "v0": operand is of incorrect type
打印并退出代码:
#exit and print
exit:
#print the positive numbers total
li v0,4
la a0,totalPositive
ecall
#print the +ve sum
li v0,1
la a0,($s1)
ecall
#print the negative total
li v0,4
la a0,totalNegative
ecall
#print the -ve sum
li v0,1
la a0,($s2)
ecall
li v0,10 #end of program exit
ecall
您正在使用仅适用于矢量扩展的 v0 寄存器。如果你是工具链。
gnu 工具链的编译器和“标准”binutils 似乎还不支持它。有一个专用的 binutils 分支 https://github.com/riscv/riscv-binutils-gdb/tree/rvv-1.0.x.
LLVM 也不支持它。
该程序存储一个包含 25 个整数(字)的数组。然后计算正数之和和负数之和,然后打印正数和负数之和。
错误信息:
Error in /Users/COD/subtractandadd.asm line 76 column 15: "v0": operand is of incorrect type
Error in /Users/COD/subtractandadd.asm line 80 column 15: "v0": operand is of incorrect type
Error in /Users/COD/subtractandadd.asm line 81 column 12: "la": Too many or incorrectly formatted operands. Expected: la t1,label
Error in /Users/COD/subtractandadd.asm line 85 column 15: "v0": operand is of incorrect type
Error in /Users/COD/subtractandadd.asm line 89 column 15: "v0": operand is of incorrect type
Error in /Users/COD/subtractandadd.asm line 90 column 12: "la": Too many or incorrectly formatted operands. Expected: la t1,label
Error in /Users/COD/subtractandadd.asm line 92 column 11: "v0": operand is of incorrect type
打印并退出代码:
#exit and print
exit:
#print the positive numbers total
li v0,4
la a0,totalPositive
ecall
#print the +ve sum
li v0,1
la a0,($s1)
ecall
#print the negative total
li v0,4
la a0,totalNegative
ecall
#print the -ve sum
li v0,1
la a0,($s2)
ecall
li v0,10 #end of program exit
ecall
您正在使用仅适用于矢量扩展的 v0 寄存器。如果你是工具链。
gnu 工具链的编译器和“标准”binutils 似乎还不支持它。有一个专用的 binutils 分支 https://github.com/riscv/riscv-binutils-gdb/tree/rvv-1.0.x.
LLVM 也不支持它。