I am getting a situation with $sscanf() where it parses the first value correctly, however the second value does not correctly capture. The code snippet are included below up to the $sscanf() call:
task automatic do_axi_mst_w (
input cmd_generic_t cmd,
ref mailbox axi_mst_mb,
input integer loud = 0
);
logic [31:0] addr;
logic [31:0] data;
axi_mst_trx_t axi_transaction;
static integer trx_count = 1;
// Parse the command string for the address and data. If valid, post the
// transaction and wait for response.
if ($sscanf(cmd.arg_str, "%x %x", addr, data)) begin
if (loud) tb_msg($sformatf("%m : AXI Write %0d: Addr: %h Data: %h", trx_count, addr, data));
The value of cmd.arg_str is 0xa0000004 0x1
(obtained from prior print statement, and also from code variable inspection in simulation.) After $sscanf(), the value of addr is 32’ha000_0004
. After $sscanf(), the value of data is 32’h0000_00x1
.
The LRM does say that %h%x can accept values including X and x, and it seems like in this instance, it’s reading x
as undefined, rather than the prefix 0x
. Oddly enough, it did it correctly in the first argument!
I suspect it might be since the variable is specified as logic [31:0]
$sscanf() is anticipating more characters to fill the variable, thus it’s reading the 0x as a 0 and an undefined in its attempt to match string to value.
Is this correct? Is there any way to $sscanf() for hex values shorter than the full logic width, properly accepting the 0x prefix?