Question: I am trying to convert C code to a working translation of Y 8 6 - 6 4 assembly . Here is the code in

I am trying to convert C code to a working translation of Y86-64assembly. Here is the code in C:
// Function to encrypt a message using Caesar cipher
void encrypt(char *message, int shift){
while (*message){
if (*message >='a' && *message ='z'){
*message =((*message -'a'+ shift)%26)+'a';
} else if (*message >='A' && *message ='Z'){
*message =((*message -'A'+ shift)%26)+'A';
}
message++;
}
}
// Function to decrypt a message using Caesar cipher
void decrypt(char *message, int shift){
encrypt(message,26- shift); // Decryption is just encryption with shift =26- original shift
}
This code encodes and decodes strings using a Caesar cipher. This program introduces the manipulation of character arrays and the application of modular arithmetic in assembly language.
For the Caesar Cipher operation, the assembly language program should handle encryption and decryption of strings based on a given shift value. The stack will be prepared as follows before calling the routine:
The shift value will be pushed onto the stack first. This integer determines the number of positions each character is shifted in the alphabet for encryption or decryption.
Next, the 64-bit pointer to the message string that will be encrypted or decrypted will be pushed onto the stack.The message string is null-terminated.
In this setup, message is at the top of the stack, directly accessible by the routine, and shift is just beneath it.
The routine should iterate over each character of the message, checking if it is an alphabetic character. For each alphabetic character, apply the shift, accounting for both uppercase and lowercase letters. The shift must wrap around the alphabet, meaning that after z, it goes back to a, and similarly, after Z, it returns to A. Non-alphabetic characters should remain unchanged.
The modified message string, now encrypted or decrypted, will be in the same memory location as the input. The routine does not need to return any value in %rax since the operation modifies the message string in place. Before returning to the caller, ensure the stack is correctly restored if modified during the routine.
I am trying to convert C code to a working

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!