Как перейти в конец скрипта к основному файлу - PullRequest
0 голосов
/ 09 мая 2019

У меня есть код на 3 файла: главный, func1, func2

код в главном файле (размещен ниже) вызывает функции, которые находятся в отдельных файлах, а затем печатает сообщение для пользователя.

проблема в том, что после завершения основного сценария (и после метки выхода) ЦП выполняет следующую инструкцию, которая является первой инструкцией внешних файлов (первая инструкция func1)

мне нужно понять, как перейти к концу объединенного файла (длинный скрипт на симуляторе, когда он объединяет основной файл с файлом функций)

Я пытался читать здесь и в сети, но безуспешно

это основной код скрипта:

.globl  main
.data 
    .asciiz 
    requestLength: "please insert the length of the list: "
    insert1:"insert number "
    insert2:" out of "
    arithSeq:"This is Arithmetic sequence"
    geoSeqMsg:"This is Geometric sequence"
    bothSeq:"This is both Arithmetic&Geometric sequence"
    none: "This is not Arithmetic nor Geometric sequence"
    .align 2
array: .word

.text
main:

# request length of the list from the user and store it in $t0
#start of the list is on $t2
la $t2, array
la $a0, requestLength
li $v0, 4
syscall

li $v0,5
syscall
addi $t0, $v0, 0

#loop of inserting numbers, the counter is $t1
li $t1, 0
loop:
    addi $t1, $t1, 1
    la $a0, insert1
    li $v0, 4
    syscall

    addi $a0, $t1, 0
    li $v0, 1
    syscall

    la $a0, insert2
    li $v0, 4
    syscall

    addi $a0, $t0, 0
    li $v0, 1
    syscall

    li $v0, 5
    syscall
    sw $v0, 0($t2)

    addi $t2, $t2, 4

    bne $t0, $t1, loop


#functions to check what type of sequence (keep results in t1,t2)

la $a0, array  #argument. a0: address of the array
addi $a1, $t0, 0 #argument. a1:size of the array

la $t5, geoSeq
jalr $t5
addi $t1, $v0, 0

jal arithematicSeq
addi $t2, $v0, 0

#print:
bne $t1, $t2, dif
    bne $t1, 0, printBoth
    la $a0, none #not sequence at all
    li $v0, 4
    syscall
    j exit
    printBoth:
        la $a0, bothSeq
        li $v0, 4
        syscall
    j exit

dif:
    bne $t1, 1, printGeo
    la $a0, arithSeq #arithmatic sequence
    li $v0, 4
    syscall
    j exit
    printGeo:
        la $a0, geoSeqMsg #geometric sequenc
        li $v0, 4
        syscall
        j exit:

exit:

func1:

.globl geoSeq
.text
   geoSeq: #a0: address of the list, a1: the size of the list
    addi $sp, $sp, -24
    sw $t0, 20($sp)
    sw $t1, 16($sp)
    sw $t2, 12($sp)
    sw $t3, 8($sp)
    sw $t4, 4($sp)
    sw $t5, 0($sp)

    li $v0, 1 #v0 is true by default
    add $t0, $a0, $zero #to save start of the list 
    add $t1, $a1, $zero #save the size of list

    lw $t2, 0($t0)  
    lw $t3, 4($t0)  
    div $t3, $t2 #set $t4 to the diffrence of the series
    mflo $t4
    bne $t4, 1, geoFail
    mfhi $t4
    geoLoop:   #check if the series follow the difference 
        addi $t1, $t1, -1
        addi $t2, $t2, 4

        lw $t2, 0($a0)  
        lw $t3, 4($a0)  
        div $t3, $t2 #set $t4 to the diffrence of the series
        mflo $t4
        bne $t4, 1, geoFail
        mfhi $t4
        bne $t4, $t5,geoFail

        bne $t1, 1, geoLoop #the loop should need to stop one number before the end to make sure we would not exceed the array      
    j geoExit
    geoFail:
    li $v0, 0

    geoExit:            
    lw $t5, 0($sp)
    lw $t4, 4($sp)
    lw $t3, 8($sp)
    lw $t2, 12($sp)
    lw $t1, 16($sp)
    lw $t0, 20($sp)
    addi $sp, $sp, 24
    jr $ra

func2:

.globl arithematicSeq
.text
   arithematicSeq: #a0: address of the list, a1: the size of the list
    addi $sp, $sp, -24
    sw $t0, 20($sp)
    sw $t1, 16($sp)
    sw $t2, 12($sp)
    sw $t3, 8($sp)
    sw $t4, 4($sp)
    sw $t5, 0($sp)

    li $v0, 1 #v0 is true by default
    add $t0, $a0, $zero #to save start of the list 
    add $t1, $a1, $zero #save the size of list

    lw $t2, 0($t0)  
    lw $t3, 4($t0)  
    sub $t4, $t3, $t2 #set $t4 to the diffrence of the series

    arthLoop:   #check if the series follow the difference 
        addi $t1, $t1, -1
        addi $t2, $t2, 4

        lw $t2, 0($a0)  
        lw $t3, 4($a0)  
        sub $t5, $t3, $t2
        bne $t4, $t5,arthFail

        bne $t1, 1, arthLoop    #the loop should need to stop one number before the end to make sure we would not exceed the array      
    j arthExit
    arthFail:
    li $v0, 0

    arthExit:           
    lw $t5, 0($sp)
    lw $t4, 4($sp)
    lw $t3, 8($sp)
    lw $t2, 12($sp)
    lw $t1, 16($sp)
    lw $t0, 20($sp)
    addi $sp, $sp, 24
    jr $ra



Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...