Code: Select all
;pb 4.30 x86
Procedure.s asm_strrev(*string)
endofnewstring = MemoryStringLength(*string)-1 ;the end should start -1 because the last one is the null terminator already
MOV eax, *string ;eax now points to the same spot as parameter
MOV ebx, *string ;ebx also points to the same spot atm
ADD ebx, endofnewstring ;add to ebx so it points to the last real character of string
reading:
MOV cl, [eax] ;reads current char of string into cl
MOV dl, [ebx] ;reads last char of string into dl
;XOR cl, dl ;performs xor swap
;XOR dl, cl ;
;XOR cl, dl ;at this point the values of cl and dl are swapped (ie first character is now the last character)
MOV [eax], dl ;writes ending char to beginning
MOV [ebx], cl ;writes beginning char to end
ADD eax, 1 ;step up the start to the next character from the beginning
SUB ebx, 1 ;step back the end to the next character from the end
CMP eax, ebx ;ebx - eax
JNA l_reading ;if eax < ebx then keep going :)
ProcedureReturn PeekS(*string)
EndProcedure
Debug asm_strrev(@"): !NOISREVER ECALP NI OLLEH")
after looking at it (duh) for a second, i really didn't need the xor swap but for some reason I just wanted to do it, this will work too.
Also, forgot I was using ebx.. From what you say I should have to preserve it, but if I push it before hand and pop it after I get crazy mem violations. It seems to set itself back to what it was previous to the function being called.
Edit:
Well I think I could prob keep going with a million different ways to do it, heres (maybe) the proper xor swap, also without using a non volatile register(according to documentation at least)
Code: Select all
;pb 4.30 x86
Procedure.s asm_strrev(*string)
endofnewstring = MemoryStringLength(*string)-1 ;the end should start -1 because the last one is the null terminator already
MOV eax, *string ;eax now points to the same spot as parameter
MOV ecx, *string ;ecx also points to the same spot atm
ADD ecx, endofnewstring ;add to ecx so it points to the last real character of string
reading:
MOV dl, [ecx] ;move last char into dl
XOR [eax], dl ;swaps
XOR dl, [eax] ;
XOR [eax], dl ;first char to last char
;why can't you xor memory with memory? grr
MOV [ecx], dl ;dl now = first char, move first char into last position
ADD eax, 1 ;step up the start to the next character from the beginning
SUB ecx, 1 ;step back the end to the next character from the end
CMP eax, ecx ;ecx - eax
JNA l_reading ;if eax < ecx then keep going :)
ProcedureReturn PeekS(*string)
EndProcedure
Debug asm_strrev(@"): !NOISREVER ECALP NI OLLEH")
Why can't you xor memory with memory?
I'll quit now because I dont want to seem spammy. At least I'm learning stuff, thanks guys
