Question: x86 Assembly MASM --- For this programming assignment you will develop two assembly language procedures that will be called from C. The C module is
x86 Assembly MASM
---
For this programming assignment you will develop two assembly language procedures that will be called from C. The C module is given to you. You will provide the assembly module containing the two procedures.
The C prototype for the first procedure is shown below.
void convertUpper(char* c);
convertUpper will receive a pointer to a character (i.e. the address). Here are the things convertUpper should do:
Check to see if the character is a lower case character. If not, return without doing anything.
Convert the character at the address to upper case.
The C prototype for the second procedure is shown next.
void convertLower(char c1, char c2, char c3, char c4, char c5, char c6, char c7);
convertLower will receive seven characters. The characters will be either alpha or numeric characters. If a character is an upper case alpha character, it should be converted to lower case. convertLower should do the following things:
Convert each of the seven characters to lower case if it is an upper case alpha character.
Call the C function, printChars, to print the seven characters after the conversion to lower case. printChars is given to you in the C source code file shown below.
The following source file contains the C code you will use to call the assembly procedures. You may modify the code for testing purposes.
You may not use the Microsoft directives PROTO and INVOKE for this assignment.
Details on how to go about this assignment would be greatly appreciated.
C code below
--------------------------
#include
// C prototypes for the functions written in assembly language void convertUpper(char* c); void convertLower(char c1, char c2, char c3, char c4, char c5, char c6, char c7);
// Main ------------------------------------------------------------------- int main() { char lowerChar = 'a'; char upperChar; char c1 = 'C', c2 = 'S', c3 = 'C', c4 = 'I', c5 = '2', c6 = '1', c7 = '2';
upperChar = lowerChar; // Copy the character to be converted convertUpper(&upperChar); // Convert character to upper case printf("lower = %c, upper = %c ", lowerChar, upperChar); // Print result
// Convert seven characters to lower case convertLower(c1, c2, c3, c4, c5, c6, c7);
return 0; }
//------------------------------------------------------------------ // Description: Prints the seven characters that are passed to it // Receives: Seven characters // Returns: Nothing void printChars(char c1, char c2, char c3, char c4, char c5, char c6, char c7) { printf("%c%c%c%c%c%c%c ", c1, c2, c3, c4, c5, c6, c7); }
==========================
I am not sure how to pass the char into my stack and keep my stack aligned and how to return the value. Please keep in mind, this, this procedure is called from an assembly file to C. I cannot use inline assembly.
My converUpper code is as follows:
.386 .model flat,C
.code
;----------------------------------------------------- convertUpper PROC ; Function prolog push ebp mov ebp, esp ; Compute the result
;mov checkUpper, 0000000000000000000000000100000b ;mask mov eax, 0000000000000000000000000100000b and eax, [ebp + 8] cmp eax, 0000000000000000000000000100000b jnz noConvert mov eax, [ebp + 8] xor eax, 0000000000000000000000000100000b nop mov [ebp +8], eax jmp upperEnd noConvert: mov eax, [ebp + 8] jmp upperEnd ; Function epilog upperEnd: nop pop ebp ret 4 convertUpper ENDP
END
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
