Skip to content
Snippets Groups Projects
Commit eab53360 authored by Pavel Pisa's avatar Pavel Pisa
Browse files

seminaries/qtrvsim/bubble-sort: provided template for bubble sort implementation.


The directory contain seminaries/qtrvsim/buble-sort/bubble-sort-template.S
file. The whole directory or only only this file should appear in the
directory work/bubble-sort/bubble-sort.S and changes should be sent
to your repository. We are working on automation process for the testing.
Expect more instructions.

Signed-off-by: default avatarPavel Pisa <pisa@cmp.felk.cvut.cz>
parent 8cff9743
No related branches found
No related tags found
No related merge requests found
*.o
depend
bubble-sort
array_data.out
array_size.in
array_data.ref
ARCH=riscv64-unknown-elf
SOURCES = bubble-sort.S
TARGET_EXE = bubble-sort
CC=$(ARCH)-gcc
CXX=$(ARCH)-g++
AS=$(ARCH)-as
LD=$(ARCH)-ld
OBJCOPY=$(ARCH)-objcopy
ARCHFLAGS += -mabi=ilp32
ARCHFLAGS += -march=rv32i
ARCHFLAGS += -fno-lto
CFLAGS += -ggdb -Os -Wall
CXXFLAGS+= -ggdb -Os -Wall
AFLAGS += -ggdb
LDFLAGS += -ggdb
LDFLAGS += -nostartfiles
LDFLAGS += -nostdlib
LDFLAGS += -static
#LDFLAGS += -specs=/opt/musl/riscv64-linux-gnu/lib/musl-gcc.specs
CFLAGS += $(ARCHFLAGS)
CXXFLAGS+= $(ARCHFLAGS)
AFLAGS += $(ARCHFLAGS)
LDFLAGS += $(ARCHFLAGS)
OBJECTS += $(filter %.o,$(SOURCES:%.S=%.o))
OBJECTS += $(filter %.o,$(SOURCES:%.c=%.o))
OBJECTS += $(filter %.o,$(SOURCES:%.cpp=%.o))
all : default
.PHONY : default clean dep all run_test
%.o:%.S
$(CC) -D__ASSEMBLY__ $(AFLAGS) -c $< -o $@
%.o:%.c
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
%.o:%.cpp
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $<
%.s:%.c
$(CC) $(CFLAGS) $(CPPFLAGS) -S $< -o $@
#default : $(TARGET_EXE)
default : run_test
$(TARGET_EXE) : $(OBJECTS)
$(CC) $(LDFLAGS) $^ -o $@
dep: depend
depend: $(SOURCES) $(glob *.h)
echo '# autogenerated dependencies' > depend
ifneq ($(filter %.S,$(SOURCES)),)
$(CC) -D__ASSEMBLY__ $(AFLAGS) -w -E -M $(filter %.S,$(SOURCES)) \
>> depend
endif
ifneq ($(filter %.c,$(SOURCES)),)
$(CC) $(CFLAGS) $(CPPFLAGS) -w -E -M $(filter %.c,$(SOURCES)) \
>> depend
endif
ifneq ($(filter %.cpp,$(SOURCES)),)
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -w -E -M $(filter %.cpp,$(SOURCES)) \
>> depend
endif
clean:
rm -f *.o *.a $(OBJECTS) $(TARGET_EXE) depend array_data.out array_data.ref array_size.in
#riscv64-unknown-elf-objdump --source bubble-sort
ARRAY_DATA_IN_FILE=array_data.in
ARRAY_SIZE:=$(words $(shell cat $(ARRAY_DATA_IN_FILE)))
ARRAY_BYTES:=$(words $(shell seq 1 $(ARRAY_SIZE)) $(shell seq 1 $(ARRAY_SIZE)) $(shell seq 1 $(ARRAY_SIZE)) $(shell seq 1 $(ARRAY_SIZE)))
run_test: $(TARGET_EXE)
echo $(ARRAY_SIZE) >array_size.in
sort <array_data.in >array_data.ref
qtrvsim_cli --dump-cycles $< \
--load-range array_size,array_size.in \
--load-range array_start,$(ARRAY_DATA_IN_FILE) \
--dump-range array_start,$(ARRAY_BYTES),array_data.out
diff -u -B -b array_data.out array_data.ref
-include depend
0x00000022
0x00000055
0x00000060
0x12345678
0x12345676
0x00000012
0x00000008
0x000000ac
0x33333333
0x02000010
0x00008382
0x12375310
0x00012340
0x00020202
0x00028288
// 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 mips-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
#pragma qtrvsim show registers
#pragma qtrvsim show memory
.option norelax
.globl array_size
.globl array_start
.text
.globl _start
_start:
la a0, array_start
la a1, array_size
lw a1, 0(a1) // number of elements in the array
//Insert your code there
//Final infinite loop
end_loop:
fence // flush cache memory
ebreak // stop the simulator
j end_loop
.data
// .align 2 // not supported by qtrvsim yet
array_size:
.word 15
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment