Assembly RISC-V加载地址未与字边界对齐
我的编译器是RARS 问题就在这里。 我被告知需要定义内存基址,不允许使用伪指令。因此,我不能使用la、li和j 当我尝试这样做时,我得到了以下错误:Assembly RISC-V加载地址未与字边界对齐,assembly,riscv,Assembly,Riscv,我的编译器是RARS 问题就在这里。 我被告知需要定义内存基址,不允许使用伪指令。因此,我不能使用la、li和j 当我尝试这样做时,我得到了以下错误: Error in /Users/SumOfArray.asm line 22: Runtime exception at 0x00400018: Load address not aligned to word boundary 0x00000001 Go: execution terminated with errors 我认为第22行的错
Error in /Users/SumOfArray.asm line 22: Runtime exception at 0x00400018: Load address not aligned to word boundary 0x00000001
Go: execution terminated with errors
我认为第22行的错误是:
lw t4,0(t3)
创建lui
指令后。我需要遍历它以将值保存到数组中
我想我是在问我如何修复下面的代码,让lui
指令在数组中循环而不出错
.data
array: .word 1,2,3,4,5,6,7,8,9,10,11,12,-1,-2,-3,-4,-5,-6,-7,-8,-9,-10,-11,-12,-5, 0
positiveSum: .word 0
negativeSum: .word 0
.text
main:
lui s0, 0x10010
lw t0,0(s0) #load array to register t0
lw s1,0(s0) #load the positive sum to s1, and negative sum to s2
lw s2,0(s0)
loop: #store values in an array using loop
slli t3,t1,2
add t3,t3,t0 #add the base address and the above result
lw t4,0(t3) #load the word from above address into t4
beqz t4,exit #exit loop when reaching 0
unsigned int hello;
无符号整数世界;
虚空乐趣(虚空)
{
你好++;
世界++;
}
-Ttext=0x1000-Tdata=0x20000300
第节的分解。正文:
00001000 :
1000:20000637 lui x12,0x20000
1004:200006b7 lui x13,0x20000
1008:30462703 lw X14772(x12)#20000304
100c:3006a783 lw X15768(x13)#20000300
1010:0705 addi x14,x14,1
1012:0785 addi x15,x15,1
1014:30E6223 sw X14772(x12)
1018:30f6a023 sw X15768(x13)
101c:8082 ret
分段sbss的拆卸:
20000300 :
20000300:0000 UNDP
...
20000304 :
20000304:0000 UNMP
...
乐趣:
lui a2,%hi(你好)
路易a3,%hi(世界)
lw a4,%lo(你好)(a2)
lw a5,%lo(世界)(a3)
addi a4、a4、1
addi a5,a5,1
西南a4,%lo(你好)(a2)
西南a5%,低(世界)(a3)
ret
当然,你可以硬编码这些偏移量,只要你真的这么做了。您没有显示.text和.data的链接器脚本或地址空间,以查看它们如何适合您的代码。如果这是一种计算有多少个数字是正数和有多少个负数的程序,那么你需要1)在数组中循环,2)确定计数的位置
如果硬编码不正确,则代码可能无法正常运行,因为您似乎看到您没有提供与该特定问题相关的任何信息。您有一些片段,但没有与问题相关的关键信息
在编写更多的代码之前,您应该重新开始,只在数组中循环,看看是否有效,然后开始处理每个元素,然后保留分数。您遇到的问题是,您正试图将lw与地址一起使用(t1前三条lw指令都有相同的地址,但您的注释暗示它们加载了不同的内容。看起来您在这个最小完整的示例中遗漏了很多代码。因此它并不完整。如果您允许,这些工具可能会帮助您处理地址,您不需要硬编码。请编写一个添加esses每个元素,然后在数组中循环。直到正确且有效后,才添加更多代码。我不明白您的意思。@old_timer其中的0(s0)部分与所有三条指令的地址相同?或者它们与注释不匹配?
unsigned int hello;
unsigned int world;
void fun ( void )
{
hello++;
world++;
}
-Ttext=0x1000 -Tdata=0x20000300
Disassembly of section .text:
00001000 <fun>:
1000: 20000637 lui x12,0x20000
1004: 200006b7 lui x13,0x20000
1008: 30462703 lw x14,772(x12) # 20000304 <hello>
100c: 3006a783 lw x15,768(x13) # 20000300 <__DATA_BEGIN__>
1010: 0705 addi x14,x14,1
1012: 0785 addi x15,x15,1
1014: 30e62223 sw x14,772(x12)
1018: 30f6a023 sw x15,768(x13)
101c: 8082 ret
Disassembly of section .sbss:
20000300 <world>:
20000300: 0000 unimp
...
20000304 <hello>:
20000304: 0000 unimp
...
fun:
lui a2,%hi(hello)
lui a3,%hi(world)
lw a4,%lo(hello)(a2)
lw a5,%lo(world)(a3)
addi a4,a4,1
addi a5,a5,1
sw a4,%lo(hello)(a2)
sw a5,%lo(world)(a3)
ret
lw s1,0(s0) #load the positive sum to s1, and negative sum to s2
lw s2,0(s0)
lw t4,0(t3)
sw s1, 0(s0)
sw s2, 4(s0)
lui s0, 0x10010
lw t0,0(s0) #load array to register t0
lw s1,0(s0) #load the positive sum to s1, and negative sum to s2
lw s2,0(s0)
main:
la t0, array
la s0, positiveSum