assembly 如何在数组mips [duplicate]中更改元素80的位置

q8l4jmvw  于 2023-04-21  发布在  其他
关注(0)|答案(1)|浏览(111)

此问题已存在

how do i modify the following mips code to such that element 82 will be contained in the array
3天前关闭。
下面是mips中的数组
网格:.byte

26, 25,22,22,12,22,22,22,22,22,10    
      25,22,22,22,42,22,22,22,22,25,10                               
      25,22,22,22,22,22,22,22,22,25,10                           
      25,22,22,22,22,22,22,22,22,25,10
      25,22,24,24,80,42,24,24,24,24,24
      24,32,32,32,32,32,32,43,34,34,34
      23,32,21,23,13,32,34,23,42,32,32
      25,23,23,23,23,23,23,23,23,23,23

我如何访问数组中元素80的位置,以便我可以将元素向上移动一列。假设数组的基址为0x0000000

emeijp43

emeijp431#

下面是示例代码,演示了它的工作方式(使用常量偏移量):

.globl main
main:
    jal print

    # move starts here
    la $t1, grid
    lb $t5, 48($t1)
    sb $t5, 37($t1)
    li $t5, ' '
    sb $t5, 48($t1)
    # move ends

    li $a0, 10
    li $v0, 11
    syscall
    jal print
    li $v0, 10
    syscall

print:
    la $t1, grid
    li $t2, 0
print_row:
    li $t3, 11
    li $v0, 1
    move $a0, $t2
    syscall
    li $a0, ':'
    li $v0, 11
    syscall
    li $a0, ' '
    li $v0, 11
    syscall
print_next:
    lb $a0, ($t1)
    addiu $t1, $t1, 1
    li $v0, 1
    syscall
    li $a0, ' '
    li $v0, 11
    syscall
    addiu $t3, $t3, -1
    bgtz $t3, print_next
    li $a0, 10
    li $v0, 11
    syscall
    addiu $t2, $t2, 1
    slti $t4, $t2, 8
    bnez $t4, print_row
    jr $ra

.data
grid:

.byte 26,25,22,22,12,22,22,22,22,22,10
.byte 25,22,22,22,42,22,22,22,22,25,10
.byte 25,22,22,22,22,22,22,22,22,25,10
.byte 25,22,22,22,22,22,22,22,22,25,10
.byte 25,22,24,24,80,42,24,24,24,24,24
.byte 24,32,32,32,32,32,32,43,34,34,34
.byte 23,32,21,23,13,32,34,23,42,32,32
.byte 25,23,23,23,23,23,23,23,23,23,23

输出:

0: 26 25 22 22 12 22 22 22 22 22 10 
1: 25 22 22 22 42 22 22 22 22 25 10 
2: 25 22 22 22 22 22 22 22 22 25 10 
3: 25 22 22 22 22 22 22 22 22 25 10 
4: 25 22 24 24 80 42 24 24 24 24 24 
5: 24 32 32 32 32 32 32 43 34 34 34 
6: 23 32 21 23 13 32 34 23 42 32 32 
7: 25 23 23 23 23 23 23 23 23 23 23 

0: 26 25 22 22 12 22 22 22 22 22 10 
1: 25 22 22 22 42 22 22 22 22 25 10 
2: 25 22 22 22 22 22 22 22 22 25 10 
3: 25 22 22 22 80 22 22 22 22 25 10 
4: 25 22 24 24 32 42 24 24 24 24 24 
5: 24 32 32 32 32 32 32 43 34 34 34 
6: 23 32 21 23 13 32 34 23 42 32 32 
7: 25 23 23 23 23 23 23 23 23 23 23

您可以看到80已经从4向上移动了一行到3,并被32(空格)取代。

相关问题