MIPS 汇编语言 printString(p) 函数

问题描述 投票:0回答:0

我在程序内存中存储了一个字符串,我试图将它打印到控制台,但它无法移动超过第一个 ascii 字母,只是重复 w 表示无穷大。我只是用一个汇编器来隐藏它,但它基本上不断地重印 W。使用带有 0x80000008 的内存映射 IO 来写入或控制台输出。

.data
welcome: .asciiz "Welcome to tab!\n"

.text
main:
  # Load the address of the "welcome" string into register $4
  la $4, welcome

  # Call the printString function
  jal printString

  # Exit the program
  li $v0, 10


# Function to print a null-terminated string to the console
printString:
  # Initialize count to 0
  add $2, $0, $0

  # Loop over the characters in the string
  loop:
    # Load the next byte from memory
    lb $8, 0($4)

    # If the byte is null, exit the loop
    beq $8, $0, end

    # Print the character to the console
    li $v0, 11
    addi $a0, $8, 0


    # Increment the current character pointer and the count
    addi $4, $4, 1
    addi $2, $2, 1

    # Jump back to the beginning of the loop
    j loop

  # Return to the calling function
  end:
    jr $ra
assembly mips
© www.soinside.com 2019 - 2024. All rights reserved.