0% found this document useful (0 votes)
2 views

Program 3

This assignment involves writing a RISC-V assembly program to decode a hexadecimal date from a FAT16 directory entry using bit masks and bit-wise operations. Students will learn to read input, implement pseudocode, and perform system calls for input and output. The program must include sufficient comments and follow assembly language programming standards to ensure clarity and correctness.

Uploaded by

i200745
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Program 3

This assignment involves writing a RISC-V assembly program to decode a hexadecimal date from a FAT16 directory entry using bit masks and bit-wise operations. Students will learn to read input, implement pseudocode, and perform system calls for input and output. The program must include sufficient comments and follow assembly language programming standards to ensure clarity and correctness.

Uploaded by

i200745
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Program 3: Using bit masks in RISC-V Assembly

and the RARS environment

Purpose:

This assignment is designed to give you the opportunity to input a


hexadecimal value and manipulate and decode that value using bit masks
and bit-wise operations.

Resources:

Learning Objectives:

You should be able to perform the following activities at the end of this
assignment:

1. read a string from the standard input

2. write an algorithm in pseudocode

3. translate the algorithm from pseudocode into RISC-V assembly

4. implement bit-wise logical operations to extract and operate on stored


values

5.

Specific Tasks:

Write and test a RISC-V assembly language program to perform the following
actions in order:

1. Download the template for program 3 Download template for


program 3, which contains a routine to read hex integers.

2. Print a welcome message that include: your name, a title, and a brief
description of the program.

3. Prompt the user to enter the hexadecimal date from a FAT16 directory
entry

4. Use the decoding information for the FAT filesystem to convert this
hexadecimal value to a string representation of the date for the file
table entry. (Decoding information can be found here).

1. Convert to big-endian
2. Decode the month, day and year, using a procedure for each
and remember to print the whole month name, not an
abbreviation.

5. Display the date corresponding to the hexadecimal value as a string

6. Print a farewell message and exit the program gracefully.

Your program should follow these loosely outlined steps in its implementation
(i.e., write the code for step 1, then for step2, etc.).

Assembly Language Programming Standards

Comments are vital in assembly language programming. You will need to


include a header similar to the one included in the RISC-V Assembly
template. In particular the Pseudocode section and the register information
will help you solidify your understanding of the program requirements and
your method of solution.

You will also need to include comments, whitespace, and blank lines in your
code to make it easy to read and to follow the implementation of the
pseudocode. While one comment per line is not required, you are
encouraged to include enough comments in you code to allow easy tracing
of the pseudocode logic through your assembly implementation (see the
Fibonacci example provided on Canvas).

Programs that do not include sufficient internal documentation via comments


will receive deductions as indicated in the assignment rubric.

Sample Execution

Here is sample output from my solution program (your output may vary).
Try 4259 and 6559 as input values (October 2, 2024 and November 5, 2024).

Submitting your program

You need to submit your complete assembly language program using


Canvas. The only file extension that is accepted is the ".asm" file created by
the RARS program.

Additional Information:

There are several system calls that are available for use in the RISC-V
assembly language. These system calls must be used for input and output in
your programs.

To perform a system call:

1. Load the service code in the a7 register


2. Load any required argument values in a0, a1,a2, or fa0, etc., as the
system call requires

3. Issue the ecall instruction

4. Use the returned values, if any, from the registers designated in the
command description

Example:

li a7, 4 # service 4 is print a NULL terminated string


la a0, prompt # load address of string in $a0, this is a "macro"
ecall # initiate the system call to print the string

A partial list available system calls and codes including the ones needed
for this assignment:

Code
ecall name Arguments Results
in a7

print integer 1 a0 = integer to print

print float 2 fa0 = float to print

fa0 = double to
print double 3
print

a0 = address of
print string 4 null-terminated
string to print

read integer 5 a0 contains the integer read

read float 6 fa0 contains float read

read double 7 fa0 contains double read

read string 8 a0 = address of reads up to a1-1 characters or up


input buffer to a newline, whichever is less,
a1 = maximum and null terminates
number of
characters to read

sbrk (allocate a0 = number of a0 = contains address of


9
heap memory) bytes to allocate allocated memory

