Re: Accessing Command-line text



On Tue, 20 Feb 2007 21:20:21 +0100, "¬a\\/b" <al@xxx> wrote:
On 18 Feb 2007 03:45:54 -0800, "omariqbalnaru"
<omariqbalnaru@xxxxxxxxx> wrote:

I am new to Assembly Language Programming and using NASM and AFD. I
want to make a program to calculate a number's factorial which is
given on the command line e.g. factorial 6 . Please tell me how to
access 6 (i.e. the number entered by the user on the command line). I
tried to understand the PSP's architecture but still didn't get how to
access the command line text. Thanks in advance.

i thought to a function that accept numbers from -1..intmax
and has as argument (and as result) a number of format

(memoria_del_vettore, lunghezza_del_numero,
a[0], a[1], ... a[memoria_del_vettore]-1)

non testato

not tested
i write this but not run it one time, it is only for clear

section _DATA public use32 class=DATA

global _fatt

section _TEXT public use32 class=CODE

; void fatt(uns* out, uns n)
; fatt(n)=n! in out
; out point to {mem, len, intarray}
; errore <=> CF==1 or len==0
; 0k, 4j, 8i, 12r, 16c, 20b, 24a, 28ra, 32Pout, 36Pn


i have some time to spend...
the input is in decimal the output is in hex

i have a question to ask: is it possible 3 (or more) times overflow
in the line with "*******************" ?

section _DATA public use32 class=DATA

global fatt

section _TEXT public use32 class=CODE

; void fatt(uns* out, uns n)
; fatt(n)=n! in out
; out=={mem, len, intarray}
; errore <=> CF==1 or len==0
; 0k, 4j, 8i, 12r, 16c, 20b, 24a, 28ra, 32Pout, 36Pn
fatt:
push eax
push ebx
push ecx
push edx
push esi
push edi
push ebp
mov ebx, [esp+32]
mov esi, [esp+36]
cmp ebx, 0
je .e
cmp dword[ebx], 0
jle .e
mov dword[ebx+4], 1
mov dword[ebx+8], 1
xor edi, edi
xor ebp, ebp
add ebx, 8
cmp esi, -1
jne .0
..a:
clc
jmp .f
..e:
mov ebx, [esp+32]
mov dword[ebx+4], 0
stc
jmp short .f
..0:
cmp esi, 0
jz .a
jl .e
mov ecx, 1
; a0, a1, a2, a3
..1:
mov eax, [ebx]
mul esi
mov [ebx], eax
add [ebx], edi
adc edx, 0
jc .e ; ********************
mov edi, edx
dec ecx
jz .2
mov eax, [esp+32]
inc ebp
cmp ebp, [eax]
jae .e
add ebx, 4
jmp short .1
..2:
cmp edx, 0
je .3
mov eax, [esp+32]
inc ebp
cmp ebp, [eax]
jae .e
add ebx, 4
mov [ebx], edx
..3:
mov edi, [esp+32]
xor ebp, ebp
add edi, 8
mov ecx, ebx
sub ecx, edi
mov ebx, [esp+32]
shr ecx, 2
inc ecx
mov edi, 0
mov dword[ebx+4], ecx
add ebx, 8
dec esi
cmp esi, 1
jg .1
clc
..f:
pop ebp
pop edi
pop esi
pop edx
pop ecx
pop ebx
pop eax
ret 8


----------------

#include <stdio.h>
#include <string.h>

int sscan_m(char** ove, char* input, char* fmt, ...);
void __stdcall fatt(unsigned* a1, int b1);


int main(void)
{unsigned a[1024];
int res, k, i;
char ar1[125], *pc=0, *r;


a[0]=1020;
printf("Insert integer number >= -1 > ");
r=fgets(ar1, 124, stdin);

if(r==0 || *r==0 || r[strlen(r)-1]!='\n')
return 0;
res=sscan_m(&pc, ar1, "%d", &k);
if(res==1) printf("valore immesso=%d\n", k);
else {printf("Valore non preso\n"); return 0;}
fatt(a, k);
printf("%d! = ", k); fflush(stdout);
if(a[1]<=0){printf("Errore\n"); return 0;}
for(i=a[1]-1; i>=0; --i)
printf("%x", a[i+2]);
return 0;
}
--------------------------

