[quirks-uvm-devel] One more program
Status: Pre-Alpha
Brought to you by:
teodor
From: Bhavani M. <bha...@ya...> - 2002-04-01 15:31:48
|
Hi, I got the flex, bison and libraries. And regarding the CtoF program, I agree with your review points. I changed it and now it is compilable. I am compiling the *.ua with ua.exe. Is this correct? Please let me know. The corrected program is below: ------------------------------- --Procedure to convert temperature in Centigrade to Fahrenheit --Temperature in Fahrenheit = 18*C/10 + 32 -- fp[0] = starting C value = 0 -- fp[1] = Max C = 100 -- ct[0] = 18, ct[1] = 10 divide these two values to get 1.8, ct[2] = 32 which is from the formula procedure :CtoF is -- Make four 32 bit local registers. -- Each register is both writeable and readable. lv is <int32/inout int32/inout int32/inout int32/inout stu>; declare map auCmp is <int32/in int32/in int32/out stu>; map is (auCmp[0], lv[1]) (auCmp[1], fp[1]) (auCmp[2], lv[0]) end map; declare map -- Get access to two registers of incrementer/decrementer auInc is <int32/in int32/out stu>; -- Three ports of multiplier auMul is <int32/in int32/in int32/out stu>; au2Mul is <int32/out int32/in int32/in stu>; auSum is <int32/in int32/in int32/out stu>; map is (auInc[0], lv[1]) --Store value of C (auMul[0], ct[0]) (auMul[1], lv[1]) (auMul[2], lv[3]) -- calculate 18 * C (au2Mul[1],lv[3]) (au2Mul[2],ct[1]) (au2Mul[0], lv[2]) -- (18 * C )/10 (auSum[0], lv[2]) (auSum[1], ct[2]) (auSum[2], lv[2]) -- done with conversion of C to F (auInc[1], lv[1]) -- Increment C end map; begin lv[1] <- fp[0]; -- Initial value of C @Loop: loop * auCmp; exit @Loop when not lv[0]; * auSum; end loop; fp[2] <- lv[2]; end :CtoF; I have wriiten One more program for Roots of the equation. The program is below: roots.ua ----------------------------------------------------- --Procedure to calculate the roots of quadratic equation -- Find Descriminant = b*b - 4*a*c -- fp[0] = starting A value = 0 -- fp[1] = Max A = 100, fp[2] is value of Descriminant, output value of fp[3] is 1000 if Roots are Imaginary, fp[3] is 1001 if Roots are real and equal, -- fp[3] is 1002 if Roots are real and unequal. -- ct[0] = 8 value of B , ct[1] = 1 value of C , ct[2] = 4 , ct[3] = 0, ct[4] = 1000, ct[5]=1001, ct[6] = 1002 procedure :roots is -- Make six 32 bit local registers. -- Each register is both writeable and readable. lv is <int32/inout int32/inout int32/inout int32/inout int32/inout int32/inout stu>; declare map auCmp is <int32/in int32/in int32/out stu>; au2Cmp is <int32/in int32/out stu>; map is (auCmp[0], lv[1]) (auCmp[1], fp[1]) (auCmp[2], lv[0]) (auCmp[0], lv[2]) (auCmp[1], ct[3]) (auCmp[2], lv[4]) (au2Cmp[0], lv[5]) (au2Cmp[1], ct[3]) end map; declare map -- Get access to two registers of incrementer/decrementer auInc is <int32/in int32/out stu>; -- Three ports of multiplier auMul is <int32/in int32/in int32/out stu>; -- Three ports of adder auSum is <int32/out int32/in int32/in stu>; map is (auMul[0], ct[0]) (auMul[1], ct[0]) (auMul[2], lv[2]) -- calculate b*b (auMul[0], lv[1]) (auMul[1], ct[1]) (auMul[2], lv[3]) -- calculate a*c (auMul[0], lv[3]) (auMul[1], ct[2]) (auMul[2], lv[3]) -- calculate 4*a*c (auSum[1], lv[2]) (auSum[2], lv[3]) (auSum[0], lv[2]) -- b*b - 4*a*c end map; begin lv[1] <- fp[0]; -- value of A @Loop: loop * auCmp; exit @Loop when not lv[0]; * auMul; * auSum; lv[5] <- lv[2]; * auCmp; if lv[4] then fp[3] <- ct[4]; endif; if not lv[4] then fp[3] <- ct[6]; endif; * au2Cmp; if lv[5] then fp[3] <- ct[5]; endif; end loop; fp[2] <- lv[2]; -- Descriminant end :roots; roots.efg ------------------------------------------------------- ct: <int32/in int32/in int32/in int32/in int32/in int32/in int32/in stu> 8 1 4 0 1000 1001 1002 roots.uvmd ------------------------------------------------------- load "roots.ru" load environment "roots.efg" select module 1 select environment 1 set fp = <int32/inout int32/inout int32/inout int32/inout stu> fp[0] = 0 fp[1] = 100 make instance of :roots ;show #roots run #roots print fp[2] print fp[3] quit --- bhavani __________________________________________________ Do You Yahoo!? Yahoo! Greetings - send holiday greetings for Easter, Passover http://greetings.yahoo.com/ |