[英]MIPS Assembly Program Not Performing Lines
I am currently using MIPS Assembly. 我当前正在使用MIPS Assembly。 I have recently learned how to do both macros and arrays (of a sort), so I promptly wrote a fairly simple program to test them out.
我最近学习了如何同时执行宏和数组(某种),因此我迅速编写了一个相当简单的程序来对其进行测试。 However, between getting the data and displaying it again, I wish to output a new message.
但是,在获取数据并再次显示之间,我希望输出一条新消息。 For some reason, my program doesn't appear to do this, even though when running through it step by step it DOES, in fact, go through those lines - it just simply doesn't have any output.
出于某种原因,我的程序似乎没有执行此操作,即使在逐步执行它的过程中,实际上确实要经过这些行-它只是没有任何输出。 Is there any particular reason in MIPS Assembly why this isn't working, or is it a glitch in the MARS assembler?
在MIPS汇编中是否有任何特定原因为什么不起作用,还是在MARS汇编器中出现故障?
.data
testlist: .word 50
request: .asciiz "Enter pi up to 50 digits: 3."
out: .asciiz "\nPi: 3."
.text
.macro arraygetword(%initaddress,%offset,%storeto)
la $a1,%initaddress
mul $a0,%offset,4
add $a0,$a0,$a1
lw %storeto,($a0)
.end_macro
.macro arraysetword(%initaddress,%offset,%value)
la $a1,%initaddress
mul $a0,%offset,4
add $a0,$a0,$a1
sw %value,($a0)
.end_macro
.macro arraygetbyte(%initaddress,%offset,%storeto)
la $a1,%initaddress
add $a0,%offset,$a1
lw %storeto,($a0)
.end_macro
.macro arraysetbyte(%initaddress,%offset,%value)
la $a1,%initaddress
add $a0,%offset,$a1
sw %value,($a0)
.end_macro
main:
la $a0,request
li $v0,4
syscall
li $t0,0
li $t1,50
forloop:
li $v0,12
syscall
arraysetword(testlist,$t0,$v0)# testlist[$t0]=$v0
addi $t0,$t0,1
blt $t0,$t1,forloop
li $t0,0
li $t1,50
la $a0,out# This is the part not working.
li $v0,4# Why doth this not output anything?
syscall# I need some sort of line break. It's awkward otherwise.
output:
arraygetword(testlist,$t0,$a0)# $a0=testlist[$t0]
li $v0,11
syscall
addi $t0,$t0,1
blt $t0,$t1,output
li $v0,10
syscall
testlist: .word 50
does not allocate 50 words, it allocates a single word with value 50. As such, your program is overwriting the memory after it, which contains your strings to print. testlist: .word 50
不分配50个字,它分配值为50。这样一个字,你的程序重写后对它的记忆,其中包含你的字符串进行打印。 Of course by that time you have already printed the request
so that is not affected. 当然,到那时您已经打印了
request
因此不会受到影响。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.