Ok.. i am in class.. 2 weeks left.. and i am stuck like chuck...so i call the pros...What i am triing to do is get user to input a word or phrase which is then encrypted.. i dont know what i am missing..last programing class ever.. :D.. def will leave to the pros... code below..
Include Irvine32.inc
.data
key BYTE -2,4,1,0,-3,5,2,-4,-4,6
keySize = $ - key
plaintext BYTE 21 DUP(0) ;input buffer
textCount DWORD ? ; holds counter
userinput BYTE "Please type in a word to encrypt : ",0
outputword BYTE "Your word encrpyted : ",0
.code
main PROC
mov edx,OFFSET plaintext ; point to the buffer
mov ecx,SIZEOF textcount ; specify max characters
mov ebx, userinput
call Write String
call ReadString ; input the string
mov textcount,eax ; number of characters
;call clrscr
;call writestring
mov esi, OFFSET plainText
L1:
mov edi, OFFSET key
mov ecx, keySize
Call Encode
jnz L1
mov edx, OFFSET plainText
call WriteString
call Crlf
exit
MAIN ENDP
Encode PROC
L1:
push ecx
cmp BYTE PTR[esi],0
je L4
mov cl,[edi]
cmp cl,0 ;rotate right
jge L2 ;if yes goto L2
neg cl
rol BYTE PTR[esi], cl ;rotate lft
jmp L3
L2:
ror BYTE PTR[esi], cl ;rotate rgt
L3:
inc esi ;nxt letter
inc edi ;nxt key
pop ecx
loop L1
or eax, 1 ;force ZF=0
jmp L5
L4:
pop ecx ; return zf=1
L5:
ret
ENCODE ENDP
END Main
mov ebx, userinput ; error A2070: invalid instruction operands
The problem is that userinput is defined as a BYTE, but EBX is a DWORD register.
The statement should probably be:
mov ebx, OFFSET userinput
call Write String ; Error A2206: missing operator in expression
"Write String" should be one word.
And there are other errors.
All compiles good buddy. Just tweak those extern symbols i put.
;Include \masm32\include\Irvine32.inc
.586
.model flat,stdcall
option casemap:none
.data
extern Write_String:NEAR
extern ReadString:NEAR
extern Crlf:NEAR
key BYTE -2,4,1,0,-3,5,2,-4,-4,6
keySize = $ - key
plaintext BYTE 21 DUP(0) ;input buffer
textcount DWORD ? ; holds counter
userinput BYTE "Please type in a word to encrypt : ",0
outputword BYTE "Your word encrpyted : ",0
.code
main PROC
mov edx,OFFSET plaintext ; point to the buffer
mov ecx,SIZEOF textcount ; specify max characters
mov ebx,offset userinput
call Write_String
call ReadString ; input the string
mov dword ptr textcount,eax ; number of characters
;call clrscr
;call writestring
mov esi, OFFSET plaintext
L1:
mov edi, OFFSET key
mov ecx, keySize
Call Encode
jnz L1
mov edx, OFFSET plaintext
call Write_String
call Crlf
;exit
main ENDP
Encode PROC
L1:
push ecx
cmp BYTE PTR[esi],0
je L4
mov cl,[edi]
cmp cl,0 ;rotate right
jge L2 ;if yes goto L2
neg cl
rol BYTE PTR[esi], cl ;rotate lft
jmp L3
L2:
ror BYTE PTR[esi], cl ;rotate rgt
L3:
inc esi ;nxt letter
inc edi ;nxt key
pop ecx
loop L1
or eax, 1 ;force ZF=0
jmp L5
L4:
pop ecx ; return zf=1
L5:
ret
Encode ENDP
END main
regs X
Thanks alot.. this really helped..still racked my brain.. :t