########################## # Programmrahmen fuer die 2. Praktikumsaufgabe # # Name: Matr.: # Name: Matr.: # Name: Matr.: # ########################## .text main: la $t0, tree sw $zero, 0($t0) li $v0, 13 #open the file la $a0, filename li $a1, 0 li $a2, 0 syscall addi $t9, $a0, 0 #save the file resource li $v0, 14 #read the data la $a1, newdata li $a2, 1024000 syscall li $v0, 16 #close the file addi $a0, $t9, 0 syscall la $t9, newdata readout_first_line: #find the end of the first line lb $t0, 0($t9) addi $t9, $t9, 1 bne $t0, 13, readout_first_line addi $t9, $t9, -1 sb $zero, 0($t9) #make a string out of the first line la $a0, newdata #parse an integer out of it jal atoi addi $s2, $v0, 0 #save the number of rows li $t0, 13 sb $t0, 0($t9) #set the new line char back la $s3, tree #set the end of the tree readout_loop: lb $t0, 0($t9) #repeat until the new row is found addi $t9, $t9, 1 bne $t0, 13, readout_loop addi $a0, $t9, 0 la $a1, tree addi $a2, $s3, 0 jal insert #call the insert function addi $s3, $v0, 0 #save the new end of the tree addi $s2, $s2, -1 #decrease the number of rows left bgtz $s2, readout_loop #repeat if there are rows left la $a0, tree #printout the results jal print_inorder j end ##################################################################### ## atoi: Konvertiert einen String in eine Ganzzahl ## ## Parameter: $a0 - address of the string ## ## Rückgabewert: $v0 - parsed number ## ## Used: $s0, $t0, $t1, $t2 atoi: add $s0, $ra, $zero #save return address li $v0, 0 #init the result li $t2, 10 #init the step addi $t0, $a0, 0 #start the counter atoi_loop: #iterate over the chars in the string lb $t1, 0($t0) #get the char addi $t0, $t0, 1 beqz $t1, end_atoi #exit if end of string blt $t1, 48, error_not_number #throw and error if NaN bgt $t1, 57, error_not_number mul $v0, $v0, $t2 #shift the result in decimal add $t1, $t1, -48 #make the char a number add $v0, $v0, $t1 #add it to the temporary result j atoi_loop error_not_number: li $v0, 4 #print error message la $a0, error_msg1 # because non-numerical char was found syscall li $v0, 10 # and exit syscall end_atoi: add $ra, $s0, $zero #restore return address jr $ra ##################################################################### ## strcmp: Vergleicht zwei Stings miteinander ## ## Parameter: $a0 - address of the first string ## $a1 - address of the second string ## ## Rückgabewert: $v0 - -1:a1a0 ## ## Used: $s1, $t4, $t5, $t6, $t8 strcmp: add $s1, $ra, $zero #save return address addi $t4, $a0, 0 addi $t5, $a1, 0 strcmp_loop: lb $t6, 0($t4) #load the current chars from both lb $t7, 0($t5) # data locations addi $t4, $t4, 1 addi $t5, $t5, 1 bne $t6, $t7, found_difference #check if there is a difference bne $t6, 58, strcmp_loop #check if the end of the data li $v0, 4 #print error message la $a0, error_msg # because the same names were found syscall li $v0, 10 # and exit syscall found_difference: #if there is difference bgt $t6, $t7, is_greater_than #if a0