Task 1. Assume you are dealing
with a 32 bit microprocessor that accesses memory in words (i.e. 32
bits) at a time, while memory is addressed bytewise. You should
store strings in memory in an aligned way. You should use as little
memory as possible without becoming unaligned.
- Sketch the
memory of the specified machine, with the string "S" stored
starting at an address above or equal to 2012 (decimal).
- Sketch the
memory of the specified machine, with the string "S" stored
starting at an address above or equal to 2013 (decimal).
- Sketch the memory of the specified machine, with the
strings "Sunshine", "Rainy", "Joy", and "Pain", stored starting at an
address above or equal to 2012 (decimal).
- Sketch the memory of the specified machine, with the
strings "Sunshine", "Rainy", "Joy", and "Pain", stored starting at
an address above or equal to 2013 (decimal).
Assume that each character in the strings is ASCII, and uses 1 byte of
storage.
Task 2. Download and install
the
RARS
RISC-V simulator and familiarise yourself with using RARS.
Task 3. Familiarise yourself
with the RISC-V processor and assembler language. Here are some links
you may find helpful (no need to read all).
- Short RISC-V Assembler
Reference.
- Advanced material (going way beyond what's needed in our course):
Task 4. Write the following
programs in RISC-V assembler language.
- A program that counts the content of register
t1
down to 0 and then terminates.
- A program that counts the content of a memory cell down to 0 and
then terminates. They following (pseudo) commands might be useful:
- The (pseudo) command
la reg mem loads the
label mem into the register reg .
- The (pseudo) command
sw reg1 mem reg2 stores the content
of reg1 in the memory cell addressed by the label mem , using
reg2 as temporary.
- A program that copies 100 Bytes from one region of memory to another.
- A program that copies
N words from the memory region starting
at A to the memory region starting at B .
Note that the source and target regions may overlap, or incrementing a
register may lead to wrapping of the register back to 0. Is that a
problem for your program?
- Write a program that computes (2+3)*4 and leaves the result on
top of the stack (remember that the stack pointer should always point
to the first free memory cell that's above the top of the stack, if
the stack grows downwards).
I recommend that you try out your RISC-V programs in RARS (step
mode) and observe how the execution changes registers and memory.
Task 5.
You were asked in last week's tutorial how to simulate an
accumulator machine on a register machine. The RISC-V assembly
language does not contain push and pop
operations. RISC-V also does not allow binary operations
(e.g. addition and comparison) to fetch arguments from the
stack. How can we simulate an accumulator machine in RISC-V? Does the
simulation work for the register machines with limited registers we
saw in lecture 8
(see here)?
Recall that we discussed a two-phase strategy for register machines
with limited registers
(see here).
Is this strategy still working if you simulate accumulator machines
in a register machine with limited registers? How?
|