编译简单的 SPARC ASM 数学代码时出错

发布于 2024-12-06 13:37:50 字数 2612 浏览 0 评论 0原文

编写 SPARC asm 代码来评估硬编码语句,但我收到一个我不明白的错误。我进行了全面搜索,虽然它似乎在一些错误报告中出现了很多,但我没有为程序员找到真正的线索。是的,这是作业,是的,我还没有完成,是的,我到处都有分支机构延误。我会自己解决,但我需要知道错误是什么。这个错误没有告诉我任何有用的东西,而且我拥有的书也没有任何用处。

我对此真的很陌生,所以任何帮助将不胜感激。

  1 /*Justin Reeves*/
  2 /*max{x^3-14x^2+56x-64} from [-2,8]*/
  3 /*for (x = lwr, x <= upr, x++) */
  4 define(lwr_b, -2)       !lower bound
  5 define(upr_b, 8)        !upper bound
  6 define(x_r, %l0)        !x
  7 define(sum_r, %l1)      !sum, each pass of loop may update
  8 define(max_r, %l2)      !max, cmp to sum, store in max if larger
  9
 10     .global main
 11 main:
 12     save    %sp, -64, %sp
 13
 14     ba      loop_test
 15     mov     lwr_b,  x_r     /*init x_r = -2 */
 16
 17 loop_test:
 18     cmp     x_r,    upr_b
 19     ble     sum_loop
 20     nop
 21 /*then x > upr_b and the max has been found*/
 22 /*odd spot for it...but this is the end of the program*/
 23
 24
 25 sum_loop: ! starting backwards to give us an intial nonzero constant sum
 26     mov     -64,    sum_r   /* sum = -64 */
 27
 28     mov     x_r,    %o0     /*56x*/
 29     mov     56,     %o0
 30     clr     %o2
 31     call    .mul            /*AFAIK 56x should now be in %o0*/
 32     nop
 33     add     sum_r,  %o0,    sum_r   /* sum = 56x-64 */
 34
 35     mov     x_r,    %o0     /* 14x^2 */
 36     mov     x_r,    %o1
 37     mov     -14,    %o2
 38     call    .mul
 39     nop
 40     add     sum_r,  %o0,    sum_r   /* sum = -14x^2+56x-64 */
 41
 42     mov     x_r,    %o0
 43     mov     x_r,    %o1
 44     mov     x_r,    %o2
 45     call    .mul
 46     nop
 47     add     sum_r,  %o0,    sum_r   /*sum = x^3-14x^2+56x-64 */
 48
 49     add     x_r,    1,      x_r     /* x++ */
 50     cmp     sum_r,  max_r
 51     bge     collect_lrg             /*branches if sum > max*/
 52     nop
 53
 54 collect_lrg:
 55     mov     sum_r,  max_r
 56     ba      loop_test
 57
 58     mov     1,      %g1     /*exit request*/
 59     ta      0               /*trap to system*/

然后,当我尝试定义宏并编译时,我得到:

cs32107@matrix:~$ m4 polynomialv2.m >多项式.s
cs32107@matrix:~$ gcc -g 多项式.s -o 多项式
ld:致命:重定位错误:R_SPARC_32:文件 /var/tmp//ccVOrnx2.o:符号:偏移量 0xfb5d11dd 未对齐 ld:致命:重定位错误:R_SPARC_32:文件 /var/tmp//ccVOrnx2.o:符号:偏移量 0xfb5d120f 未对齐 ld:致命:重定位错误:R_SPARC_32:文件 /var/tmp//ccVOrnx2.o:符号:偏移量 0xfb5d1215 未对齐 ld:致命:重定位错误:R_SPARC_32:文件 /var/tmp//ccVOrnx2.o:符号:偏移量 0xfb5d1219 未对齐 ld:致命:重定位错误:R_SPARC_32:文件 /var/tmp//ccVOrnx2.o:符号:偏移量 0xfb5d121d 未对齐 ld:致命:重定位错误:R_SPARC_32:文件 /var/tmp//ccVOrnx2.o:符号:偏移量 0xfb5d1266 未对齐 Collect2: ld 返回 1 退出状态 cs32107@矩阵:~$

