0% found this document useful (0 votes)
4 views11 pages

RISC-V Program 3: Bit Masks & Dates

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
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views11 pages

RISC-V Program 3: Bit Masks & Dates

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
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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@[Link].

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.

Common questions

Powered by AI

Achieving correct date manipulation and display in a RISC-V assembly program involves several carefully structured procedures. Begin by accurately reading the hexadecimal input and converting it to the opposite endian format if needed . Implement bitwise masking and shifting to separate and extract year, month, and day components from the input data . Each extraction task can be modularized into procedures for cleanliness and reusability, typically using registers to pass needed parameters and protect them during procedure calls . To convert numerical month outputs into string names for display, utilize arrays or lookup tables. Employ full month strings rather than abbreviations for clarity, printing these with the print_string system call using a proper register setup . Finally, ensure thorough testing of computed dates to verify date integrity and presentation correctness, making adjustments for any offset or base year differences as specified by the filesystem (e.g., FAT16 uses 1980 as a base year). Each procedure contributes to a seamless and correctly formatted output aligning with user-friendly design.

Writing and testing a RISC-V assembly language program requires consideration of several criteria outlined in the assignment rubric. First, ensure the program assembles without errors; syntax and logical errors must be rectified for full functionality . Commentary and documentation should sufficiently annotate the code, tying program design to implementation, which means including a comprehensive header and inline comments. Input and output must be managed using appropriate system calls with correct setups . The user interface should be neatly formatted. Additionally, verify that bitwise and logical operations compute and display correct outputs, such as date decoding or endian conversions . The rigorous application of these criteria determines the effectiveness and correctness of the program as per the evaluation standards.

Adhering to programming standards in RISC-V assembly language assignments is critical because it ensures that programs are understandable, maintainable, and properly evaluated by instructors or automated tools. Comprehensive commenting, including pseudocode and inline annotations, elucidates the program’s logic and function, aiding readability and potential bug-tracing . Structured comments link the implementation to its high-level design, which is especially important in low-level programming where misinterpretations can lead to severe logical errors. Proper file submission with the correct .asm extension ensures compatibility with tools like RARS for automated assembling and running tests . Standards not only reflect a professional discipline in programming but also impact the grading quality and accuracy, as programs that deviate from guidelines may face deductions or exhibit non-functionality, compromising individual evaluations and learning outcomes.

Bitwise operations can be employed in RISC-V assembly to decode a date from a FAT16 directory entry by masking and shifting specific bits to isolate and extract different components (year, month, day). First, convert the hexadecimal input to big-endian format if necessary, reversing the byte order to maintain correct bit positions . Utilize bitwise AND operations to mask out unwanted bits and keep only the relevant portions. For each component (year, month, day), shift the bits accordingly to align the least significant bit in the proper position, then use addition or multiplication to compute the exact values after shifting . This process helps in accurately extracting each portion of the date from the hexadecimal representation.

To implement a hexadecimal value input and decoding program in RISC-V, you need to follow these steps: First, write pseudocode to outline the logic and structure of your program. Translate this pseudocode into RISC-V assembly language. Use system calls to handle input and output; specifically, load the appropriate service code in register 'a7' and required arguments in registers 'a0', 'a1', etc., then execute the ecall instruction . For input, prompt the user to enter a hexadecimal date from a FAT16 directory entry and read it into your program. Use bitwise operations to decode the hexadecimal value, converting it into a human-readable date format by extracting year, month, and day components . Implement necessary arithmetic and memory operations to manipulate and store these values . Finally, format and display the decoded date, using an array to output the full month name, and handle program termination gracefully .

In a RISC-V assembly language program, welcome and farewell messages should be structured to meet user interface standards by being clear, informative, and user-friendly. The welcome message should include the programmer’s name, the program title, and a brief program description to provide context and introduce the program’s functionality . Each message should utilize string-printing system calls, with the message strings stored in memory either as arrays of characters or null-terminated strings, using 'a0' to pass the string address and 'a7' for the print service code. Farewell messages should similarly acknowledge the program end and thank the user for usage, offering a smooth and polite transition out of the application . Utilizing consistent formatting and clear labeling ensures messages contribute positively to user interaction and program aesthetics.

Converting from little-endian to big-endian format in RISC-V assembly involves challenges such as maintaining correct data representation across differing memory architectures. The solution is to reverse the byte order, ensuring bytes are placed in reverse sequence when reading or writing. This may be done by utilizing bitwise operations and shifts to rearrange the sequence of bytes in registers. Proper handling of these transformations is crucial; otherwise, data interpretation errors can occur. In a RISC-V environment, careful manipulation of bytes ensures that storage and subsequent operations on data maintain integrity and correctness . Adhering to these practices allows consistent and accurate data representation regardless of the underlying platform's native endianness.

Including comments and pseudocode in RISC-V assembly programs is important as it enhances code readability and maintainability. Comments provide insights into the programmer’s logic and intentions, facilitating easier code tracing and debugging. They explain the purpose of complex segments or algorithms, thereby aiding others or future-self to comprehend the assembly code’s flow. Pseudocode serves as an intermediary step between high-level algorithmic conception and low-level coding, ensuring that the programmer translates logical steps accurately into assembly instructions . This practice promotes better understanding, efficient debugging, and ensures code robustness especially when shared among team members or reviewed for improvements.

Using arrays and bit masks in date decoding within RISC-V assembly programs is crucial because they facilitate efficient data manipulation and storage. Arrays provide a structured method for storing elements such as strings for month names or other sequential data, enabling easy access and manipulation . Bit masks, through bitwise operations, allow extraction and modification of specific bits within a data word. This capability is essential for tasks like converting and decoding hexadecimal date values from the FAT16 filesystem, where distinct bits represent year, month, and day. These techniques, when combined, provide a powerful means to manage data representations smartly and perform complex operations systematically, enhancing the program's capability to handle intricate data transformations effectively.

Incorporating error handling and system call usage in a RISC-V program involves setting up checks before and after executing system calls to ensure robustness in managing user inputs. Use conditional branches to verify if expected data formats and values are received, and alert users with descriptive error messages if inputs are invalid or unexpected . System calls for receiving input must be properly configured by loading service codes into register 'a7' and using registers 'a0', 'a1', etc. to supply necessary argument data. Additional ecall checks can be used post-input to validate successful data reading. This dual strategy ensures that user inputs are received, processed correctly, and errors are managed gracefully, reducing program crashes or undefined behaviors.

You might also like