Advertisement
karol_dziachan

task2_exam_PWR_assembler

May 27th, 2020
3,191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .data
  2.     enter: .asciiz "Enter the number: "
  3.     menu: .asciiz "\nChoose action \n[1]Add number\n[2]Display number\n[3]End: "
  4.     empty: .asciiz "The stack is empty"
  5.    
  6.     numberFromTop: .asciiz "Number: "
  7.    
  8.     # 2 – for word and 0 – for byte
  9.    .align 2
  10.    #memory reservation
  11.     stack: .space 100
  12. .text
  13. #$t2 will be counter
  14.     li $t2, 0
  15. # init stack
  16.     la $sp, stack
  17. .main:
  18.  
  19. menuE:
  20.    #display menu
  21.     la $a0, menu
  22.     li $v0, 4
  23.     syscall
  24.    
  25.     #choose
  26.     li $v0,5
  27.     syscall
  28.        
  29.     #save choose in $t0
  30.     move $t0,$v0
  31.    
  32.     beq $t0, 1, readNumbers
  33.     nop
  34.  
  35.     beq $t0, 2, checkStack
  36.     nop
  37.    
  38.     end:
  39.         li $v0,10
  40.     syscall
  41.    
  42.  
  43.  
  44.   checkStack:
  45.  #check whether stack is empty
  46.   beq $t2, 0, emptyStack
  47.  
  48. printOneNumber:
  49.  
  50.   # display 'number'
  51.     li $v0, 4
  52.     la $a0, numberFromTop
  53.     syscall
  54.    
  55.     #download numebr and display
  56.    subi $sp, $sp, 4
  57.     l.s $f12, 0($sp)
  58.     li $v0, 2
  59.    syscall
  60.  
  61.     #decrement counter  
  62.      sub $t2, $t2, 1
  63.  
  64.  
  65.  
  66.      j menuE
  67.     nop
  68.    
  69.    
  70.  
  71. readNumbers:
  72.    # display 'enter'
  73.     li $v0, 4
  74.     la $a0, enter
  75.     syscall
  76.    # $f0=number
  77.     li  $v0, 6
  78.     syscall
  79.    # $f0 to stack
  80.     s.s $f0, 0($sp)
  81.     addi $sp, $sp, 4
  82.    
  83.     add $t2, $t2, 1
  84.    
  85.     j menuE
  86.     nop
  87.  
  88.  
  89. #when stack is empty
  90. emptyStack:
  91.     li $v0, 4
  92.     la $a0, empty
  93.     syscall
  94.    
  95.     j menuE
  96.     nop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement