Skip to main content Link Menu Expand (external link) Document Search Copy Copied

RISC-V Access and Number Conversion in C

Deliverables due Tue Sep 3rd by 11:59pm in your Project01 GitHub repo

Project01 will be interactively graded on Wed Sep 4th

Get tests repo here: https://github.com/USF-CS315-F24/tests

Get autograder here: https://github.com/phpeterson-usf/autograder

Dev Environment Requirments

  1. Show you can use ssh without passwords to access the BeagleV machines.
  2. Show you can access GitHub using ssh keys for your repos on the BeagleV machines.
  3. Show you can run the autograder on the BeagleV machines.
  4. Show you can use a console-based editor like micro or vim (not nano).
  5. (Extra credit) Show you can do all of the above on a local RISC-V Ubuntu VM.

Warmup problem - numinfo

For this problem you will implement a C program called numinfo that takes a string as a single command line argument and determines if the string can represent an integer value (int), and binary value (bin) or a hexadecimal value (hex). The numinfo command works like this:

$ ./numinfo 1010
int: true
bin: true
hex: true

$ ./numinfo 1234
int: true
bin: false
hex: true

$ ./numinfo 1AB3
int: false
bin: false
hex: true

$ ./numinfo 1ab3
int: false
bin: false
hex: true

$ ./numinfo
Usage: numinfo <value>

Note that an integer value must consist of only decimal digits (0, 1, 2, …, 9). A binary value must consist of only the digits 0 or 1, and a hexadecimal value must consist of only digits or the letters (a, b, c, d, e, f, A, B, C, D, E, F). You should implement your solution by writing several helper functions:

bool is_dec_digit(char c);
bool is_bin_digit(char c);
bool is_hex_digit(char c);
bool is_dec_str(char *s);
bool is_bin_str(char *s);
bool is_hex_str(char *s);

Number Base Conversion - numconv

You will implement a base conversion tool called numconv. It converts numbers expressed in bases 2, 10, and 16 into the other bases. The numconv program can optionally output the conversion in multiple bases. The order of the output bases is fixed: base2, base10, then base16. Examples:

$ ./numconv 10 -o 2
0b1010
$ ./numconv 0xFF -o 10
255
$ ./numconv 0b11011110101011011011111011101111 -o 16
0xDEADBEEF
$ ./numconv 0b11111111111111111111111111111111 -o 10
4294967295
$ ./numconv -o 10 0x0000000B
11
$ ./numconv 0b123 -o 2
Bad input
$ ./numconv 213 -o 2 -o 16
0b11010101
0xd5
$ ./numconv 213 -o 2 -o 16 -o 10
0b11010101
213    
0xd5
  1. You must implement the base conversions yourself, without using C library printf("%d"), printf("%x"), scanf(), or atoi()
  2. You are give a Makefile which builds the executables numinfo and numconv. You need to implement numinfo.c and numconv.c
  3. The basic idea is to covert the input number as a string into a uint32_t type. Then covert the uint32_t version of the value to one or more output strings in the specified bases.

Given

We will review processing command line arguments in C

Pseudocode for uint32_t string_to_int(char *str)

init retval to 0
init placeval to 1 (anything to the 0 power is 1)
determine the base of the str by looking at first two chars
    `0b` means base is 2, `0x` means base is 16, otherwise base is 10
loop over str from the highest index down to 0
    calculate the integer corresponding to the character at that index	
    calculate the value of that place by multiplying the integer * placeval
    add the value to the retval
    update to placeval to placeval * base
return the return value

Pseudocode for void int_to_string(uint32_t value, char *str, int base)

init buffer to empty
while value != 0
    quot = value / base
    rem = value % base
    calculate the character value of rem
    append the character value to the buffer
    value = quot
copy buffer into str in reverse order

Rubric

50% Dev Env Setup 50% Points determined by Project01 autograder tests.

Extra Credit

(5 points) Demostrate you have a fully working local RISC-V Ubuntu VM setup on your laptop.