BBC BASIC
Programming >> Assembly Language >> Increment of a value in assembler?
http://bbcbasic.conforums.com/index.cgi?board=assembly&action=display&num=1462859858

Increment of a value in assembler?
Post by michaelgallup on May 10th, 2016, 05:57am

I am trying to learn how this works.
Actually this should go faster if I can send the increased information to the start variable value within the assembler.
I need to find out how to loop within the assembler, but what if I only increment a certain amount for each assembler use? I am doing something wrong I am sure..
Code:
      DIM bin% 3, bcd% 9      PRINT "Please wait for increment to 2 million"      PROCassemble      !bin%=1000      REPEAT        CALL bin2bcd        !bin%=!bcd%      UNTIL !bcd%=2000000      PRINT "DONE"      END      DEF PROCassemble      LOCAL P%, L%      DIM P% 12, L% -1      [OPT 10      .bin2bcd      mov eax,[bin%]      inc eax      mov [bcd%],eax      ret      ]      ENDPROC 

Profiler report file - Mon.09 May 2016,23:54:42

File - Digits.BBC

Figures in the first column indicate approximate
time in milliseconds spent in each program line.

Figures in the second column indicate approximate
percentage of the total time spent in each program line.

Initial timeout setting : 1000 milliseconds.

Time spent Profiling : 1000 milliseconds.

0: DIM bin% 3, bcd% 9
2: 0.20 PRINT "Please wait for increment to 2 million"
0: PROCassemble
0: !bin%=1000
0: REPEAT
121: 12.10 CALL bin2bcd
842: 84.20 !bin%=!bcd%
35: 3.50 UNTIL !bcd%=2000000
0: PRINT "DONE"
0: END
0:
0: DEF PROCassemble
0: LOCAL P%, L%
0: DIM P% 12, L% -1
0: [OPT 10
0: .bin2bcd
0: mov eax,[bin%]
0: inc eax
0: mov [bcd%],eax
0: ret
0: ]
0: ENDPROC

Re: Increment of a value in assembler?
Post by Richard Russell on May 10th, 2016, 07:05am

An alternative is for the assembler code to act on ordinary BASIC variables like this:

Code:
      PRINT "Please wait for increment to 2 million"      PROCassemble      bin%=1000      REPEAT        CALL bin2bcd        bin%=bcd%      UNTIL bcd%=2000000      PRINT "DONE"      END      DEF PROCassemble      LOCAL P%, L%      DIM P% 12, L% -1      [OPT 10      .bin2bcd      mov eax,[^bin%]      inc eax      mov [^bcd%],eax      ret      ]      ENDPROC 

The difference is a subtle one, but I think there is some benefit, especially for a beginner, in not needing to reserve memory for the 'variables' or to use 'indirection' in the BASIC code.

Richard.

Re: Increment of a value in assembler?
Post by michaelgallup on May 10th, 2016, 08:27am

Thanks Richard !! And now I found a way to make it even faster !! I beat the profiler by 184 milliseconds !! That's speed!
But it appears to be almost 2 times slower than the hexdecimal example
and many times slower than the fastest program in the later posts after I posted it.
I think the only way to increase the speed is if I was able to loop within the assembly as it is being added to.

Oh well, it was something to experiment with.
Code:
      PRINT "Please wait for increment to 2 million"      PROCassemble      bin%=1000      REPEAT        CALL bin2bcd      UNTIL bin%=2000000      PRINT "DONE"      END      DEF PROCassemble      LOCAL P%, L%      DIM P% 12, L% -1      [OPT 10      .bin2bcd      mov eax,[^bin%]      inc eax      mov [^bin%],eax      ret      ]      ENDPROC 

Profiler report file - Tue.10 May 2016,02:24:51

File - Digits.BBC

Figures in the first column indicate approximate
time in milliseconds spent in each program line.

Figures in the second column indicate approximate
percentage of the total time spent in each program line.

Initial timeout setting : 1000 milliseconds.

Time spent Profiling : 816 milliseconds.

1: 0.12 PRINT "Please wait for increment to 2 million"
0: PROCassemble
0: bin%=1000
2: 0.25 REPEAT
404: 49.51 CALL bin2bcd
409: 50.12 UNTIL bin%=2000000
0: PRINT "DONE"
0: END
0: DEF PROCassemble
0: LOCAL P%, L%
0: DIM P% 12, L% -1
0: [OPT 10
0: .bin2bcd
0: mov eax,[^bin%]
0: inc eax
0: mov [^bin%],eax
0: ret
0: ]
0: ENDPROC

0: Libraries and immediate mode