I am trying to accomplish a simple task (in theory):
1. Get the computer name
2. Loop through each letter performing this operation:
A. Ascii of letter MOD 10
B. Divide by 2
C. Send result to a buffer to hold the final password
so far I have this, and errors seem to be everywhere. Be gentle... :) I am still new!
Am I even close????????
CalculateCombo PROC USES EBX ECX EDX ESI
LOCAL iComputerNameLen
LOCAL iSerialLength
LOCAL sCorrectPassword
xor ecx,ecx ; Clear Registers
xor eax,eax
xor ebx,ebx
invoke lstrlen,addr ComputerName ; Length of ComputerName
mov iComputerNameLen, eax
mov edi,offset ComputerName ; Move Name to EDI
mov ecx, 0 ; Zero out ECX to be sure
.while ecx < iComputerNameLen
mov dl,byte ptr [edi+ecx] ; ComputerName Byte
push al ; Preserve Registers??
push ah
mov ax, dl ; Character to dl
div 10h ; Divide by 10h
; Remainder is in AH
mov ax, ah
div 2
; Quotient is in AL
mov al, byte ptr [sCorrectPassword+ecx]
inc ecx
.endw
CalculateCombo EndP
Is it mod 10 decimal or 10 hex (16 decimal) ?
After div 2 what will you add to put it back in regular keyboard character range,
32, 48, 64, 96 ?
Where is the newly generated string stored ?
Usually a push is a 32 bit value ie push eax.
For each push a pop is needed to balance the stack.
edi is used but isn't listed in USES
a convention is ebx esi edi are preserved.
ENDP does not generate a RET instruction.
Add RET.
Giovanni,
> CalculateCombo PROC USES EBX ECX EDX ESI
Something worth getting right is which registers you preserve and which ones you can trash. You would not normally preserve ECX and EDX as they are transient registers where you normally preserve EBX ESI and EDI. When you use a normal stack frame ESP and EBP are already preserved.
I am a dinosaur and prefer the manual register style of preservation so I would start the proc like this,
CalculateCombo proc
push ebx
push esi
push edi
; write your prcedure here
pop edi
pop esi
pop ebx
ret
CalculateCombo endp
With this normal layout you can trash EAX ECX and EDX without having to preserve them but if you use any of EBX ESI and EDI you must preserve them.