Computer Architecture I ShanghaiTech University
HW2 HW3 HW4
In this homework you will write a program to generate a preorder traversal of a binary search tree from given inorder and postorder traversals using RISC-V. Here is a very simple template.
The input is given by one integer and two array of integers in form of data in data section,
input_size:
.word 4
input_inorder:
.word 1
.word 2
.word 3
.word 4
input_postorder:
.word 1
.word 2
.word 4
.word 3
or in equivalent form of global variable in c language.
input_size
is the size of both input_inorder
and input_postorder
, which contain inorder and postorder of a same tree respectively. For example, the previous input specify the following tree.
3
/ \
2 4
/
1
The numbers representing nodes are not necessarily continuous or positive.
The output will consist of one single line with input_size
number of integers representing the preorder traversal of the binary search tree.
For example the output of the program given the input above would be
3 2 1 4
Notice that each number is separated by exactly one space, and at the end of the line, there are exactly one space and one line break ('\n'
). Any output in other format will be rejected.
We will test your program using RISC-V emulator venus. You probably want to read this before you started.
#
.hw3.s
. Any other file found will result in a score of zero. Submission containing any of input_size
, input_inorder
or input_postorder
label will be rejected.