我一直试图设计一个表达式来检查MIPS指令,例如:
lw $t1 70000($s0)
我有lw
和$t1
部分的表达式,但我被卡在70000($s0)
部分。
($s0)
前的数字不能超过−32768
或32767
,$
必须只有一次,s
部分必须是s
或t
仅发生一次,之后的数字范围仅为0-7
的{{1}}和s
的{{1}}。
对此的任何帮助都将非常感激。
以下是我脚本另一部分0-9
部分的表达式:
t
我在if语句中使用它来检查输入的文本是否有效,它主要是我被卡住的前缀数字部分。
由于
EDIT1 :我已设法使用$s0
将值与^(\$((s?[0-7])|(t?([0-9]))))$
分开,以将字符串截断到第一个($s0)
之前。我的脚本不会在值之前处理offset=${w3%(*}
之类的任何内容。
我现在需要检查此值是否小于(
或大于(
。我对如何存档这个有任何想法吗?
EDIT2:我已经设法解决了我的问题,并将解决方案作为答案发布,感谢所有回复。
答案 0 :(得分:1)
df1 = df1.interpolate(method='nearest',axis=0)
我同意让正则表达式检测数值范围是浪费精力。以上内容捕获了偏移并按照您的描述进行了注册,并进行了一些修正和简化。
答案 1 :(得分:0)
好的,我已经成功解决了这个问题,方法如下:
offset1=${w3%(*} # retrive the offset of the instruction
if [[ ${offset1:0:1} == "-" ]]; then # if the first char is a - then,
offset1NoSign=${w3%(*} # get the offset number
offset1NoSign=${offset1NoSign##*-} # get rid of the -
echo " This should not have a - sign: $offset1NoSign"
fi
if [[ ( ${offset1:0:1} == "-" && $offset1NoSign -gt "32768" ) || ( $offset1 -gt "32767" ) ]]; then
echo "Out of bounds immediate. Immediates range between −32768 and 32767."
else
---- rest of code ----
它不是很漂亮但它有效。它首先使用offset1=${w3%(*}
截断字符串以获取(
之前的数字(例如。-500($s0)
将被截断为-55
)。
然后检查第一个字符是否为-
,如果是,则删除它:
if [[ ${offset1:0:1} == "-" ]]; then # if the first char is a - then,
offset1NoSign=${w3%(*} # get the offset number
offset1NoSign=${offset1NoSign##*-} # get rid of the -
#echo " This should not have a - sign: $offset1NoSign"
fi
接下来,检查它是否超过两个数字
if [[ ( ${offset1:0:1} == "-" && $offset1NoSign -gt "32768" ) || ( $offset1 -gt "32767" ) ]]; then
echo "Out of bounds immediate. Immediate range between −32768 and 32767."
else
检查第一个字符是-
,是否大于32768
,或者数字是否大于32767
。
指令的其余部分只使用正则表达式来检查它。