Fans of Raymond Chen's blog will have probably been pleased to see, as I was, that today he made one of his rare forays into assembly language programming (albeit via compiler intrinsics rather than a conventional assembler):
http://blogs.msdn.com/b/oldnewthing/archive/2014/12/01/10576992.aspx
I thought it might be of interest to list a BBC BASIC equivalent of the code he discusses:
Code: INSTALL @lib$+"ASMLIB2"
DIM xarray% 10000*4 + 15
xarray% = (xarray% + 15) AND -16 : REM align
FOR I% = 0 TO 9999
xarray%!(I%*4) = I%
NEXT
xboundary% = 4999
DIM P% 150, L% -1
ON ERROR LOCAL [OPT FN_asmext : ]
[OPT 10
.countthem
pxor xmm5,xmm5
pxor xmm6,xmm6
movd xmm7,[^xboundary%]
pshufd xmm7,xmm7,%00000000
mov ecx,9980
.loop
movdqu xmm0,xarray%[ecx*4] ; REM GETVALUE(0)
movdqu xmm1,xarray%[ecx*4+16] ; REM GETVALUE(1)
movdqu xmm2,xarray%[ecx*4+32] ; REM GETVALUE(2)
movdqu xmm3,xarray%[ecx*4+48] ; REM GETVALUE(3)
movdqu xmm4,xarray%[ecx*4+64] ; REM GETVALUE(4)
pcmpgtd xmm0,xmm7 ; REM GETTEST(0)
pcmpgtd xmm1,xmm7 ; REM GETTEST(1)
pcmpgtd xmm2,xmm7 ; REM GETTEST(2)
pcmpgtd xmm3,xmm7 ; REM GETTEST(3)
pcmpgtd xmm4,xmm7 ; REM GETTEST(4)
psubd xmm5,xmm0 ; REM GETCOUNT(0)
psubd xmm6,xmm1 ; REM GETCOUNT(1)
psubd xmm5,xmm2 ; REM GETCOUNT(2)
psubd xmm6,xmm3 ; REM GETCOUNT(3)
psubd xmm5,xmm4 ; REM GETCOUNT(4)
sub ecx,20
jns loop
paddd xmm5,xmm6
pshufd xmm6,xmm5,%10001110
paddd xmm5,xmm6
pshufd xmm6,xmm5,%10110001
paddd xmm5,xmm6
movd eax,xmm5
ret
]
RESTORE ERROR
PRINT "There were "; 10000-USR(countthem) ;
PRINT " values less than or equal to " ; xboundary%
To borrow Raymond's own phrase, the code above is a 'small program' and small programs don't bother with error checking or niceties such as moving code into procedures and functions. Also, the special requirements of ASMLIB (to allow the program to be compiled) have not been addressed.
Richard.