How to pop out of the stack in the MIPS assembly?

I am trying to learn the MIPS assembly since I have free time and I am trying to write a program that pushes numbers to the stack and then pushes them. I want him to count the number of numbers that popped up before reaching a negative number, and then every time he gets a negative, consider the number of negative and positive numbers.

so far i got this:

 #count the number of negative words on the stock by poping the stack until a non-    negative word is found 
#and print out the number of words found

.text
.globl main
#this code reads the numbers from the data area and stores in them in a stack
#the numbers are located in the test area and the number of numbers in the num area

main:   la $t0, test
lw $t1, num
loop:   lw $t2,($t0)
sub $sp, $sp, 4
sw $t2($sp)
add $t0, $t0, 4
add $t1, $t1, -1
bnez $t1, loop


#pop from the stack and print the number of numbers in the stack before a nonnegative number is reached 
#then keep count of how many negative and positive ones there are total

#code I cannot come up with would go here

.data
test:   .word
2, 0xfffabfff,2,-4,-9,0x99999999,0x90000000,-2147479536,0x80000000
num:    .word 10
ans:    .asciiz "Number is = "
endl:   .asciiz "\n"

I got this to push as far as I can judge, but I can't figure out what needs to be done. what do i need to do here?

+5
source share
1 answer

Pop will be the opposite of push. Therefore, if you use this, click $t2:

sub $sp,$sp,4
sw $t2,($sp)

You put it with:

lw $t2,($sp)
addiu $sp,$sp,4

, , , BGEZ , popped = > 0 .

+4

All Articles