//////////////////////////////////////////////////////// // ECE 272 Lab // // NAME: Firstname Lastname // // SECTION: Four (12:20 - 2:20) M // // DATE DUE: Feb. 1, 1998 // // FILENAME: somefile.extension // // PROJECT: Lab Assignment #1 // // PURPOSE: This assembly program calculates the // // ASCII sum of the characters passed to // // it as a character array. // ////////////////////////////////////////////////////////A brief explanation of some of the entries:
///////////////////////////////////////////////////// // PROCEDURE: ProcedureName // // PARAMETERS: Listing of parameters // // RETURNS: Listing of data that gets returned // // DESCRIPTION: What this procedure does // /////////////////////////////////////////////////////A brief explanation of some of the entries:
First, the C file :
////////////////////////////////////////////////////////
// ECE 272 Lab //
// NAME: Joe Smith //
// SECTION: Four (12:20 - 2:20) M //
// DATE DUE: Feb. 1, 1998 //
// FILENAME: drv.c //
// PROJECT: Lab Assignment #1 //
// PURPOSE: This C program prompts the user for //
// a string terminated with a newline //
// character. It then makes a call to //
// an assembly function named asum and //
// prints the ASCII sum returned by that //
// function. //
////////////////////////////////////////////////////////
main() {
char buffer[256];
do {
int i = 0;
printf("Enter a string terminated with a newline\n");
do {
buffer[i] = getchar();
} while(buffer[i++] != '\n');
buffer[i-1] = 0;
i = asum(buffer);
if(i) {
printf("ascii sum is %d\n", i);
continue;
}
} while(1);
}
And now the Assembly file :
////////////////////////////////////////////////////////
// ECE 272 Lab //
// NAME: Joe Smith //
// SECTION: Four (12:20 - 2:20) M //
// DATE DUE: Feb. 1, 1998 //
// FILENAME: asm.s //
// PROJECT: Lab Assignment #1 //
// PURPOSE: This Assembly program calculates the //
// ASCII sum of an array of characters //
// passed to it. //
////////////////////////////////////////////////////////
.file "asm.s"
.align 16
.global asum
.type asum,@function
/////////////////////////////////////////////////////
// PROCEDURE: asum //
// PARAMETERS: A character array placed on the //
// stack. //
// RETURNS: The ASCII sum of the characters of //
// the array. //
// DESCRIPTION: Sums up the ASCII values of an //
// array of characters. //
/////////////////////////////////////////////////////
asum:
pushl %ebp # 34qfwasfd
movl %esp, %ebp
subl $4, %esp
movl $0, -4(%ebp)
.L2:
movl 8(%ebp), %eax
cmpb $0, (%eax)
jne .L4
jmp .L3
.align 16
.L4:
movl 8(%ebp), %eax
movsbl (%eax), %edx
addl %edx, -4(%ebp)
incl 8(%ebp)
movl $-1, %ebx
jmp .L2
.align 16
.L3:
movl -4(%ebp), %eax
jmp .L1
.align 16
.L1:
movl %ebp, %esp
popl %ebp
ret
.Lfel:
.size asum, .Lfel-asum