The firmware kit prints hex only, because the core has no divide instruction. Write the decimal printer that a log line needs, and print a number the bench chooses.
Hardware context: The console channel of ap_soc v1.5 against the UART0 path to pad IO0. A decimal printer for log lines.
A log line in hex is cheap for the core and hard for people. A regression report wants decimal. Write put_dec(n): print the unsigned number n in decimal with no leading zeros, through tb_putc.
main reads n from TB_ARG and prints value, n, half , n / 2 and a new line, each number in decimal. So TB_ARG = 1234 prints value 1234 half 617.
Full specification
ap_rv32 has no divide instruction (RV32I, no M extension). In C, n / 10 and n % 10 become calls to the kit's shift-and-subtract helpers __udivsi3 and __umodsi3. They work, and they cost cycles: the lesson measures them.
There is no printf and no C library. tb_putc writes one character to TB_PUTC.
Given Files
Read-only files supplied by the bench.
tb.h
#ifndef AP_TB_H
#define AP_TB_H
_Noreturn void tb_pass(void);
_Noreturn void tb_fail(unsigned code);
void tb_putc(char byte);
void tb_puts(const char *text);
void tb_put_hex(unsigned value);
void tb_event(unsigned id);
/* Slot zero is the single bench-to-firmware argument word. */
unsigned tb_arg(unsigned n);
void tb_wait_event(unsigned id);
#endif
hal.h
#ifndef AP_HAL_H
#define AP_HAL_H
#include "ap_soc_regs.h"
/* V13.4 supplies these two functions through DPI in a host-native build. */
#ifdef AP_HOST_DPI
unsigned reg_read32(unsigned address);
void reg_write32(unsigned address, unsigned value);
#else
static inline unsigned reg_read32(unsigned address)
{
return *(volatile unsigned *)address;
}
static inline void reg_write32(unsigned address, unsigned value)
{
*(volatile unsigned *)address = value;
}
#endif
#define FIELD_GET(field, word) (((word) & field##_MASK) >> field##_SHIFT)
#define FIELD_PREP(field, value) (((unsigned)(value) << field##_SHIFT) & field##_MASK)
#endif
Examples
Example 1
n = 1234- Input
n = 1234
- Output
value 1234 half 617
1234 / 2 is 617.
Example 2
n = 0- Input
n = 0
- Output
value 0 half 0
Zero prints one digit.
Example 3
The Largest Number- Input
n = 4,294,967,295
- Output
value 4294967295 half 2147483647
Ten digits, unsigned.
Constraints and Contract
- C firmware with the kit, SRAM layout.
- Print only through the kit: tb_putc, tb_puts.
- The console is compared exactly for many values of n, from 0 to 4,294,967,295.
Hints
Hint 1
n % 10 is the last digit. Which order do the digits come out in?
Hint 2
How many digits does the largest unsigned number have?
Hint 3
What must the loop do for n = 0?
What the grader checks: Each case writes n into TB_ARG and compares the console line exactly. It does not count cycles.
9 checks on ap_soc v1.5 · firmware · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain your text only; the chip, the bench and the hidden checks stay on the server. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 2 problems on this path