some advice
From: psi (i_at_m.t)
Date: 06/28/04
- Next message: Phil Carmody: "Re: Random number question?"
- Previous message: Betov: "Re: Why RosAsm Breaks on a large number of symbols"
- Next in thread: psi : "Re: some advice"
- Reply: psi : "Re: some advice"
- Reply: psi : "Re: some advice"
- Reply: C: "Re: some advice"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 28 Jun 2004 09:19:01 GMT
I now have to translate simple routines of bignum from C to assembly.
I would like to hear some advice on errors and eventually speed up the
minor() routine.
Thank you
/*--------------------------------------*/
typedef struct{
unsigned len;
unsigned *num;
}num;
this is the routine (that compare bignum) to traslate in assembly
static int minoa(const num* a, const num* b)
{unsigned *aa, *bb;
if(a->len < b->len) R 1;
if(a->len > b->len) R -1;
aa=a->num, bb=b->num;
F(aa+=a->len-1, bb+=a->len-1; *aa == *bb; --aa, --bb)
if( a->num == aa) R 0;
R *bb > *aa ? 1: -1;
}
this is my traslation
section _TEXT public align=1 class=CODE use32
global _minor_s
; offset della struttura num_s */
%define len_off 0
%define num_off 4
; int a minor(&num1, &num2) */
_minor:
push ebp
mov ebp, esp
push ebx
push esi
push edi
push edx
;------------------*/
mov esi, [ebp+8]
mov edi, [ebp+12]
mov eax, [esi]
mov ebx, [edi]
cmp eax, ebx
jae .con ; b == <; a < b*/
mov eax, 1
jmp short .fine
.con:
jbe .con1
mov eax, -1
jmp short .fine
.con1:
dec ebx ; len - 1 */
dec eax
mov esi, [esi + num_off]
mov edi, [edi + num_off]
push esi
shl eax, 2 ; a=4*a b=4*b */
shl ebx, 2
add esi, eax
add edi, ebx
pop eax
mov edx, 4
.lo:
mov ebx, [esi]
cmp ebx, [edi]
jne .esci
cmp esi, eax
jne .co
mov eax, 0
jmp short .fine
.co:
sub esi, edx
sub edi, edx
jmp short .lo
.esci:
jbe .con2
mov eax, -1
jmp short .fine
.con2:
mov eax, 1
.fine:
pop edx
pop edi
pop esi
pop ebx
mov esp, ebp
pop ebp
ret
/*----------------------------*/
/*or in 'my' macro assembly */
section _TEXT public align=1 class=CODE use32
global _minor_s
/* offset della struttura num_s */
%define len_off 0
%define num_off 4
/* int a minor(&num1, &num2) */
_minor:
{< k | k=s;
< b, i, j, r
/*------------------*/
i = [k+8]; j = [k+12]
a = [i]; b = [j]
a <> b
jae .con /* b == <; a < b*/
{ a = 1; jmp short .fine }
.con:
jbe .con1
{ a = -1; jmp short .fine }
.con1:
--b; --a /* len - 1 */
i = [i + num_off]; j = [j + num_off]
< i;
a <<= 2; b <<=2 /* a=4*a b=4*b */
i += a ; j += b
> a;
r=4;
.lo:
b = [i]
b!=[j] ? .esci;
i==a ! .co;
{ a=0; jmp short .fine }
.co:
i -= r | j -= r
jmp short .lo
.esci:
jbe .con2
{ a=-1; jmp short .fine }
.con2:
a=1
.fine:
> b, i, j, r
s=k | > k
ret
}
- Next message: Phil Carmody: "Re: Random number question?"
- Previous message: Betov: "Re: Why RosAsm Breaks on a large number of symbols"
- Next in thread: psi : "Re: some advice"
- Reply: psi : "Re: some advice"
- Reply: psi : "Re: some advice"
- Reply: C: "Re: some advice"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|