Я пытаюсь изучить сборку MIPS, так как у меня есть свободное время, и я пытаюсь написать программу, которая подталкивает числа к стеку, а затем выталкивает их. Я хочу, чтобы он подсчитал количество чисел, которые выскочили, прежде чем достигнуть отрицательного числа, а затем каждый раз, когда он получает отрицательный, учитывайте количество отрицательных и положительных чисел.Как выскочить из стека в сборке MIPS?
до сих пор я получил это:
#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"
Я получил его толкать прямо, насколько я могу сказать, но я не могу понять, толкание и подсчет права. что мне нужно делать здесь?
Extreme nitpicking, я знаю, но 'sub' с немедленным не существует, это должно быть' addi $ sp, $ sp, -4'. –
Это скорее всего признано ассемблером псевдо-инструкцией и переведено в 'addiu'. – Michael