why do i get a SEGMENTATION FAULT error when i run the follow C program with the assembly code.
================assembly====================
regstack = 4 * 8 # There are 8 32-bit registers on the stack
arg1 = regstack + 8 # The offset for arg1 is 4 greater to skip ret add
arg2 = arg1 + 8
arg3 = arg2 + 8
.globl add4 #function name( yours is add4)m
add4: pushal # save all the registers
movl %esp, %ebp # and set the frame pointer
movl arg1(%ebp), %esi# esi points to the source number
movl arg2(%ebp), %edi# and edi the destination
movl arg3(%ebp), %ecx# ecx gets the longword count
clc # start with c-bit = 0
l1: movl (%esi), %eax # get next longword of source
adcl %eax, (%edi) # and add it to the destination
leal 4(%esi), %esi # bump both pointers
leal 4(%edi), %edi
decl %ecx # decrement the loop counter
# (note this does not affect the c-bit)
jnz l1 # loop until 0
movl $0, regstack-4(%ebp) # clear the location of %eax
adcl $0, regstack-4(%ebp) # and add in the c-bit
popal # then restore all the registers
ret # and return
=============c program=============
#include <stdio.h>
int add4(unsigned int a[], unsigned int b[], unsigned int c[]);
int main()
{
unsigned int a[4], b[4], c[4], carry, rem;
while(1)
{
printf("a=");
scanf("%x%x%x%x", &a[3], &a[2], &a[1], &a[0]);
printf("b=");
scanf("%x%x%x%x", &b[3], &b[2], &b[1], &b[0]);
carry = add4(a, b, c);
printf("add %d%9.8X%9.8X%9.8X%9.8X\n", carry, c[3], c[2], c[1], c[0]);
if(!(carry||c[0]||c[1]||c[2]||c[3]))
return 0;
}
}
_________________ n/a
|