Defines interface of printnum.c functions (do not modify)
More...
Go to the source code of this file.
|
char | getDigit (int val) |
|
void | divRem (int numerator, int divisor, int *quotient, int *remainder) |
|
void | printNum (int x, int base) |
|
This file defines the interface to a C file printnum.c that you will complete. You will learn how to use the C language operators for address-of (&), and dereferencing pointers *). This will serve as a model when you implement the same functions in LC3 assembly language.
◆ divRem()
void divRem |
( |
int |
numerator, |
|
|
int |
divisor, |
|
|
int * |
quotient, |
|
|
int * |
remainder |
|
) |
| |
Calculate both the quotient and remainder of a division and return the values via pointers. You may use the C operators for division (/) and modulus (%). However, you might want to write a loop to using repeated subtraction do the calculations to help you understand how you will implement this in LC3 assembly language (which has no operators for division or modulus).
- Parameters
-
numerator | - non-negative value for numerator |
divisor | - a positive value to divide by |
quotient | - a pointer to the location to store the result of division |
remainder | - a pointer to the location to store the remainder |
- Todo:
- Implement based on documentation contained in printnum.h
◆ getDigit()
Return the character corresponding to the digit. Use val
as an index into the string digits
- Parameters
-
val | - a value in the range of 0 - (base-1) |
- Returns
- - character '0' .. '9' or 'A'..'Z'
- Todo:
- Implement based on documentation contained in printnum.h
◆ printNum()
void printNum |
( |
int |
x, |
|
|
int |
base |
|
) |
| |
Print a number in the specified base. Use the C call putchar()
to print a single character obtained using getDigit()
. This corresponds to the OUT
instruction of the LC3 OS. You may not use any other C I/O routine for printing. This function MUST be implemented recursively.
- Parameters
-
x | - the number to print |
base | - the base in which the number should be printed |
- Todo:
- Implement based on documentation contained in printnum.h
◆ digits
A string of characters representing the digits to output for a particular value. Defined in the file testPrint.c
.