有关 MIPS 汇编的一些帮助 - 跳转和链接

发布于 2024-08-23 06:18:22 字数 1410 浏览 3 评论 0原文

我以前从未使用过 MIPS 汇编,它只是在课堂上介绍的。我正在做家庭作业,但调用函数时遇到一些困难。这是我到目前为止已经解决的问题:

        .data
    .align 2    
    matrix_a:   .word 11, 23, 31, 46, 52, 66, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16

    .text
    .align 2
    .globl main

main:
    la $a0, matrix_a   #; Address of matrix_a
    addi $a1, 16       #; set the second argument to the size of matrix_a, 16
    jal matrix_print   #; and call the function

matrix_print:
    add $t3,$zero,$a0
    li $t2, 0                   #; And initialize $t2 = 0
    add $t4, $t2, $zero         #; Set $t4 = $t2, we will use $t4 for checking our loop
    add $t5,$zero,$a1           #; And $t5 is our max point
    Loop:
        bge $t4, $t5, Exit      #; If our index has reached our constraint, jump to exit
        add $t2,$zero,$t4       #; Otherwise, set $t2 to equal $t4
        add $t2, $t2, $t2       #; Double $t2
        add $t2, $t2, $t2       #; and double it again
        add $t1, $t2, $t3       #; and store $t2, the offset, + $t3, the initial address
        li $v0,1                #; Get ready to system call print an int
        lw $a0, 0($t1)          #; Pass in $t1 to print
        syscall                 #; Print        
        addi $t4,$t4,1          #; increment $t4 by 1
        j Loop
    Exit:
    li  $v0,10                  #; Exit
    syscall

问题是它永远循环,所以我相信 $a1 没有正确通过。当我直接在函数中设置大小时,此代码有效。有人能指出我正确的方向吗?谢谢!

I've never used MIPS assembly before and it was just introduced in class. I'm working on a homework assignment, but I'm having some difficulty calling a function. Here's what I've worked out so far:

        .data
    .align 2    
    matrix_a:   .word 11, 23, 31, 46, 52, 66, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16

    .text
    .align 2
    .globl main

main:
    la $a0, matrix_a   #; Address of matrix_a
    addi $a1, 16       #; set the second argument to the size of matrix_a, 16
    jal matrix_print   #; and call the function

matrix_print:
    add $t3,$zero,$a0
    li $t2, 0                   #; And initialize $t2 = 0
    add $t4, $t2, $zero         #; Set $t4 = $t2, we will use $t4 for checking our loop
    add $t5,$zero,$a1           #; And $t5 is our max point
    Loop:
        bge $t4, $t5, Exit      #; If our index has reached our constraint, jump to exit
        add $t2,$zero,$t4       #; Otherwise, set $t2 to equal $t4
        add $t2, $t2, $t2       #; Double $t2
        add $t2, $t2, $t2       #; and double it again
        add $t1, $t2, $t3       #; and store $t2, the offset, + $t3, the initial address
        li $v0,1                #; Get ready to system call print an int
        lw $a0, 0($t1)          #; Pass in $t1 to print
        syscall                 #; Print        
        addi $t4,$t4,1          #; increment $t4 by 1
        j Loop
    Exit:
    li  $v0,10                  #; Exit
    syscall

The problem is that it is looping forever, so I believe that $a1 isn't coming through properly. This code work when I was setting the size directly in the function. Can anyone point me in the right direction? Thanks!

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

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

发布评论

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

评论(1

仅此而已 2024-08-30 06:18:22

addi $a1, 16 行中,在添加 16 之前,$a1 的值是多少?

In the line addi $a1, 16, what value does $a1 have before you add 16 to it?

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