Writing SPARC asm code to evaluate a hardcoded statement, but I'm getting an error I don't understand. I've searched all over, and while it seems to come up a lot in some bug reports out there, there's no real clues that I've found for programmers. Yes, it is homework, and yes, I'm not finished, and yes I have branch delays all over the place. I'll get to them on my own, but I need to know what the error is. This error's not telling me anything useful, and the books I have aren't any good for it either.

I'm really new at this, so any help would be greatly appreciated.

  1 /*Justin Reeves*/
  2 /*max{x^3-14x^2+56x-64} from [-2,8]*/
  3 /*for (x = lwr, x <= upr, x++) */
  4 define(lwr_b, -2)       !lower bound
  5 define(upr_b, 8)        !upper bound
  6 define(x_r, %l0)        !x
  7 define(sum_r, %l1)      !sum, each pass of loop may update
  8 define(max_r, %l2)      !max, cmp to sum, store in max if larger
  9
 10     .global main
 11 main:
 12     save    %sp, -64, %sp
 13
 14     ba      loop_test
 15     mov     lwr_b,  x_r     /*init x_r = -2 */
 16
 17 loop_test:
 18     cmp     x_r,    upr_b
 19     ble     sum_loop
 20     nop
 21 /*then x > upr_b and the max has been found*/
 22 /*odd spot for it...but this is the end of the program*/
 23
 24
 25 sum_loop: ! starting backwards to give us an intial nonzero constant sum
 26     mov     -64,    sum_r   /* sum = -64 */
 27
 28     mov     x_r,    %o0     /*56x*/
 29     mov     56,     %o0
 30     clr     %o2
 31     call    .mul            /*AFAIK 56x should now be in %o0*/
 32     nop
 33     add     sum_r,  %o0,    sum_r   /* sum = 56x-64 */
 34
 35     mov     x_r,    %o0     /* 14x^2 */
 36     mov     x_r,    %o1
 37     mov     -14,    %o2
 38     call    .mul
 39     nop
 40     add     sum_r,  %o0,    sum_r   /* sum = -14x^2+56x-64 */
 41
 42     mov     x_r,    %o0
 43     mov     x_r,    %o1
 44     mov     x_r,    %o2
 45     call    .mul
 46     nop
 47     add     sum_r,  %o0,    sum_r   /*sum = x^3-14x^2+56x-64 */
 48
 49     add     x_r,    1,      x_r     /* x++ */
 50     cmp     sum_r,  max_r
 51     bge     collect_lrg             /*branches if sum > max*/
 52     nop
 53
 54 collect_lrg:
 55     mov     sum_r,  max_r
 56     ba      loop_test
 57
 58     mov     1,      %g1     /*exit request*/
 59     ta      0               /*trap to system*/

then when I try to define the macros and compile I get:

cs32107@matrix:~$ m4 polynomialv2.m > polynomial.s
cs32107@matrix:~$ gcc -g polynomial.s -o polynomial
ld: fatal: relocation error: R_SPARC_32: file /var/tmp//ccVOrnx2.o: symbol : offset 0xfb5d11dd is non-aligned
ld: fatal: relocation error: R_SPARC_32: file /var/tmp//ccVOrnx2.o: symbol : offset 0xfb5d120f is non-aligned
ld: fatal: relocation error: R_SPARC_32: file /var/tmp//ccVOrnx2.o: symbol : offset 0xfb5d1215 is non-aligned
ld: fatal: relocation error: R_SPARC_32: file /var/tmp//ccVOrnx2.o: symbol : offset 0xfb5d1219 is non-aligned
ld: fatal: relocation error: R_SPARC_32: file /var/tmp//ccVOrnx2.o: symbol : offset 0xfb5d121d is non-aligned
ld: fatal: relocation error: R_SPARC_32: file /var/tmp//ccVOrnx2.o: symbol : offset 0xfb5d1266 is non-aligned
collect2: ld returned 1 exit status
cs32107@matrix:~$

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷︶言冷语的世界 2024-12-13 13:37:50

汇编程序中的错误会导致调试代码添加未对齐的数据访问。如果需要调试信息,请不要使用 -g,但可以使用 -gstabs。也许有一个天然气更新也可以解决这个问题。

A bug in the assembler causes debugging code to add unaligned data access. Don't use -g but perhaps -gstabs if you need debugging information. There maybe an update for gas that fixes the problem too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文