Assembly 在MIPS中打印单词的字母
请帮我写汇编程序(MIPS) 我有一个词“你好!”我接下来需要mips打印:Assembly 在MIPS中打印单词的字母,assembly,mips,Assembly,Mips,请帮我写汇编程序(MIPS) 我有一个词“你好!”我接下来需要mips打印: h he hel hell hello hello! 我试过这个: .data lbl1: .asciiz "hello!" lbl2: .asciiz "h " end_line: .asciiz "\n" .text main: la $s0, lbl1 move $a0, $s0 addi $v0, $zero, 4 syscall jr $ra 但它打
h
he
hel
hell
hello
hello!
我试过这个:
.data
lbl1: .asciiz "hello!"
lbl2: .asciiz "h "
end_line: .asciiz "\n"
.text
main: la $s0, lbl1
move $a0, $s0
addi $v0, $zero, 4
syscall jr $ra
但它打印出所有的字符串,我只需要一两个字母
感谢您的帮助确定,因此您有一个系统调用来打印以零结尾的字符串。那么你要做的就是
for i = 1 to 6 (length of "hello!")
read the character from position i in your string and store it safely
write a 0 into your string at position i
syscall to print the edited string
write the saved character back to position i
syscall to print the newline
next
或
希望您知道的足够多,可以将其中一个作为汇编程序编写。您还可以通过在字符串中交换换行符和换行符以及零来实现第一个换行符。如何从程序集打印取决于您的操作系统的打印接口-这是哪个操作系统/环境?它可能只是定义一个字符串常量并将指向该常量的指针传递到操作系统调用中-但是如果您需要一次打印一个以上的字母,则需要根据可用的操作系统调用修改字符串或字符计数。我尝试了以下操作:.data lbl1:.asciiz“hello!”lbl2:.asciiz“h”end_行:.asciiz“\n”.text main:la$s0,lbl1 move$a0,$s0 addi$v0,$zero,4 syscall jr$ra,但它会打印所有字符串,我只需要一两个字母。我也尝试过这个方法,我将$s0预付1,所以mips会打印我“ello!”而不打印“h”,如果我再预付一次,它会打印“llo!”等等。我需要它先打印我的“h”,然后是“他”,然后是“Hell”,“hello”,“hello!”。你也能给我看一下代码吗?我不太懂MIPS,但这里的协议是,我们不会为家庭作业问题(或我们怀疑是家庭作业的问题)发布代码解决方案。不,您需要做的不止这些:您需要就地编辑字符串或将缩写形式复制到新的缓冲区,如我所述-例如,有另一个等于s0+1的寄存器(s1?),从那里读取一个字节,将0写入该字节,syscall,回写字节,递增s1并循环-直到读取的字节为0,那就停下来,谢谢你的回答。但是如果有人知道一点mips,请给我一个线索。我需要使用哪种代码或指令操作才能从字符串中加载一个字母,例如“hello”。我需要用字母“h”来注册s0美元。我已经尝试过的代码在注释上方。
allocate a buffer for a complete copy of your string
for i = 1 to 6
copy the first i characters of your string into the buffer
append a newline and a zero to terminate the string
syscall to print the buffer
next