From 84eb1d6068803b969ceed432f721b8ed29777627 Mon Sep 17 00:00:00 2001 From: "Ponomarev, Nazar" Date: Sun, 20 Mar 2022 11:35:39 +0000 Subject: [PATCH] Update bubble-sort-template.S --- .../qtrvsim/buble-sort/bubble-sort-template.S | 68 +++++++++++-------- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/seminaries/qtrvsim/buble-sort/bubble-sort-template.S b/seminaries/qtrvsim/buble-sort/bubble-sort-template.S index 1e71ed5..302c066 100644 --- a/seminaries/qtrvsim/buble-sort/bubble-sort-template.S +++ b/seminaries/qtrvsim/buble-sort/bubble-sort-template.S @@ -1,46 +1,56 @@ -// bubble-sort.S file template, rename and implement the algorithm -// Test algorithm in qtrvsim_gui program -// Select the CPU core configuration with delay-slot -// This setups requires (for simplicity) one NOP instruction after -// each branch and jump instruction (more during lecture about pipelining) -// The code will be compiled and tested by external riscv64-unknown-elf-gcc -// compiler by teachers, you can try make in addition, but testing -// by internal assembler should be enough - -// copy directory with the project to your repository to -// the directory work/bubble-sort -// critical is location of the file work/bubble-sort/bubble-sort.S -// which is checked by the scripts - -// Directives to make interesting windows visible +// Directives to make interresting windows visible #pragma qtrvsim show registers #pragma qtrvsim show memory +.globl _start +.globl array_size +.globl array_start .option norelax -.globl array_size -.globl array_start - .text -.globl _start _start: - +la a1, array_size +lw a1, 0(a1) // number of elements in the array +addi s0, zero, 0 // inicializacni prikaz cyklu for: i=0, kde i=s1 +addi s1, a1, -1 // nastaveni horni meze cyklu 1 +addi t1, zero, 1 +for1: + addi t2, zero, 0 + beq s0, s1, end1 + addi s2, zero, 0 // inicializacni prikaz cyklu for: j=0, kde j=s2 + sub s3, s1, s0 // nastaveni horni meze cyklu 2 la a0, array_start - la a1, array_size - lw a1, 0(a1) // number of elements in the array - -//Insert your code there + for2: + beq s2, s3, end2 + lw a2, 0x0(a0) + lw a3, 0x4(a0) + slt t0, a3, a2 + bne t0, t1, L1 + addi t2, t2, 1 + sw a3, 0x0(a0) + sw a2, 0x4(a0) + + L1: + addi a0, a0, 0x4 + addi s2, s2, 1 + + j for2 + end2: + + addi s0, s0, 1 + beq t2, zero, end1 + j for1 +end1: //Final infinite loop end_loop: - fence // flush cache memory - ebreak // stop the simulator + ebreak // stop the simulator j end_loop - + nop .data -// .align 2 // not supported by qtrvsim yet +// .align 2 // not supported by QtRVSim yet array_size: .word 15 @@ -48,4 +58,4 @@ array_start: .word 5, 3, 4, 1, 15, 8, 9, 2, 10, 6, 11, 1, 6, 9, 12 // Specify location to show in memory window -#pragma qtrvsim focus memory array_size +#pragma qtrvsim focus memory array_start -- GitLab