Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .text # 7.4
- main: # start of program
- addi a7,zero,9 # set break ecall code
- addi a0,zero,8 # argument ask for 8 Bytes
- ecall # malloc 8 bytes
- sw t1,(a0) # head node data=0
- sw zero,4(a0) # set null to next node pointer
- add s0,zero,a0 # s0 = pointer in list head
- add s1,zero,a0 # s1 = pointer in list tail
- loop74: # LOOP starts here
- jal ra,read_int # call function read_int
- add t0,zero,a0 # copy int form a0 to t0
- bge zero,t0,exit74 # if 0 >= int(a0) go to cont74
- jal ra,node_alloc # go to node_alloc function
- sw t0,(a0) # save t0 to (a0)node.data
- sw a0,4(s1) # link the node in queue list
- add s1,zero,a0 # set the new tail in s1
- jal zero,loop74 # END OF LOOP
- exit74:
- jal ra,read_int # call function read_int
- add s1,zero,a0 # copy int to s1
- blt s1,zero,exit75 # if int(s1) < 0 exit program
- add s2,zero,s0 # set s2 as pointer of the list
- add a0,zero,s2 # pass s2 pointer as parameter
- add a1, zero,s1 # pass integer s1 as parameter
- jal ra,search_list # go to s_l fynct
- read_int:
- addi a7,zero,5 # ecall code for read_int
- ecall # read a line containing an integer
- jr ra # return from function
- node_alloc:
- addi a7,zero,9 # ecall code for set break
- addi a0,zero,8 # argument ask for 8 Bytes
- ecall #
- jr ra # return from function
- print_node:
- lw t0,(a0) # load word from list(s2)
- bge a1,t0,cont75 # if s1 >= t0 go to
- addi a7,zero,1 # ecall code for print_int
- add a0,zero,t0 # copy t0 to a0 for the ptint
- ecall #
- jr ra # return fron function
- search_list:
- loop_s:
- addi sp,sp,-4 # make space in stack
- sw a0,(sp) # store parameter in stack
- jal ra,print_node # call print_node funct
- lw a0,(sp) # get word from stack
- cont75:
- addi a0,a0,8 # move on next node
- lw t0,(a0) # load word node
- beq t0,zero,exitl # if pointer is NULL branch
- jal zero,loop_s # go to get next int
- exitl:
- jal zero,exit74 # go to lopp75 start
- exit75:
- addi a7,zero,10 # ecall for exit program
- ecall # exit
- jr ra # return from function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement