先上代码:
.data
welcome: .ascii “welcome to very9s.net:”
buffer:
.text
main:
li $v0, 8
la $a0, buffer
li $a1, 64
syscall
li $v0, 4
la $a0, welcome
syscall
仿真结果:
输入前的内存空间:
输入后的内存空间:
可见内存里多了输入的内容。
==============================================
编程过程中出现的错误:- 用.asciiz, 应用.ascii。他们的差别在于是否有家终止符。
- buffer在welcome前 ,正确的是welcome在buffer前。原因大概是.data中的顺序就是内存地址的顺序。否则输入数据会覆盖welcome中原有的数据。
8号服务若不设置$a1将默认为1,输入将被忽略。
Service 8 - Follows semantics of UNIX 'fgets'. For specified length n, string can be no longer than n-1. If less than that, adds newline to end. In either case, then pads with null byte If n = 1, input is ignored and null byte placed at buffer address. If n < 1, input is ignored and nothing is written to the buffer.
由于welcome并没有添加终止符,因此调用4号服务,在屏幕打印字符串时,将会从welcome的起始地址逐位打印直到遇到终止符停止输出。
===============================================
总结:
还是蛮简单的。
没有评论:
发表评论
谢谢您的留言^_^