Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2020
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     .text   # 7.4
  2. main:               # start of program 
  3.     addi a7,zero,9      # set break ecall code
  4.     addi a0,zero,8      # argument ask for 8 Bytes
  5.     ecall           # malloc 8 bytes
  6.     sw t1,(a0)      # head node data=0
  7.     sw zero,4(a0)       # set null to next node pointer
  8.     add s0,zero,a0      # s0 = pointer in list head
  9.     add s1,zero,a0      # s1 = pointer in list tail
  10. loop74:             # LOOP starts here
  11.     jal ra,read_int     # call function read_int
  12.     add t0,zero,a0      # copy int form a0 to t0
  13.     bge zero,t0,exit74  # if 0 >= int(a0) go to cont74
  14.     jal ra,node_alloc   # go to node_alloc function
  15.     sw t0,(a0)      # save t0 to (a0)node.data
  16.     sw a0,4(s1)     # link the node in queue list
  17.     add s1,zero,a0      # set the new tail in s1
  18.     jal zero,loop74     # END OF LOOP
  19. exit74:
  20.     jal ra,read_int     # call function read_int
  21.     add s1,zero,a0      # copy int to s1
  22.     blt s1,zero,exit75  # if int(s1) < 0 exit program
  23.     add s2,zero,s0      # set s2 as pointer of the list
  24.  
  25.     add a0,zero,s2      # pass s2 pointer as parameter
  26.     add a1, zero,s1     # pass integer s1 as parameter
  27.     jal ra,search_list  # go to s_l fynct
  28.  
  29. read_int:
  30.     addi a7,zero,5      # ecall code for read_int
  31.     ecall           # read a line containing an integer
  32.     jr ra           # return from function
  33.    
  34. node_alloc:
  35.     addi a7,zero,9      # ecall code for set break
  36.     addi a0,zero,8      # argument ask for 8 Bytes
  37.     ecall           #
  38.     jr ra           # return from function
  39.    
  40. print_node:
  41.     lw t0,(a0)      # load word from list(s2)
  42.     bge a1,t0,cont75    # if s1 >= t0 go to
  43.     addi a7,zero,1      # ecall code for print_int
  44.     add a0,zero,t0      # copy t0 to a0 for the ptint
  45.     ecall           #
  46.     jr ra           # return fron function
  47.    
  48. search_list:   
  49.     loop_s:
  50.         addi sp,sp,-4       # make space in stack
  51.         sw a0,(sp)      # store parameter in stack
  52.         jal ra,print_node   # call print_node funct
  53.         lw a0,(sp)      # get word from stack
  54.     cont75:
  55.         addi a0,a0,8        # move on next node
  56.         lw t0,(a0)      # load word node
  57.         beq t0,zero,exitl   # if pointer is NULL branch
  58.         jal zero,loop_s     # go to get next int
  59.     exitl:  
  60.         jal zero,exit74     # go to lopp75 start
  61.     exit75:
  62.         addi a7,zero,10     # ecall for exit program
  63.         ecall           # exit
  64.         jr ra           # return from function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement