Lab 4: Image Blurring
CMPUT 229 University of Alberta
Lab Requirements
¡ñ Function calls and register conventions
¡ñ Loading and storing from memory
¡ñ Loops and control flow
¡ñ Bit manipulation
Background
¡ñ Common technique to hide key
information
¡ñ Distort the detail of an image to make it less clear
Programming Help, Add QQ: 749389476
PPM format:
The Assignment
¡ñ digitToAscii ¡ñ copyImage ¡ñ asciiToDigit
¡ñ readNextNumber ¡ñ storeNumber
¡ñ pixelKernelMul ¡ñ blurImage
readNextNumber
asciiToDigit
pixelKernelMul
storeNumber
digitToAscii
Subroutines
digitToAscii:
This function returns the ASCII value of the digit.
Arguments:
a0: a single digit represented as an integer, between 0 and 9
a0: the ASCII value of the digit, between 48 (0x30) and 57 (0x39)
浙大学霸代写 加微信 cstutorcs
Subroutines
This function copies all the RGB values to another address.
Arguments:
a0: address of the start of RGB values (where to copy from) a1: address of the start of where to copy to
a2: length in words
Subroutines
asciiToDigit:
This function returns the digit for the given ASCII value
Arguments:
a0: the ASCII value of the digit, between 48 (0x30) and 57 (0x39)
a0: a single digit represented as an integer, between 0 and 9
Subroutines
readNextNumber:
It reads a string of ASCII characters and converts the first number it finds into an integer. It is guaranteed to only have ASCII numbers between 0 and 255. The function skips any whitespace before the number, then reads until it encounters a whitespace character including:”space” or “\n” or “\r” or “\t”
Arguments:
a0: the current address to start reading
a0: the address to start reading the next number a1: the number represented as an integer
Subroutines
storeNumber:
This function converts the integer(at most 3 digits) to ASCII and then store their ASCII to the address. Store the leftmost digit first, consider using the function digitToAscii.
Arguments:
a0: the number represented as an integer a1: address for the integer to be stored
a0: the next address that’s available to be stored
Subroutines
pixelKernelMul:
This function calculate the average for each of the R, G, B values and store the value.
Arguments:
a0: address of the start of RGB values, store the calculated RGB values in this region (a0 is the base address) a1: address of the start of the copy of RGB values
a2: row # of the current pixel to blur
a3: col # of the current pixel to blur
a4: total row (may not be used)
a5: total col
The pixels in memory:
Big-endian:
CS Help, Email: tutorcs@163.com
COoripgyin:al:
new[x][y] = average of all of the surrounding 49 elements
Subroutines
blurImage:
This function blurs the image using pixelKernelMul on all possible pixels. It will run PixelKernelMul on all pixels except for the ones on the edges and corners.
Arguments:
a0: kernel size
a1: total rows
a2: total columns
a3: address of the start of RGB values, store the calculated RGB values in this region (a0 is the base address) a4: address of the start of the copy of RGB values
Pseudo Code
Register Conventions in RISC-V
Register conventions are required for this lab. Review your notes on using the stack pointer and register conventions.
Tips and Notes
¡ñ Loops are a very important part of this lab. Review your notes.
¡ñ For the simplicity of this lab, we are only blurring the center part of the lab and
ignoring the edges and the corners.
¡ñ You can make any other helper functions to break down the problem.
¡ñ Read carefully about the instructions and examples provided.
¡ñ Do not edit any part of common.s
¡ñ Do not use any labels used in common.s