does it result this?
(decimal)! = (hex)
4! = 18
10! = 375f00
15! = 13077775800
20! = 21c3677c82b40000
50! = 49eebc961ed279b02b1ef4f28d19a84f5973a1d2c780000
100! =
1b30964ec395dc24069528d54bbda40d16e966ef9a70eb21b5b2943a321cdf10391745570
cca9420c6ecb3b72ed2ee8b02ea2735c61a000

600! =
30fe96c513d96281e30d034086d886a581c48f25c801401c65a7f276a61a37810b4d8b166
d2d04c2a652e28c4ce6652283afaddf53787cb701688f4ab70daf4cab53f93d7e71cf2e84d9725d6
bffbe8bd4b8e93435ca19c8fffd60142abdd0b8ed5e9265087bebfb8be0623f7b35913e6b1d01576
6096ac55400a784f7801d46b01ca459b4bef2b3b5cd97e2442b63d69aee6e4a37532ec9a0737f3dd
08790e5a5d4a537735f67bf86ff8c8000117d8c015db5a450fbb49778dc5ed9d9de8540065d3ae9e
2226aff448176cfec2ce07de76b15ae8fc66881734dc65164a19f95ad25ba4b613ca891be9497c1d
ae216d7b16a21a11318db6b03246fc8874707556d87b1499de3e3ce7d80686b98de481b73c1081b9
b23956965164461fc3e1910c698c34720308c4e66deb1fd9272cfc1c2c79b27da491937d00e063db
8ec7b8b4d5c3bb68f6cac31352ff7ce78bbdd55a38e23c16ecc1faa7fc7b7f31e0d0c83bfe2e4202
124d74892a07f4fa7c7422c9911c184e39e6128f69d7dc9aec52cabc36a9a5c8a58f9eb39c894816
58f12e9678e8b4d81acc1fcb30ece429377b3fc313703651c33a7b1b8b77a289c230bac4db3a78d4
878a063f5d3cdd9c40c7d441fe27fca109b07daa2bd1fa4fba2db928b9c55efb921e4b92a6230a97
9024b639a36260cd4122fdf06ecfc8e3321bf63ff01098f55af625ab7d3430000000000000000000
0000

