Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
79
Task/Bitwise-operations/Tiny-BASIC/bitwise-operations.basic
Normal file
79
Task/Bitwise-operations/Tiny-BASIC/bitwise-operations.basic
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
REM VARIABLES
|
||||
REM A = first number
|
||||
REM B = second number
|
||||
REM C = result
|
||||
REM P = current bit position
|
||||
REM U = number of on bits at position P, or carry flag for rotate ops
|
||||
REM Z = logic gate selection, then target number of on bits
|
||||
|
||||
10 LET P = 16384
|
||||
LET F = 0
|
||||
PRINT "1. A and B"
|
||||
PRINT "2. A or B"
|
||||
PRINT "3. A xor B"
|
||||
PRINT "4. not A"
|
||||
PRINT "5. A shr B"
|
||||
PRINT "6. A shl B"
|
||||
PRINT "7. A ror B"
|
||||
PRINT "8. A rol B"
|
||||
PRINT "Select a bitwise operation."
|
||||
INPUT Z
|
||||
IF Z < 1 THEN GOTO 10
|
||||
IF Z > 8 THEN GOTO 10
|
||||
11 PRINT "What is A? "
|
||||
INPUT A
|
||||
IF A < 0 THEN GOTO 11
|
||||
IF Z = 4 THEN GOTO 15
|
||||
12 PRINT "What is B?"
|
||||
INPUT B
|
||||
IF B < 0 THEN GOTO 12
|
||||
15 GOSUB 100 + 10*Z
|
||||
PRINT "The result is ", C,"."
|
||||
END
|
||||
110 LET Z = 2
|
||||
GOSUB 500
|
||||
RETURN
|
||||
120 LET Z = 0
|
||||
GOSUB 500
|
||||
LET A = C
|
||||
GOSUB 140
|
||||
RETURN
|
||||
130 LET Z = 1
|
||||
GOSUB 500
|
||||
LET A = C
|
||||
GOSUB 140
|
||||
RETURN
|
||||
140 LET C = 32767 - A
|
||||
RETURN
|
||||
150 IF B = 0 THEN RETURN
|
||||
LET A = A / 2
|
||||
LET B = B - 1
|
||||
GOTO 150
|
||||
160 IF B = 0 THEN RETURN
|
||||
IF A > P THEN LET A = A - P
|
||||
LET A = A * 2
|
||||
LET B = B - 1
|
||||
GOTO 160
|
||||
170 IF B = 0 THEN RETURN
|
||||
LET U = 0
|
||||
IF 2*(A/2) <> A THEN LET U = 1
|
||||
LET A = A / 2 + U*P
|
||||
LET B = B - 1
|
||||
LET C = A
|
||||
GOTO 170
|
||||
180 IF B = 0 THEN RETURN
|
||||
LET U = 0
|
||||
IF A >= P THEN LET U = 1
|
||||
LET A = (A-F*P)*2 + U
|
||||
LET B = B - 1
|
||||
LET C = A
|
||||
GOTO 180
|
||||
500 LET U = 0
|
||||
IF B >= P THEN LET U = 1
|
||||
IF A >= P THEN LET U = U + 1
|
||||
IF U = Z THEN LET C = C + P
|
||||
IF A >= P THEN LET A = A - P
|
||||
IF B >= P THEN LET B = B - P
|
||||
LET P = P / 2
|
||||
IF P = 0 THEN RETURN
|
||||
GOTO 500
|
||||
Loading…
Add table
Add a link
Reference in a new issue