Domanda

I am currently using 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?

.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
È stato utile?

Soluzione

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. Of course by that time you have already printed the request so that is not affected.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top