1000! =
2a2a773338969b740de6e2b291fd8dd6ee62a2b41525ab61cbe52489b6cf344c23231711
b6d9f34e0f13ab50eaf1ad3dd92771ec26b4b9ea80411c866b1ccbd855f8326edab10832755e1682
d3e7a91335e3670329bc1571b5208d72f7d6be81483a6e6708abf913b789f41838e9a73c1ba82e3a
95657405a660a17e1125838bc810c8d2c63915481914ea202867a563a41b6aefef5feac300a78803
a30eb995208842ebeba8729397a8cd9087e28fb155a3de0f18dd90e64a9293af6487a5aabdab855f
a254fcbdc9f1116060bc2e2b4410e55e7368b844d9bfaeca92deb017def69af777e8d4edb1f1b926
ae01df3366abb9e4568fc08fe255b68bca0e48382a8e6df1c7bba33bc2225cc512b39176a26b1309
8e733e51417224be36fbd933a8a7d98a08f356cf01f0fc59b9f1e32d3fb43209a82fa0e7f69e302f
cb0f20362b86cbbeb8b81b1ba07f08ab119ce5e092d09996b710588779327d91ee80eb679a99f0fd
ca7eb4a5ef174295e94d590e3cf8bf37d23e5b22dcd79a4ac2c1ea7d1d55170789fcd2fcbb3ea52e
ad4f7116f862578f5e22421c90cd0a7ee095903150631f27305191429a54cace66dd076c51a94034
b31bebec406ee46181225e3a9a22c51e6a2a8db4a94fd352605115caf251b14df0cec523c48b79b5
8b0fc676792d38a0d61523eb75f5cbc33ebda1b19933878ce705356bd228ce9327a9916f9ff3bb5b
6beedfe5382b861d6c4da52a9754b6feec8a99372b43afa7808836d281c5b2cdf791cf76d6c737aa
d32c5ed7475855fc15c3f45c4705dd0d6b478656d027cfee6f37772e03c35c0dcbbdaa25ea64d686
5c87cac0a9a999eb88d7a16515811a77192071189c353c1e72242a4f316cef2bad1075549b4efd68
85690f3f58c1f4686951cc543118428ec653e3c6fbdb42793f624680672c1e70c25db7e7b67016a9
5b30dba56d0083759eac93a8e4d0c54853aa43f197b96fd7696ae5750d7d1f0427b8dbcfafc8b992
4d51340fbf71bc22780fba76525f5e5b91a2461983b60bf87dfdd89dcbc6f7892d9e4c5d55d106d4
5f77e4fc1c44a376d693bfb8b160f12ed1bdf5f4f1127e61d9dec2dc1bba43a6ff47d294de7a67cd
f3ef90937667092517e985642d195031c6f5339c1cea607a699c55e75c5479cbd30ddaccab307472
aa67a6a9a547d7e1eba123144193e6d2933556ddeb516151eacf0b48ce08892236abfb74bf0cee3a
0e45997301027f2a53990697694f14de4fac0c908eeaeedf3dbb45c4ce9f744fef88ec1068c52056
b16da099e1fb62bd90de25534b5e820b367a40000000000000000000000000000000
10000! = Errore

this is the traslation in my little language

section _DATA public use32 class=DATA

global fatt

section _TEXT public use32 class=CODE

/* void fatt(uns* out, uns n)
/* fatt(n)=n! in out
/* out=={mem, len, intarray}
/* errore <=> CF==1 or len==0
/* 0k, 4j, 8i, 12r, 16c, 20b, 24a, 28ra, 32Pout, 36Pn
fatt:
< a, b, c, r, i, j, k
b=[s+32]; i=[s+36];
b==0#.e; D*b<=0?#.e;
D[b+4]=1; D[b+8]=1;
j^=j; k^=k; b+=8;
i==-1!?#.0
..a: clc; ##.f;
..e: b=[s+32]; D[b+4]=0; stc; #.f;
..0: i<>0; =#.a; <?#.e;
c=1;
/* a0, a1, a2, a3
..1: a=*b; mul i; *b=a; *b+=j; r++=0; jc .e; /*3overflow?
j=r; --c!#.2; a=[s+32]; ++k; k>=[a]#.e; b+=4;
#.1;
..2: r==0#.3| a=[s+32]; ++k; k>=[a]#.e; b+=4; *b=r;
..3: j=[s+32]; k^=k; j+=8;
c=b; c-=j; b=[s+32]; c>>=2;
++c; j=0; D[b+4]=c; b+=8;
--i; i>1?#.1;
clc
..f:
a, b, c, r, i, j, k
ret 8



.



Relevant Pages

  • C asm to delphi asm
    ... cmpxchg [edi], ebx ... mov ebx, eax ... mov eax, edi ...
    (borland.public.delphi.language.basm)
  • Re: C asm to delphi asm
    ... > cmpxchg [edi], ebx ... > mov ebx, eax ... > mov eax, edi ...
    (borland.public.delphi.language.basm)
  • Re: Working on fast memcmp-like code
    ... mov esi, ... mov edi, ... mov ebx, ...
    (comp.lang.asm.x86)
  • Re: Help: ASM to ASM calls
    ... mov bl, ... movzx ebp, byte ... closely watching the stack... ... caller's ebx ...
    (comp.lang.asm.x86)
  • Re: DivMod
    ... mov ebx, edx ... mov ebx, Remainder ... mov edi, ...
    (borland.public.delphi.language.basm)