Dec 112017
 
From Computer Language Magazine, FEB 1990.
File CLM90FEB.ZIP from The Programmer’s Corner in
Category Files from Magazines
From Computer Language Magazine, FEB 1990.
File Name File Size Zip Size Zip Type
BASIC.TXT 4540 1391 deflated
HEAP.DBG 22404 5721 deflated
INTERSIM.TXT 5655 2309 deflated
MUDD.ZIP 11237 9503 deflated

Download File CLM90FEB.ZIP Here

Contents of the BASIC.TXT file


===========================LISTING 1============================

;X% = ASC(MID$(Work$, Y%))
MOV AX,OFFSET WORK$ ;get the address for Work$
PUSH AX ;push that onto the stack
PUSH WORD PTR [Y%] ;push the value of Y%
MOV AX,7FFF ;load AX with 7FFFh (32767)
PUSH AX ;push that as well
CALL B$FMID ;call the BASIC MID$ routine
PUSH AX ;push the address MID$ returns
CALL B$FASC ;call the BASIC ASC routine
MOV WORD PTR X%, AX ;assign the value ASC returns

===========================LISTING 2============================

FOR X% = 1 TO 100
Y% = X%
NEXT

;FOR X% = 1 TO 100
B80100 MOV AX, 1 ;assign AX = 1 to initialize the loop
E90400 JMP 003A ;jump into NEXT at address 003A
;Y% = X%
0036:
A33600 MOV WORD PTR [Y%], AX ;assign Y% from AX ;NEXT
40 INC AX ;increment AX
003A:
A33800 MOV WORD PTR [X%], AX ;assign X% from AX
3D6400 CMP AX, 64 ;64 Hex = 100 Decimal
7EF4 JLE 0036 ;jump if less or equal

===========================LISTING 3============================

X% = 1
DO WHILE X% <= 100
Y% = X%
X% = X% + 1
LOOP

;X% = 1
C70636000100 MOV WORD PTR [X%], 1 ;assign X% = 1
;DO WHILE X% <= 100
0036:
833E360064 CMP WORD PTR [X%], 64 ;compare X% to 100
7E03 JLE 0040 ;jump if less/equ.
E90C00 JMP 004C ;else we're done
;Y% = X%
0040:
A13600 MOV AX, WORD PTR [X%] ;assign AX from X%
A33800 MOV WORD PTR [Y%], AX ;assign Y% from AX
;X% = X% + 1
FF063600 INC WORD PTR [X%] ;increment X%
EBEA JMP 0036 ;jump back in
004C:
;program continues

===========================LISTING 4============================

IF X% > 100 THEN
Y% = 2
ELSEIF Z% < 1 THEN
Y% = 3
ELSEIF X% < 0 THEN
Y% = 4
END IF


;IF X% > 100 THEN
833E360064 CMP WORD PTR [X%], 64 ;is X% > 100?
7F03 JG 003A ;yes, jump ahead
E90900 JMP 0043 ;no, keep checking
;Y% = 2
003A:
C70638000200 MOV WORD PTR[Y%], 2 ;assign Y% = 2
E92300 JMP 0066 ;done, jump out
;ELSEIF Z% < 1 THEN
0043:
833E3A0001 CMP WORD PTR [Z%], 1 ;is Z% < 1?
7C03 JL 004D ;yes, jump ahead
E90900 JMP 0056 ;no, keep checking
;Y% = 3
004D:
C70638000300 MOV WORD PTR [Y%], 3 ;assign Y% = 3
E91000 JMP 0066 ;done, jump out
;ELSEIF X% < 0 THEN
0056:
833E360000 CMP WORD PTR [X%], 0 ;is X% < 0?
7C03 JL 0060 ;yes, jump ahead
E90600 JMP 0066 ;no, bag out
;Y% = 4
0060:
C70638000400 MOV WORD PTR [Y%], 4 ;assign Y% = 4
;END IF
0066:
;program continues

===========================LISTING 5============================

;IF LEN(Work$) > X% + 14 THEN Z% = 1
MOV AX, WORD PTR [X%] ;put the value of X% into AX
ADD AX, 0E ;add 14 decimal (X% + 14)
MOV BX, AX ;save the result in BX
MOV AX, OFFSET Work$ ;get the address of Work$
PUSH AX ;push it for LEN below
MOV [BP-0C], BX ;save BX for a moment
CALL B$FLEN ;call BASIC's LEN routine
CMP AX, [BP-0C] ;compare LEN in AX to what we
; evaluated and saved earlier
JG 005F ;it is greater, jump to assign
JMP 0065 ;it's not greater, jump over
005F:
MOV WORD PTR [Z%], 1 ;assign Z% = 1
0065:
;program continues

===========================LISTING 6============================

Not recommended:

IF X% + 14 < 100 THEN 'BASIC evaluates X% + 14 here
Y% = 2
ELSEIF X% + 14 = 100 THEN 'and then again here
Y% = 3
ELSEIF X% + 14 > 100 THEN 'and again here too
Y% = 4
END IF

Much better:

SELECT CASE X% + 14 'BASIC evaluates X% + 14 once.
CASE < 100 'All of these tests are then
Y% = 2 ' performed on the results
CASE 100 ' of the first evaluation.
Y% = 3
CASE > 100
Y% = 4
END SELECT

SELECT CASE is therefore similar to:

Temp% = X% + 14
IF Temp% < 100 THEN
Y% = 2
ELSEIF Temp% = 100 THEN
.
.



 December 11, 2017  Add comments

Leave a Reply