Question: We were given this example and expected to know how to impliment the functions below: For this assignment, you'll implement five C functions to perform
We were given this example and expected to know how to impliment the functions below:
For this assignment, you'll implement five C functions to perform different kinds of accesses to a block of memory. Be
sure to pay attention to the restrictions that are imposed on your implementation. In particular, each function is restricted to
using pointer notation to manage all accesses to the data; use of array bracket notation will result in a score of 0.
The first function you will implement is functionally equivalent to the example function:
/** Uses array
- based logic to access a specified portion of a region of
*memory and print the corresponding bytes to a supplied file stream.
*
* Pre: Out is open on a file
* Base[0] is the first byte of the memory region to be examined
* Index is the index of the first relevant byte of the memory region
* nToPrint is the number of bytes to be printed
* Restrictions:
* You may not use any pointer syntax in accessing the data.
*/
void showBytesAtIndex (FILE* Out, const uint8_t Base[], uint16_t Index, uint8_t nToPrint) {
for (uint8_t pos = 0; pos < nToPrint; pos++) {
fprintf(Out, "%02X ", Base[Index + pos]);
}
fprintf(Out, " ");
}
Need some help with these functions:
#include "PtrStuff.h" // Add include directives here, as needed /** Uses pointer-based logic to access a specified portion of a region of * memory and prints the corresponding bytes to a supplied file stream. * * Pre: Out is open on a file * baseAddr points to the first byte of the memory region * Offset is the location, relative to baseAddr, of the first * relevant byte of the memory region * nToPrint is the number of bytes to be printed */ void showBytesAtOffset(FILE* Out, const uint8_t* const baseAddr, uint16_t Offset, uint8_t nBytes) { fprintf(Out, " "); } /** Uses pointer-based logic to display a specified portion of a region of * memory, using pointer typecasts to control the number of bytes that are * displayed, and the way those byte are interpreted. * * Pre: Out is open on a file * baseAddr points to the first byte of the memory region * Offset is the location, relative to baseAddr, of the first * relevant byte of the memory region * Sign indicates whether the bytes are to be interpreted as representing a * signed or unsigned integer * * nByte is the number of bytes to be considered. You may assume nByte * will be 1, 2, 4, or 8, corresponding to the sizes of the integer * types in . * * Restrictions: * You must use only pointer syntax in accessing the data. */ void showValueAtOffset(FILE* Out, const uint8_t* const baseAddr, uint32_t Offset, Sign Sgn, uint8_t nBytes) { fprintf(Out, " "); } /** Uses pointer-based logic to search a specified portion of a region of * memory for occurrences of a specified one-byte value. * * Pre: Out is open on a file * baseAddr points to the first byte of the memory region * Length is number of bytes in the memory region * Byte is the value to be found * Restrictions: * You must use only pointer syntax in accessing the data. */ void findOccurrencesOfByte(FILE* Out, const uint8_t* const baseAddr, uint32_t Length, uint8_t Byte) { fprintf(Out, " "); } /** Uses pointer-based logic to copy a specified portion of a region of * memory to replace the bytes in another portion of that memory region. * * Pre: Out is open on a file * baseAddr points to the first byte of the memory region * Source and Destination point to the first bytes of two sections * of the memory region that contains Length bytes * The regions pointed to by Source and Destination do not overlap * Post: Length bytes, beginning at *Source, have been copied to Length * consecutive locations, beginning at *Destination * Restrictions: * You must use only pointer syntax in accessing the data. */ void copyBlock(FILE* Out, const uint8_t* const baseAddr, uint32_t Source, uint32_t Destination, uint32_t Length) { fprintf(Out, " "); } /** Uses pointer-based logic to modify the contents of a specified portion * of a region of memory, by bitwise blending with bytes of another * portion of that memory region. * * Pre: Out is open on a file * baseAddr points to the first byte of the memory region * First and Second point to the first bytes of two sections * of the memory region that each contain Length bytes * The regions pointed to by First and Second do not overlap * Post: Length bytes, beginning at *Second, have been blended with Length * bytes, beginning at *First; the blending is accomplished as * follows: the k-th byte of *Second is modified by XORing its * hi nybble with the low nybble of the k-th byte from *First, * and its low nybble with the hi nybble of the k-th byte from * *First. * Restrictions: * You must use only pointer syntax in accessing the data. */ void blendBytes(FILE* Out, const uint8_t* const First, uint8_t* const Second, uint32_t Length) { fprintf(Out, " "); } HEADER:
#ifndef PTRSTUFF_H #define PTRSTUFF_H #include #include /** Uses pointer-based logic to access a specified portion of a region of * memory and prints the corresponding bytes to a supplied file stream. * * Pre: Out is open on a file * baseAddr points to the first byte of the memory region * Offset is the location, relative to baseAddr, of the first * relevant byte of the memory region * nToPrint is the number of bytes to be printed */ void showBytesAtOffset(FILE* Out, const uint8_t* const baseAddr, uint16_t Offset, uint8_t nBytes); /** Enumerated type used in interface of showValue() */ enum _Sign {SIGNED, UNSIGNED}; typedef enum _Sign Sign; /** Uses pointer-based logic to display a specified portion of a region of * memory, using pointer typecasts to control the number of bytes that are * displayed, and the way those byte are interpreted. * * Pre: Out is open on a file * baseAddr points to the first byte of the memory region * Offset is the location, relative to baseAddr, of the first * relevant byte of the memory region * Sign indicates whether the bytes are to be interpreted as representing a * signed or unsigned integer * nByte is the number of bytes to be considered. You may assume nByte * will be 1, 2, 4, or 8, corresponding to the sizes of the integer * types in . * * Restrictions: * You must use only pointer syntax in accessing the data. */ void showValueAtOffset(FILE* Out, const uint8_t* const baseAddr, uint32_t Offset, Sign Sgn, uint8_t nBytes); /** Uses pointer-based logic to search a specified portion of a region of * memory for occurrences of a specified one-byte value. * * Pre: Out is open on a file * baseAddr points to the first byte of the memory region * Length is number of bytes in the memory region * Byte is the value to be found * Restrictions: * You must use only pointer syntax in accessing the data. */ void findOccurrencesOfByte(FILE* Out, const uint8_t* const baseAddr, uint32_t Length, uint8_t Byte); /** Uses pointer-based logic to copy a specified portion of a region of * memory to replace the bytes in another portion of that memory region. * * Pre: Out is open on a file * baseAddr points to the first byte of the memory region * Source and Destination point to the first bytes of two sections * of the memory region that contains Length bytes * The regions pointed to by Source and Destination do not overlap * Post: Length bytes, beginning at *Source, have been copied to Length * consecutive locations, beginning at *Destination * Restrictions: * You must use only pointer syntax in accessing the data. */ void copyBlock(FILE* Out, const uint8_t* const baseAddr, uint32_t Source, uint32_t Destination, uint32_t Length); /** Uses pointer-based logic to modify the contents of a specified portion * of a region of memory, by bitwise blending with bytes of another * portion of that memory region. * * Pre: Out is open on a file * baseAddr points to the first byte of the memory region * First and Second point to the first bytes of two sections * of the memory region that each contain Length bytes * The regions pointed to by First and Second do not overlap * Post: Length bytes, beginning at *Second, have been blended with Length * bytes, beginning at *First; the blending is accomplished as * follows: the k-th byte of *Second is modified by XORing its * hi nybble with the low nybble of the k-th byte from *First, * and its low nybble with the hi nybble of the k-th byte from * *First. * Restrictions: * You must use only pointer syntax in accessing the data. */ void blendBytes(FILE* Out, const uint8_t* const First, uint8_t* const Second, uint32_t Length); #endif Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
