Fill out the missing parts from the assembly language codeMI

Fill out the #missing# parts from the assembly language code(MIPS).

data

stack_pointer:   .word   0

heap_pointer:   .word   0

bottom_of_the_stack:   .word   0

codes_p:   .asciiz   \"\ Enter 0 to push a value on top of the stack.\ Any other value entered will pop off the element at the top of the stack.\ \ \"

   .text

main:

   jal   initialize_stack_pointer

   sw $v0 stack_pointer

sw $v0 heap_pointer

   sw   $v0   bottom_of_the_stack

# An infinite loop that pushes and pops values off the stack based whether input is 0 or non-zero

main_loop:              

   la   $a0   codes_p

   li   $v0   4

   syscall

   #missing#

   #missing#

   la   $a0   stack_pointer       #pass argument

   la   $a1   heap_pointer       #pass argument

   la   $a2   bottom_of_the_stack   #pass argument

   #missing#

   jal   pop

   b   main_loop

jump_to_push:

   jal   push

   b   main_loop

exit:   li   $v0   10

   syscall

initialize_stack_pointer:   # returns the start address of heap

   li   $a0   0

   li   $v0   9

   syscall  

   jr   $ra

   .data

prompt_p:   .asciiz   \"\ Enter a value to be pushed on the stack: \"

push_string:   .asciiz   \" pushed on top of the stack\ \"

   .text

push:

   move   $t0   $a0

   move   $t1   $a1

   move   $t5   $a2

   #missing#

   #missing#

   beq   $t2   $t3   push_allocate_more_space # if stack pointer and heap pointer are same

push_value_on_stack:

   la   $a0   prompt_p

   li   $v0   4

   syscall

li $v0 5

syscall

   #missing#          

   addi   $t2   $t2   4   #move stack pointer by 4 bytes

   #missing#

   move   $a0   $v0

   li   $v0   1

   syscall

   li   $v0   4

   la   $a0   push_string

   syscall

   jr   $ra

push_allocate_more_space:

   li   $a0   4

   li   $v0   9

   syscall

   #missing#      

   sw   $v0   0($t1)   #store address of newly allocated 4 bytes of memory to heap_pointer

   b   push_value_on_stack

   .data

pop_string:   .asciiz   \" poped off from top of the stack\ \"

pop_bottom_p:   .asciiz   \"Stack is empty!\ \"

   .text

pop:

   move   $t0   $a0

   #missing#

   lw   $t1   0($t0)

   #missing#

   beq   $t3   $t1   pop_bottom

   #missing#      

   la   $v0   1   #print the element residing at top of the stack

   syscall

   li   $v0   4

   la   $a0   pop_string

   syscall

   #missing#  

   sw   $t1   0($t0)

   move   $a0   $v0

   jr   $ra

pop_bottom:

   li   $v0   4

   la   $a0   pop_bottom_p

   syscall

   jr   $ra

Solution

using System; using System.Collections; public class SamplesStack { public static void Main() { // Creates and initializes a new Stack. Stack myStack = new Stack(); myStack.Push( \"The\" ); myStack.Push( \"quick\" ); myStack.Push( \"brown\" ); myStack.Push( \"fox\" ); // Displays the Stack. Console.Write( \"Stack values:\" ); PrintValues( myStack, \'\\t\' ); // Removes an element from the Stack. Console.WriteLine( \"(Pop)\\t\\t{0}\", myStack.Pop() ); // Displays the Stack. Console.Write( \"Stack values:\" ); PrintValues( myStack, \'\\t\' ); // Removes another element from the Stack. Console.WriteLine( \"(Pop)\\t\\t{0}\", myStack.Pop() ); // Displays the Stack. Console.Write( \"Stack values:\" ); PrintValues( myStack, \'\\t\' ); // Views the first element in the Stack but does not remove it. Console.WriteLine( \"(Peek)\\t\\t{0}\", myStack.Peek() ); // Displays the Stack. Console.Write( \"Stack values:\" ); PrintValues( myStack, \'\\t\' ); } public static void PrintValues( IEnumerable myCollection, char mySeparator ) { foreach ( Object obj in myCollection ) Console.Write( \"{0}{1}\", mySeparator, obj ); Console.WriteLine(); } } /* This code produces the following output. Stack values: fox brown quick The (Pop) fox Stack values: brown quick The (Pop) brown Stack values: quick The (Peek) quick Stack values: quick The */
Fill out the #missing# parts from the assembly language code(MIPS). data stack_pointer: .word 0 heap_pointer: .word 0 bottom_of_the_stack: .word 0 codes_p: .asc
Fill out the #missing# parts from the assembly language code(MIPS). data stack_pointer: .word 0 heap_pointer: .word 0 bottom_of_the_stack: .word 0 codes_p: .asc
Fill out the #missing# parts from the assembly language code(MIPS). data stack_pointer: .word 0 heap_pointer: .word 0 bottom_of_the_stack: .word 0 codes_p: .asc
Fill out the #missing# parts from the assembly language code(MIPS). data stack_pointer: .word 0 heap_pointer: .word 0 bottom_of_the_stack: .word 0 codes_p: .asc

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site