#include<stdio.h>
void encode( char* str ){
asm (
"movl %0,%%ebx\n\t" //store the string address in ebx register
"eback:\n\t" //loop scans the string character
"movb (%%ebx), %%al\n\t" //put next character to eax register
"cmp $0, %%al\n\t" //look at string termination, NULL character
"je efinish\n\t" //jump to finish point if null is found
"addb $3, %%al\n\t" //forward 3 characters front..
"movb %%al, (%%ebx)\n\t" //put encrypted character to its place
"addl $1, %%ebx\n\t" //go to next character
"jmp eback\n\t"
"efinish:\n\t"
:
:"g"(str)
:"%ebx" //ebx is marked as changed register
);
}
void decode( char* str ){
asm (
"movl %0,%%ebx\n\t" //store the string address in ebx register
"dback:\n\t" //loop scans the string character
"movb (%%ebx), %%al\n\t" //put next character to eax register
"cmp $0, %%al\n\t" //look at string termination, NULL character
"je dfinish\n\t" //jump to finish point if null is found
"subb $3, %%al\n\t" //forward 3 characters back..
"movb %%al, (%%ebx)\n\t" //put encrypted character to its place
"addl $1, %%ebx\n\t" //go to next character
"jmp dback\n\t"
"dfinish:\n\t"
:
:"g"(str)
:"%ebx" //ebx is marked as changed register
);
}
int main(){
char message[] = "Hi this is emreknlk";
/*original message*/
printf("original \tmessage: %s\n",message);
/* encode the message:*/
encode( message );
printf("encoded \tmessage: %s\n",message);
/*decode the message*/
decode( message );
printf("decoded \tmessage: %s\n",message);
return 0;
}
output:
D:\My Documents\itu\cc>sezar_asm.exe
original message: Hi this is emreknlk
encoded message: Kl#wklv#lv#hpuhnqon
decoded message: Hi this is emreknlk
yea, i want to begin with C, asm and pointers :) It is just a begining it is not the end.. C U Soon guys..
3 comments:
welcome back chief :)
hey men you coool ha ;)
"bak uzun zaman oldu haaaaa" diye başlamışsın cümlene ama görüyorumki septemberda yazmışsın en son bunu da bu duruşa bi son vermenin zamanı gelmedi mi sayın knlk:p
Post a Comment