Hey guys...
I am currently writing two programs, a transmitter and a receiver, which sends and receives a file between two computers over the COM port, the programs do work, however it's the encryption/cipher I am stuck on, I need to call a C function in assembler so that the character being read from the file is "encrypted".
Also... if the code below doesn't make sense... the character from the file is converted to ASCII format, then the value is incremented by 10, it is then converted back to character value.
Here's the code:
C:
Code:
// Start of cipher algorithm //
char cipher(char a){
int b = a;
int i = 0;
// Loop to increment the ascii equivilent of the character by 10 //
for(i = 0;i<10;i++){
// Once the integer reaches the end of the ascii table, loop it back around to the start //
if (b == 128){
b = 32;
}else{
b++;
}
}
char o=b;
return o;
}
Assembly:
Code:
// while (not EOF) {
top_of_loop:
// Read char from file
mov eax, DWORD PTR fileptr ; load the file/port ptr
push eax ; push the file/port ptr onto the stack
call DWORD PTR fgetc ; call fgetc()
add esp,4 ; remove the file/port ptr from the stack
mov chr, al ; char is returned in a
cmp al, EOF
je end_of_loop
// Write char to COM1
mov eax, DWORD PTR portptr ; load the file/port ptr
push eax ; push the file/port ptr onto the stack
mov al, chr ; load the char to be output
push eax ; push char onto the stack (needs to be tested)
call DWORD PTR fputc ; call fputc()
add esp, 8 ; remove both parameters from the stack
// }
jmp top_of_loop
That assembly code is only a selection, but I believe the function needs to be called in there, as it's reading from the file and then writes it to the COM1 port.
Regards,
Chris