K
Kenneth Brun Nielsen
Guest
Is it possible to specify whether a given numeric string should be
interpreted as, say binary or hex type, by $sscanf?
E.g.
readLine = a register containing a string read from file.
if ($sscanf(readLine, "I2CWRITE %s %h", addrName, hexValue) == 2)
begin
// lookup addrName and
// write the hexadecimal sequence to the given address
end
else if ($sscanf(readLine, "I2CWRITE %s %b", addrName, binValue) == 2)
begin
// lookup addrName and
// write the binary sequence to the given address
end
else
$display( "Unknown command");
If readLine is the string "I2CWRITE TESTENABLE 01", $sscanf will
interpret "01" as both binary and hex. Does any syntax exist to
specify what type a given numeric value are of? For instance, if I
could write:
"I2CWRITE TESTENABLE 01b" in order to specify that the numeric value
01 should be interpreted as binary.
Obviously I could invent my own syntax and include it in the $sscanf
format line a'la
if ($sscanf(readLine, "I2CWRITE %s HEX %h", addrName, hexValue) == 2)
//
else if ($sscanf(readLine, "I2CWRITE %s BIN %b", addrName, binValue)
== 2)
, but:
1) I prefer a syntax without whitespaces (so the numeric value has
either a suffix or prefix)
2) I'd rather follow a predefined syntax, if it is already possible in
the $sscanf format.
Best regards,
Kenneth
interpreted as, say binary or hex type, by $sscanf?
E.g.
readLine = a register containing a string read from file.
if ($sscanf(readLine, "I2CWRITE %s %h", addrName, hexValue) == 2)
begin
// lookup addrName and
// write the hexadecimal sequence to the given address
end
else if ($sscanf(readLine, "I2CWRITE %s %b", addrName, binValue) == 2)
begin
// lookup addrName and
// write the binary sequence to the given address
end
else
$display( "Unknown command");
If readLine is the string "I2CWRITE TESTENABLE 01", $sscanf will
interpret "01" as both binary and hex. Does any syntax exist to
specify what type a given numeric value are of? For instance, if I
could write:
"I2CWRITE TESTENABLE 01b" in order to specify that the numeric value
01 should be interpreted as binary.
Obviously I could invent my own syntax and include it in the $sscanf
format line a'la
if ($sscanf(readLine, "I2CWRITE %s HEX %h", addrName, hexValue) == 2)
//
else if ($sscanf(readLine, "I2CWRITE %s BIN %b", addrName, binValue)
== 2)
, but:
1) I prefer a syntax without whitespaces (so the numeric value has
either a suffix or prefix)
2) I'd rather follow a predefined syntax, if it is already possible in
the $sscanf format.
Best regards,
Kenneth