News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Converting BASIC program to HLA?

Started by Paul Panks, August 10, 2005, 10:16:00 PM

Previous topic - Next topic

Paul Panks

I'm trying to convert the following QBASIC program to HLA. It takes a string of text that the user inputs and converts into into the Numerica Format (which I developed in April of 2004). Here's the BASIC source code:

5 dim a$(55):dim b$(55)
100 for x=1 to 50:read a$(x):read b$(x):next x
105 print"numerica format":print
106 print"enter a sentence to convert to numerica format:":print
110 line input ry$:ry$=lcase$(ry$)
115 print:print"working..."
120 print
125 c$="":for x=1 to len(ry$):for y=1 to 50:if mid$(ry$,x,1)=a$(y) then c$=c$+b$(y)
130 next:next
135 print:print"in numerica format:":print
140 print c$
145 print
146 rem input"convert back (y/n)";ry$
147 rem if ry$="y" or ry$="Y" then goto 160
149 rem print
150 input"another (y/n)";ry$
151 if ry$="y" or ry$="Y" then run
152 end
160 rem print
161 rem print "converting back...":print
162 rem d$="":for x=1 to len(c$):for y=1 to 50:if mid$(c$,x,1)=b$(y) then d$=d$+a$(y)
163 rem next:next
164 rem print d$
165 rem print:goto 150
1000 rem numerica format
1001 data"a","01","b","02","c","03","d","04","e","05"
1002 data"f","06","g","07","h","08","i","09","j","52"
1003 data"k","56","l","62","m","67","n","72","o","53"
1004 data"p","82","q","89","r","92","s","19","t","54"
1005 data"u","73","v","22","w","23","x","64","y","55"
1006 data"z","26",".","93","!","74","?","29",",","65"
1007 data"&","31"," ","84","*","33","@","34","%","75"
1008 data"$","94","+","37","-","38","#","39","0","40"
1009 data"1","41","2","42","3","43","4","44","5","45"
1010 data"6","46","7","47","8","48","9","49","'","50"

For a description of the Numerica Format, please click below:

http://members.tripod.com/~panks/numerica.html

Sincerely,

Paul Panks
dunric@yahoo.com

Paul Panks

Here's an updated version of the program which converts to and from Numerica Format:

5 dim a$(55):dim b$(55)
100 for x=1 to 50:read a$(x):read b$(x):next x
105 print"numerica format":print
106 print"enter a sentence to convert to numerica format:":print
110 line input ry$:ry$=lcase$(ry$)
115 print:print"working..."
120 print
125 c$="":for x=1 to len(ry$):for y=1 to 50:if mid$(ry$,x,1)=a$(y) then c$=c$+b$(y)
130 next:next
135 print:print"in numerica format:":print
140 print c$
145 print
146 input"convert back (y/n)";ry$
147 if ry$="y" or ry$="Y" then goto 160
149 print
150 input"another (y/n)";ry$
151 if ry$="y" or ry$="Y" then run
152 end
160 print
161 print "converting back...":print
162 d$="":for x=1 to len(c$) step 2:for y=1 to 50:if mid$(c$,x,2)=b$(y) then d$=d$+a$(y)
163 next:next
164 print d$
165 print:goto 150
1000 rem numerica format
1001 data"a","01","b","02","c","03","d","04","e","05"
1002 data"f","06","g","07","h","08","i","09","j","52"
1003 data"k","56","l","62","m","67","n","72","o","53"
1004 data"p","82","q","89","r","92","s","19","t","54"
1005 data"u","73","v","22","w","23","x","64","y","55"
1006 data"z","26",".","93","!","74","?","29",",","65"
1007 data"&","31"," ","84","*","33","@","34","%","75"
1008 data"$","94","+","37","-","38","#","39","0","40"
1009 data"1","41","2","42","3","43","4","44","5","45"
1010 data"6","46","7","47","8","48","9","49","'","50"

Paul

Randall Hyde

Quote from: Paul Panks on August 11, 2005, 01:32:06 AM
Here's an updated version of the program which converts to and from Numerica Format:

5 dim a$(55):dim b$(55)
100 for x=1 to 50:read a$(x):read b$(x):next x
105 print"numerica format":print
106 print"enter a sentence to convert to numerica format:":print
110 line input ry$:ry$=lcase$(ry$)
115 print:print"working..."
120 print
125 c$="":for x=1 to len(ry$):for y=1 to 50:if mid$(ry$,x,1)=a$(y) then c$=c$+b$(y)
130 next:next
135 print:print"in numerica format:":print
140 print c$
145 print
146 input"convert back (y/n)";ry$
147 if ry$="y" or ry$="Y" then goto 160
149 print
150 input"another (y/n)";ry$
151 if ry$="y" or ry$="Y" then run
152 end
160 print
161 print "converting back...":print
162 d$="":for x=1 to len(c$) step 2:for y=1 to 50:if mid$(c$,x,2)=b$(y) then d$=d$+a$(y)
163 next:next
164 print d$
165 print:goto 150
1000 rem numerica format
1001 data"a","01","b","02","c","03","d","04","e","05"
1002 data"f","06","g","07","h","08","i","09","j","52"
1003 data"k","56","l","62","m","67","n","72","o","53"
1004 data"p","82","q","89","r","92","s","19","t","54"
1005 data"u","73","v","22","w","23","x","64","y","55"
1006 data"z","26",".","93","!","74","?","29",",","65"
1007 data"&","31"," ","84","*","33","@","34","%","75"
1008 data"$","94","+","37","-","38","#","39","0","40"
1009 data"1","41","2","42","3","43","4","44","5","45"
1010 data"6","46","7","47","8","48","9","49","'","50"

Paul

some useful tools:


type
   ne:record
       a:string;
       b:string;
  endrecord;

readonly
   numTable:ne[55] :=
  [
    ne:["a","01"],
    ne["b", "02"],
     etc.
    ne["'", "50"]
];

This gives you your data tables (A$ and B$ in the BASIC program).

You can use addressing modes like "numTable[edx*8].a" and "numTable[edx*8].b" to access the two fields of these array elements. Everything else should be a straight-forward conversion (assuming you're familiar with the HLA stdlib string functions).
Cheers,
Randy Hyde