exit (terminate
10
execution)

RISC-V Assembly commands you may need for this assignment:

Arithmetic:

 add t1, t2, t3 Addition with overflow t1 = t2 + t3

 sub t1, t2, t3 Subtraction with overflow t1 = t2 - t3

 mul t1, t2, t3 Multiply t1 = t2 x t3 low order 32-bits of result

 div t1, t2, t3 Divide t1 = t2/t3

 rem t1, t2, t3 Remainder t1 = remainder of t2/t3

Memory Access:

 lw t1, offset(t2) Load word from memory t1 = word at [t2 + offset]

 lw t1, label Load word at the "label" address

 sw t1, offset(t2) Store word into memory word at [t2 + offset] = t1

 sw t1, label, t2 NOTE: some store instructions require a "temp"


register

 mv t1, t2 Copy contents of t2 into t1 (extended instruction)

Other commands:

 ecall Execute the system call identified by a7 (see above)

 la t1, label Load the address of label into t1 t1 = address of


label

 li t1, immd Load the numeric value immd into t1 t1 = immd

The one hour rule... If you have been working on a problem for over an
hour with no progress, contact me, usually with a copy of your code as an
attachment to an email. Please use the email address in the syllabus:
markhuson@weber.edu.

Array and Bitmask with Date Decoding Rubric

Criteria Ratings

20 pts

Assembles with no
problems

15 pts

Minor typographical
or transfer errors
Program assembles without errors prevent assembly
without modification

0 pts

Major modifications
required or only a
shell of the
complete program is
present

Program commented appropriately 15 pts

Full program header


including
pseudocode,
program commented
througout to tie
implementation to
program design

12 pts

Comments do not
Array and Bitmask with Date Decoding Rubric

Criteria Ratings

identify key portions


of code

8 pts

Program heading
comments
incomplete, do not
match template

0 pts

Token commenting
or no comment, just
author name or
other similar
comments in
program

Program Input and Output handled correctly, demonstrating 10 pts


proper use of system calls
Full Marks

5 pts

Most I/O properly


handled, but some
logic errors in either
argument or result
processing

0 pts

Input and output


does not work
properly, registers
and calls set up and
Array and Bitmask with Date Decoding Rubric

Criteria Ratings

performed correctly

5 pts

Output is neatly
formated, labeled
and clear to follow

3 pts

Some labels or
User interface formatting. requirements
missing, or
formatted
inappropriately

0 pts

Output not
formated, no labels,
only values printed.

Numeric value read in correctly 5 pts

Appropriate system
calls and registers
used to read in
hexadecimal value

3.34 pts

System calls correct


but other issues in
using values in
program

1.67 pts
Array and Bitmask with Date Decoding Rubric

Criteria Ratings

Valiant attempt, but


values neither read
nor used

0 pts

We needed numeric
values to compute
the power of a
number?

All three required procedures appropriately implemented 15 pts


(no procedures, no points)
For all 3 required
procedures,
appropriate
parameter values
prepared, procedure
called with jal, and
used registers are
pushed and poped
before if necessary

10 pts

One or more
procedures has side
effects from call as
used registers are
not protected.

5 pts

Procedures created
but not properly
called/implemented/
used resulting in
Array and Bitmask with Date Decoding Rubric

Criteria Ratings

program errors.

0 pts

No procedures
implemented for this
problem.

10 pts

All dates are correct.

5 pts

One or more
portions of the date
Date value computed correctly are computed
incorrectly.

0 pts

Perhaps the world


doesn't start until
2080 instead of
1980.

Date is displayed correctly. 15 pts

Lookin' good, yes,


full month name,
pulled from a string
(array of
characters).

10 pts

Spacing off or dates


don't quite display
Array and Bitmask with Date Decoding Rubric

Criteria Ratings

correctly, though
month value is
extracted from a
string (array of
characters).

0 pts

Display completely
incorrect or month is
determined solely
with a massive
"case" statement
implemnetation...
bummer.

5 pts

Byte order is
reversed

2.5 pts
Conversion from little endian to big endian is performed Bytes are moved,
correctly but do not end in
contiguous bytes.

0 pts

No coversion
attempted.

You might also like