Have you ever wondered just how difficult it is to do division using nothing but NOT,AND,OR,XOR? Well, so do I. It turns out I also need ADD,SUB, and CMP. Also, Shift command. Still, these are easily within the domain of any assembly language programming.
- CLS
- A=RND(255):B=RND(15)
- ?A,B
- C=0:D=128:E=B*D
- FOR I=1 TO 8
- IF A-E>=0 THEN A=A-E:C=C+D
- ?A,B,C,D,E
- D=D/2:E=E/2
- NEXT I
- ?C,A
- FOR I=0 TO 8
- VSYNC 1:I=BTRIG():NEXT
- GOTO @DIV2
A contains the number to be divided. B contains the number that divides. This computes C=A/B and A=A%B. A pretty nifty code that fits single screen challenge. Notice, that you can also do it this way (untested) on line 6:
- A=A-E:IF A<0 THEN A=A+E ELSE C=C+D
This way, due to the calculation in Assembly language where the register holds the resulting value of the calculation.
No comments:
Post a Comment