Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
8
Task/Reverse-a-string/FBSL/reverse-a-string-1.fbsl
Normal file
8
Task/Reverse-a-string/FBSL/reverse-a-string-1.fbsl
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
Function StrRev1(ByVal $p1)
|
||||
dim $b = ""
|
||||
REPEAT len(p1)
|
||||
b = b & RIGHT(p1,1)
|
||||
p1 = LEFT(p1,LEN(p1)-1)
|
||||
END REPEAT
|
||||
return b
|
||||
End Function
|
||||
7
Task/Reverse-a-string/FBSL/reverse-a-string-2.fbsl
Normal file
7
Task/Reverse-a-string/FBSL/reverse-a-string-2.fbsl
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
Function StrRev2(ByVal $p1)
|
||||
dim $b = "", %i
|
||||
for i = len(p1) DOWNTO 1
|
||||
b = b & MID(p1,i,1)
|
||||
next
|
||||
return b
|
||||
End Function
|
||||
7
Task/Reverse-a-string/FBSL/reverse-a-string-3.fbsl
Normal file
7
Task/Reverse-a-string/FBSL/reverse-a-string-3.fbsl
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
Function StrRev3( $s )
|
||||
FOR DIM x = 1 TO LEN(s) \ 2
|
||||
PEEK(@s + LEN - x, $1)
|
||||
POKE(@s + LEN - x, s{x})(@s + x - 1, PEEK)
|
||||
NEXT
|
||||
RETURN s
|
||||
end function
|
||||
20
Task/Reverse-a-string/FBSL/reverse-a-string-4.fbsl
Normal file
20
Task/Reverse-a-string/FBSL/reverse-a-string-4.fbsl
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
DynC StringRev($theString) As String
|
||||
void rev(char *str)
|
||||
{
|
||||
int len = strlen(str);
|
||||
char *HEAD = str;
|
||||
char *TAIL = str + len - 1;
|
||||
char temp;
|
||||
int i;
|
||||
for ( i = 0; i <= len / 2; i++, HEAD++, TAIL--) {
|
||||
temp = *HEAD;
|
||||
*HEAD = *TAIL;
|
||||
*TAIL = temp;
|
||||
}
|
||||
}
|
||||
char *main(char* theString)
|
||||
{
|
||||
rev(theString);
|
||||
return theString;
|
||||
}
|
||||
End DynC
|
||||
49
Task/Reverse-a-string/FBSL/reverse-a-string-5.fbsl
Normal file
49
Task/Reverse-a-string/FBSL/reverse-a-string-5.fbsl
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
DYNASM RevStr(BYVAL s AS STRING) AS STRING
|
||||
// get length of string
|
||||
// divide by two
|
||||
// setup pointers to head and tail
|
||||
// iterate from 1 to (length \ 2)
|
||||
// swap head with tail
|
||||
// increment head pointer
|
||||
// decrement tail pointer
|
||||
|
||||
ENTER 0, 0 // = PUSH EBP: MOV EBP, ESP
|
||||
PUSH EBX // by Windows convention EBX, EDI, ESI must be saved before modification
|
||||
|
||||
MOV EAX, s // get string pointer
|
||||
MOV ECX, EAX // duplicate it
|
||||
|
||||
.WHILE BYTE PTR [ECX] <> 0
|
||||
|
||||
INC ECX // propagate to tail
|
||||
|
||||
.WEND
|
||||
|
||||
MOV EDX, ECX // duplicate tail pointer
|
||||
DEC EDX // set it to last byte before trailing zero
|
||||
|
||||
SUB ECX, EAX // get length in ECX in 1 CPU cycle
|
||||
SHR ECX, 1 // get length \ 2 in 1 CPU cycle; that's the beauty of power-of-two division
|
||||
|
||||
.WHILE ECX > 0
|
||||
|
||||
MOV BL, [EDX] // no need to XOR; just overwrite BL and BH contents
|
||||
MOV BH, [EAX] // DynAsm deduces data size from destination register sizes
|
||||
|
||||
MOV [EDX], BH // ditto, source register sizes
|
||||
MOV [EAX], BL
|
||||
|
||||
INC EAX // propagate pointers
|
||||
DEC EDX
|
||||
|
||||
DEC ECX // decrement counter
|
||||
|
||||
.WEND
|
||||
|
||||
// point to start of string again
|
||||
MOV EAX, s // MOV = 1 CPU cycle, PUSH + POP = 2 CPU cycles
|
||||
|
||||
POP EBX // by Windows convention ESI, EDI, EBX must be restored if modified
|
||||
LEAVE // = POP EBP
|
||||
RET
|
||||
END DYNASM
|
||||
Loading…
Add table
Add a link
Reference in a new issue