+################################################################################
+# div_test #
+################################################################################
+
+def div_test(a, b)
+ begin
+ line = $sp.gets()
+ line = "" if line==nil
+ puts("DBG got: "+line) if $debug
+ if /^Error:.*/.match(line)
+ puts line
+ return false
+ end
+ end while ! /[\s]*enter a:[\s]*/.match(line)
+ $sp.print(a.to_s(16) + " ")
+ begin
+ line = $sp.gets()
+ line = "" if line == nil
+ puts("DBG got: " + line) if $debug
+ if /^Error:.*/.match(line)
+ puts line
+ return false
+ end
+ end while ! /[\s]*enter b:[\s]*/.match(line)
+ $sp.print(b.to_s(16) + " ")
+ line = ''
+ begin
+ line_tmp = $sp.gets()
+ line_tmp = '' if line_tmp == nil
+ line += line_tmp
+ puts("DBG got: " + line) if $debug
+ if /^Error:.*/.match(line)
+ puts line
+ return false
+ end
+ end while ! m=/[\s]*([+-]?[0-9a-fA-F]*)[\s]+\/[\s]+([+-]?[0-9a-fA-F]*)[\s]*=[\s]*([+-]?[0-9a-fA-F]+);[\s]*R[\s]*=[\s]*([+-]?[0-9a-fA-F]+)/.match(line)
+ a_ = m[1].to_i(16)
+ b_ = m[2].to_i(16)
+ c_ = m[3].to_i(16)
+ d_ = m[4].to_i(16)
+ line.strip!
+ if (a_== a && b_ == b && c_ == (a / b) && d_ == (a % b))
+ $logfile.printf("[pass (%d)]: %s\n", $testno, line)
+ return true
+ else
+ $logfile.printf("[fail (%s%s%s%s) (%d)]: %s",
+ (a == a_) ? "" : "a",
+ (b == b_) ? "" : "b",
+ (c_ == a / b) ? "" : "c",
+ (d_ == a % b) ? "" : "d", $testno, line)
+ $logfile.printf(" ; should %s %% %s = %s; R = %s\n", a.to_s(16), b.to_s(16), (a / b).to_s(16), (a % b).to_s(16))
+ return false
+ end
+ return false
+end
+