1

In MIPS Assembly how would I go about creating a program that would create an array of different size based on user input?

For example, the program would ask the user to input an integer X and create an array of length X.

Any code examples would be greatly appreciated.

1 Answer 1

3

You can use the sbrk system call to allocate memory.

Consider the following:

.data
    prompt: .asciiz "Number of integers "
.text

    main:
        #print prompt
        la $a0 prompt
        li $v0 4
        syscall

        #get int
        li $v0 5
        syscall

        #allocate space
        sll $a0 $v0 2 #number of bytes now in $a0
        li  $v0 9
        syscall 

        #address of space now in $v0
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.