Convert an ip address to long value

J

John F

John F wrote:
reset^=reset;


Jordan Abel said:
The problem is that your variable is in memory, so storing an 0 literal
to it is faster than the "xor trick"

I know... that's why there is no "best solution" except the compiler does
the optimizing in a certain way. That's why I occationally look at the
disassembly.
It sounds like you don't really understand asm

I do understand ASM ... x86, C166, 8051, MIPS, some DSPs ... so ...
I just did not get the right switches for forcing reset into a register.
Now I get it (see listing below...) some debug options prevented the
compiler from doing most optimisazion...
It does optimize reset=0; to the same instruction now... so ... excellent
work done by OW ... I knew it did work somehow ;-)

see 002E... that's what I intended to get...

regards
John

Listing (use fixed kerning font):
Segment: _TEXT PARA USE32 000000A4 bytes
0000 iptol_:
0000 53 push ebx
0001 51 push ecx
0002 52 push edx
0003 56 push esi
0004 57 push edi
0005 55 push ebp
0006 89 C5 mov ebp,eax
0008 B9 01 00 00 00 mov ecx,0x00000001
000D 31 F6 xor esi,esi
000F 31 D2 xor edx,edx
0011 80 38 00 cmp byte ptr [eax],0x00
0014 74 06 je L$2
0016 L$1:
0016 40 inc eax
0017 80 38 00 cmp byte ptr [eax],0x00
001A 75 FA jne L$1
001C L$2:
001C 89 C3 mov ebx,eax
001E 89 EF mov edi,ebp
0020 48 dec eax
0021 29 DF sub edi,ebx
0023 74 39 je L$7
0025 80 38 2E cmp byte ptr [eax],0x2e
0028 75 06 jne L$3
002A 48 dec eax
002B C1 E1 08 shl ecx,0x08
002E 31 D2 xor edx,edx
0030 L$3:
0030 83 FA 01 cmp edx,0x00000001
0033 75 16 jne L$5
0035 BB 0A 00 00 00 mov ebx,0x0000000a
003A L$4:
003A 0F BE 38 movsx edi,byte ptr [eax]
003D 83 EF 30 sub edi,0x00000030
0040 0F AF F9 imul edi,ecx
0043 0F AF DF imul ebx,edi
0046 42 inc edx
0047 01 DE add esi,ebx
0049 EB D1 jmp L$2
004B L$5:
004B 83 FA 02 cmp edx,0x00000002
004E 75 07 jne L$6
0050 BB 64 00 00 00 mov ebx,0x00000064
0055 EB E3 jmp L$4
0057 L$6:
0057 BB 01 00 00 00 mov ebx,0x00000001
005C EB DC jmp L$4
005E L$7:
005E 89 F0 mov eax,esi
0060 5D pop ebp
0061 5F pop edi
0062 5E pop esi
0063 5A pop edx
0064 59 pop ecx
0065 5B pop ebx
0066 C3 ret
 
R

RSoIsCaIrLiIoA

Do you want to convert a string like "137.193.64.130" into a 32 bit value
stored in a register (eax)? And for this you need more than 350 line of
code?

in the origin was

"ping 192.0xb2.031.249"

it is for convert ip number like above; the number can be after each
point hexadecimal, decimal or octotal. you are right, i have not
'reduced' it; you are not the only one that like
small programs :))))))))
 
R

RSoIsCaIrLiIoA

in the origin was

"ping 192.0xb2.031.249"

it is for convert ip number like above; the number can be after each
point hexadecimal, decimal or octotal. you are right, i have not
'reduced' it; you are not the only one that like
small programs :))))))))

i have try to reduce but with no success
yes in this case i'm long: i add some comments
do you like my "spaghetti" code ? :))
how many people can write or read code like that?
(i thik for read only the cpu in .exe and nobody in conventional
assembly form)

; nasmw -f obj this_file.asm
; bcc32 this_file.obj

section _DATA public align=4 class=DATA use32

Scrivi_numero_ip db "Srivi un internet adr. > " , 0
Errore db "Errore" , 10 , 0
Errore1 db "Errore" , 0
Errore_linea_troppo_lunga db "Errore linea troppo lunga" , 0
Numero_naturale_conversione_$u
db "Numero naturale conversione %u" , 10 , 0
Errore_contenuto_linea db "Errore contenuto linea" , 10 , 0

$lf db "%lf" , 0
errno_u_$i db "errno=%i " , 0
$u_$u db " <%u %u> " , 0
$i_p$i_p$i_p$i db " %d.%d.%d.%d%*[^" , 10 , "]" , 0
val db 0

extern _printf , _errno , _sscanf , _fgets
extern _perror , __streams , _isspace
global _main

section _TEXT public align=1 class=CODE use32


; unsigned otto_to_u(char* dove, char* arr)
; legge numeri che sono considerati di base 8
; di al massimo tre cifre significative
; del tipo 0123 oppure 0 oppure 01 oppure 012
; che hanno il terminatore '.' o '\n' o ' ' o '\t'
; in caso di errore 'dove'='arr'; altrimenti
; 'dove' punta al prossimo carattere non letto
; s=0c, 4i, 8r, 12b, 16ra, 20dove, 24arr
otto_to_u:
push ebx
push edx
push esi
push ecx
mov esi, [esp+24]
mov edx, 0
mov eax, 0
mov ecx, 3
cmp byte[esi], '0'
jne .e0
inc esi
..a0:
mov dl, [esi]
..a1:
cmp edx, '7'
jg .e1
cmp edx, '0'
jl .e1
jmp short .a2
..e0:
mov eax, [esp+24]
mov ebx, [esp+20]
mov [ebx], eax
mov eax, 0
jmp short .fn
..e1: ; 9=TAB
cmp edx, ' '
je .a4
cmp edx, 10
je .a4
cmp edx, 9
je .a4
cmp edx, 0
je .a4
cmp edx, '.'
je .a4
jmp short .e0

..a2:
shl eax, 3
sub edx, '0'
add eax, edx
inc esi
dec ecx
jnz .a0

..a3:
mov dl, [esi]
jmp short .e1
..a4:
mov edx, [esp+20]
mov [edx], esi
..fn:
pop ecx
pop esi
pop edx
pop ebx
ret



; unsigned decarr_to_u(char* dove, char* arr)
; legge numeri che sono considerati di base 10
; di al massimo tre cifre significative
; [del tipo 123 oppure 1 oppure 12]
; che hanno il terminatore '.' o '\n' o ' ' o '\t'
; in caso di errore 'dove'='arr'; altrimenti
; 'dove' punta al prossimo carattere non letto
; s=0c, 4i, 8r, 12b, 16ra, 20dove, 24arr
decarr_to_u:
push ebx
push edx
push esi
push ecx
mov esi, [esp+24]
mov edx, 0
mov eax, 0
mov ecx, 3
..a0:
mov dl, [esi]
..a1:
cmp edx, '9'
jg .e1
cmp edx, '0'
jl .e1
jmp short .a2
..e0:
mov eax, [esp+24]
mov ebx, [esp+20]
mov [ebx], eax
mov eax, 0
jmp short .fn
..e1:
cmp ecx, 3
je .e0
..e2:
cmp edx, ' '
je .a4
cmp edx, 0
je .a4
cmp edx, 9
je .a4
cmp edx, 10
je .a4
cmp edx, '.'
je .a4
jmp short .e0

..a2:
lea ebx, [4*eax+eax]
sub edx, '0'
lea eax, [2*ebx]
add eax, edx
inc esi
dec ecx
jnz .a0

..a3:
mov dl, [esi]
jmp short .e2
..a4:
mov edx, [esp+20]
mov [edx], esi
..fn:
pop ecx
pop esi
pop edx
pop ebx
ret

; unsigned hexarr_to_u(char* dove, char* arr)
; legge numeri che sono considerati di base 16
; di al massimo tre cifre significative
; del tipo 0x123 oppure 0x0 oppure 0X1 oppure 0x12
; che hanno il terminatore '.' o '\n' o ' ' '\t'
; in caso di errore dove=arr; altrimenti
; dove punta al prossimo carattere non letto
; s=0c, 4i, 8r, 12b, 16ra, 20dove, 24arr
hexarr_to_u:
push ebx
push edx
push esi
push ecx
mov esi, [esp+24]
mov edx, 0
mov eax, 0
mov ecx, 3
cmp byte[esi], '0'
jne .e0
inc esi
cmp byte[esi], 'x'
je .h0
cmp byte[esi], 'X'
je .h0
jmp .e0
..h0:
inc esi
..a0:
mov dl, [esi]
..a1:
cmp edx, 'F'
ja .c0
cmp edx, 'A'
jb .c0
sub edx, 'A'
add edx, 10
jmp short .a2
..c0:
cmp edx, 'f'
ja .c1
cmp edx, 'a'
jb .c1
sub edx, 'a'
add edx, 10
jmp short .a2
..c1:
cmp edx, '9'
jg .e1
cmp edx, '0'
jl .e1
sub edx, '0'
jmp short .a2
..e0:
mov eax, [esp+24]
mov ebx, [esp+20]
mov [ebx], eax
mov eax, 0
jmp .fn
..e1:
cmp ecx, 3
je .e0
..e2:
cmp edx, ' '
je .a6
cmp edx, 0
je .a6
cmp edx, 9
je .a6
cmp edx, 10
je .a6
cmp edx, '.'
je .a6
jmp short .e0

..a2:
shl eax, 4
inc esi
add eax, edx
dec ecx
jnz .a0

..a3:
mov dl, [esi]
jmp short .e2
..a6:
mov edx, [esp+20]
mov [edx], esi
..fn:
pop ecx
pop esi
pop edx
pop ebx
ret


; ip_to_ul(dword* ris, dword* arr)
; trasforma un numero ip del tipo 0x23.023.123.123
; in un numero di 32 bit. i 4 campi devono essere
; separati *solo* da un punto, devono essere compresi
; tra 0 e 255 non possono avere zeri non significativi.
; I quattro campi possono essere dati come
; numero decimale (es. 125), esadecimale (es. 0x4, 0X9)
; ottottale (es. 012, 01, 0)
; k=0k, 4Ra, 8ris, 12arr
ip_to_ul:
push ebp
mov ebp, esp ; @w
sub esp, 32 ; 21..24 <32
push ebx
push ecx
push edx
push esi
push edi
%define @ris ebp+8
%define @arr ebp+12
%define @w ebp+24
mov esi, [@arr]
xor ebx, ebx
jmp short .c1
..c0:
inc esi
..c1:
mov bl, [esi]
cmp ebx, ' '
je .c0
cmp ebx, 9
je .c0

cmp bl, 0
jne .c2
..e0:
mov eax, [@ris]
mov dword[eax], 0
jmp .fn
..c2: ; c=1.2.3.4
mov ecx, 4
mov edx, 0
mov ebx, 0
..c3:
cmp byte[esi], '0'
jne .b0
cmp byte[esi+1], 'x'
je .a1
cmp byte[esi+1], 'X'
jne .a2
..a1:
lea eax, [@w]
push esi
push eax
call hexarr_to_u
add esp, 8
jmp short .c4
..a2:
lea eax, [@w]
push esi
push eax
call otto_to_u
add esp, 8
jmp short .c4
..b0:
lea eax, [@w]
push esi
push eax
call decarr_to_u
add esp, 8
..c4:
cmp esi, [@w]
je .e0
cmp eax, 255
ja .e0
shl ebx, 8
mov esi, [@w]
add ebx, eax
cmp ecx, 1
je .c5
cmp byte[esi], '.'
jne .e0
jmp short .c6
..c5:
cmp byte[esi], ' '
je .c7
cmp byte[esi], 10
je .c7
cmp byte[esi], 9
je .c7
jmp .e0
..c6:
inc esi
dec ecx
jmp .c3
..c7:
mov eax, [@ris]
mov dword[eax], 1
mov eax, ebx
..fn:
%undef @ris
%undef @arr
%undef @w
pop edi
pop esi
pop edx
pop ecx
pop ebx
mov esp, ebp
pop ebp
ret


; k= 0k, 4Ra, 8@argc, 12@argv
_main: ; foo[256], sp[4], w[4]

push ebp ; 11..266, 267..270, 271..274<512
mov ebp, esp
sub esp, 512
push ebx
push esi
push edi
%define @argc ebp+8
%define @argv ebp+12
%define @foo ebp-266
%define @w ebp-274
mov eax, 0
mov ebx, ebp
..l0:
mov byte[ebx], 0
inc eax
dec ebx
cmp eax, 400
jb .l0
..a0:
push Scrivi_numero_ip
call _printf
add esp, 4
lea eax, [@foo]
push __streams
push 256
push eax
call _fgets
add esp, 12
cmp eax, 0
jne .l4
..l1:
push Errore
call _printf
add esp, 4
jmp .fine
..l2:
push Errore_linea_troppo_lunga
call _printf
add esp, 4
jmp .fine
..l3:
push Errore_contenuto_linea
call _printf
add esp, 4
jmp .fine
..l4:
cmp byte[eax+254], 0
jne .l2
lea ebx, [@w]
push eax
push ebx
call ip_to_ul
add esp, 8
cmp dword[@w], 0
je .l3
cmp eax, 0
je .fine
push eax
push Numero_naturale_conversione_$u
call _printf
add esp, 8
jmp .l0
..fine:
mov eax, 0
%undef @argc
%undef @argv
%undef @foo
%undef @w
pop edi
pop esi
pop ebx
mov esp, ebp
pop ebp
ret
 
M

Mark McIntyre

On Sun, 05 Feb 2006 20:06:59 +0100, in comp.lang.c , RSoIsCaIrLiIoA

(more assembler)

Please stop x-posting assembler to comp.lang.c where it is violently
offtopic.
Mark McIntyre
 
S

SM Ryan

# in the origin was
#
# "ping 192.0xb2.031.249"

int convert(char *string,unsigned char *address,int length) {
int i; char *p,*q;
for (i=0,p=string; i<length && *p; i++,p=q) {
switch (*p) {
case ':': address = strtol(p,&q,16); break;
case '.': p++;
default:
if (!isdigit(*p)) return -1; /*component not a number*/
address = strtol(p,&q,0);
break;
}
if (p==q) return -2; /* malformed component*/
}
if (*p) return -3; /*string has too many components*/
return i;
}

long ip4pack(unsigned char *address /*length==4*/) {
int i; long a = 0;
for (i=0; i<4; i++) a = (a<<8)|address;
return htonl(a);
}
 
D

Dave Thompson

Traditionally, each octet is allowed to be in decimal, hex, or
octal, independent of each previous octet. To match "traditional
BSD semantics", make the strtoul() call above use base 0.

Yes, this means that you can "ping 192.0xb2.031.249". No, there
is no particularly good reason to do that -- and some implementations
do not allow it (but some spammers do depend on it to hide their
"real" IP addresses).
And if you mistakenly use a fixed format, as one app I worked on did,
extra-0 means octal and e.g. 192.168.010.077 produces results
different from what almost any sane person wants or expects.
(Traditional BSD libraries also allow the entire 32-bit address to
be given as a single number, but that requires more code, whereas
changing the last argument to strtoul() does not.)

Actually tradition allows 1.3 and 1.1.2 as well as 1.1.1.1 and 4.
These were originally intended for class A and B networks back when
(it was thought) addresses were actually going to be assigned that
way. IME spammers and other miscreants more often use these formats,
especially 4, than just hex-ed octets. Although it it used to amuse me
when they forged Received headers with e.g. 123.345.567.789.
("Used to" because nowadays I no longer bother looking.)

- David.Thompson1 at worldnet.att.net
 
J

John F

RSoIsCaIrLiIoA said:
in the origin was

"ping 192.0xb2.031.249"

it is for convert ip number like above; the number can be after each
point hexadecimal, decimal or octotal. you are right, i have not
'reduced' it; you are not the only one that like
small programs :))))))))

How about that function, I wrote it some time ago ... know what? it still
works :)

//doesn't need any library functions, pure C
//@param: IP: NULL-terminated string of the addy
unsigned long iptol(char* IP) {
char* runner=IP;
unsigned long factor=1;
unsigned long temp=0;
unsigned int reset=0;

//roll in to the last char...
while(*runner) runner++;

//seek dots from back to forth
while((IP - runner--)) {
if(*runner=='.') {
factor <<= 8;
reset=0;
runner--;
}
temp += (factor * (*(runner) - '0') *
(reset==1?10:(reset==2?100:1)));
reset++;
}
return temp;
}

It even does convert 10.10.10.10.10.10.10 and so on .... well some
intelligence could still be added.
 
R

RSoIsCaIrLiIoA

find this line
****************************************************************
in the origin was

"ping 192.0xb2.031.249"

it is for convert ip number like above; the number can be after each
point hexadecimal, decimal or octotal. you are right, i have not
'reduced' it; you are not the only one that like
small programs :))))))))

i have try to reduce but with no success
yes in this case i'm long: i add some comments
do you like my "spaghetti" code ? :))
how many people can write or read code like that?
(i thik for read only the cpu in .exe and nobody in conventional
assembly form)

; nasmw -f obj this_file.asm
; bcc32 this_file.obj

section _DATA public align=4 class=DATA use32

Scrivi_numero_ip db "Srivi un internet adr. > " , 0
Errore db "Errore" , 10 , 0
Errore1 db "Errore" , 0
Errore_linea_troppo_lunga db "Errore linea troppo lunga" , 0
Numero_naturale_conversione_$u
db "Numero naturale conversione %u" , 10 , 0
Errore_contenuto_linea db "Errore contenuto linea" , 10 , 0

$lf db "%lf" , 0
errno_u_$i db "errno=%i " , 0
$u_$u db " <%u %u> " , 0
$i_p$i_p$i_p$i db " %d.%d.%d.%d%*[^" , 10 , "]" , 0
val db 0

extern _printf , _errno , _sscanf , _fgets
extern _perror , __streams , _isspace
global _main

section _TEXT public align=1 class=CODE use32


; unsigned otto_to_u(char* dove, char* arr)
; legge numeri che sono considerati di base 8
; di al massimo tre cifre significative
; del tipo 0123 oppure 0 oppure 01 oppure 012
; che hanno il terminatore '.' o '\n' o ' ' o '\t'
; in caso di errore 'dove'='arr'; altrimenti
; 'dove' punta al prossimo carattere non letto
; s=0c, 4i, 8r, 12b, 16ra, 20dove, 24arr
otto_to_u:
push ebx
push edx
push esi
push ecx
mov esi, [esp+24]
mov edx, 0
mov eax, 0
mov ecx, 3
cmp byte[esi], '0'
jne .e0
inc esi
..a0:
mov dl, [esi]
..a1:
cmp edx, '7'
jg .e1
cmp edx, '0'
jl .e1
jmp short .a2
..e0:
mov eax, [esp+24]
mov ebx, [esp+20]
mov [ebx], eax
mov eax, 0
jmp short .fn
..e1: ; 9=TAB
cmp edx, ' '
je .a4
cmp edx, 10
je .a4
cmp edx, 9
je .a4
cmp edx, 0
je .a4
cmp edx, '.'
je .a4
jmp short .e0

..a2:
shl eax, 3
sub edx, '0'
add eax, edx
inc esi
dec ecx
jnz .a0

..a3:
mov dl, [esi]
jmp short .e1
..a4:
mov edx, [esp+20]
mov [edx], esi
..fn:
pop ecx
pop esi
pop edx
pop ebx
ret



; unsigned decarr_to_u(char* dove, char* arr)
; legge numeri che sono considerati di base 10
; di al massimo tre cifre significative
; [del tipo 123 oppure 1 oppure 12]
; che hanno il terminatore '.' o '\n' o ' ' o '\t'
; in caso di errore 'dove'='arr'; altrimenti
; 'dove' punta al prossimo carattere non letto
; s=0c, 4i, 8r, 12b, 16ra, 20dove, 24arr
decarr_to_u:
push ebx
push edx
push esi
push ecx
mov esi, [esp+24]
mov edx, 0
mov eax, 0
mov ecx, 3
..a0:
mov dl, [esi]
..a1:
cmp edx, '9'
jg .e1
cmp edx, '0'
jl .e1
jmp short .a2
..e0:
mov eax, [esp+24]
mov ebx, [esp+20]
mov [ebx], eax
mov eax, 0
jmp short .fn
..e1:
cmp ecx, 3
je .e0
..e2:
cmp edx, ' '
je .a4
cmp edx, 0
je .a4
cmp edx, 9
je .a4
cmp edx, 10
je .a4
cmp edx, '.'
je .a4
jmp short .e0

..a2:
lea ebx, [4*eax+eax]
sub edx, '0'
lea eax, [2*ebx]
add eax, edx
inc esi
dec ecx
jnz .a0

..a3:
mov dl, [esi]
jmp short .e2
..a4:
mov edx, [esp+20]
mov [edx], esi
..fn:
pop ecx
pop esi
pop edx
pop ebx
ret

; unsigned hexarr_to_u(char* dove, char* arr)
; legge numeri che sono considerati di base 16
; di al massimo tre cifre significative
; del tipo 0x123 oppure 0x0 oppure 0X1 oppure 0x12
; che hanno il terminatore '.' o '\n' o ' ' '\t'
; in caso di errore dove=arr; altrimenti
; dove punta al prossimo carattere non letto
; s=0c, 4i, 8r, 12b, 16ra, 20dove, 24arr
hexarr_to_u:
push ebx
push edx
push esi
push ecx
mov esi, [esp+24]
mov edx, 0
mov eax, 0
mov ecx, 3
cmp byte[esi], '0'
jne .e0
inc esi
cmp byte[esi], 'x'
je .h0
cmp byte[esi], 'X'
je .h0
jmp .e0
..h0:
inc esi
..a0:
mov dl, [esi]
..a1:
cmp edx, 'F'
ja .c0
cmp edx, 'A'
jb .c0
sub edx, 'A'
add edx, 10
jmp short .a2
..c0:
cmp edx, 'f'
ja .c1
cmp edx, 'a'
jb .c1
sub edx, 'a'
add edx, 10
jmp short .a2
..c1:
cmp edx, '9'
jg .e1
cmp edx, '0'
jl .e1
sub edx, '0'
jmp short .a2
..e0:
mov eax, [esp+24]
mov ebx, [esp+20]
mov [ebx], eax
mov eax, 0
jmp .fn
..e1:
cmp ecx, 3
je .e0
..e2:
cmp edx, ' '
je .a6
cmp edx, 0
je .a6
cmp edx, 9
je .a6
cmp edx, 10
je .a6
cmp edx, '.'
je .a6
jmp short .e0

..a2:
shl eax, 4
inc esi
add eax, edx
dec ecx
jnz .a0

..a3:
mov dl, [esi]
jmp short .e2
..a6:
mov edx, [esp+20]
mov [edx], esi
..fn:
pop ecx
pop esi
pop edx
pop ebx
ret


; ip_to_ul(dword* ris, dword* arr)
; trasforma un numero ip del tipo 0x23.023.123.123
; in un numero di 32 bit. i 4 campi devono essere
; separati *solo* da un punto, devono essere compresi
; tra 0 e 255 non possono avere zeri non significativi.
; I quattro campi possono essere dati come
; numero decimale (es. 125), esadecimale (es. 0x4, 0X9)
; ottottale (es. 012, 01, 0)
; k=0k, 4Ra, 8ris, 12arr
ip_to_ul:
push ebp
mov ebp, esp ; @w
sub esp, 32 ; 21..24 <32
push ebx
push ecx
push edx
push esi
push edi
%define @ris ebp+8
%define @arr ebp+12
%define @w ebp+24
*********************************************
this should be
"%define @w ebp-24 "
*********************************************
mov esi, [@arr]
xor ebx, ebx
jmp short .c1
..c0:
inc esi
..c1:
mov bl, [esi]
cmp ebx, ' '
je .c0
cmp ebx, 9
je .c0

cmp bl, 0
jne .c2
..e0:
mov eax, [@ris]
mov dword[eax], 0
jmp .fn
..c2: ; c=1.2.3.4
mov ecx, 4
mov edx, 0
mov ebx, 0
..c3:
cmp byte[esi], '0'
jne .b0
cmp byte[esi+1], 'x'
je .a1
cmp byte[esi+1], 'X'
jne .a2
..a1:
lea eax, [@w]
push esi
push eax
call hexarr_to_u
add esp, 8
jmp short .c4
..a2:
lea eax, [@w]
push esi
push eax
call otto_to_u
add esp, 8
jmp short .c4
..b0:
lea eax, [@w]
push esi
push eax
call decarr_to_u
add esp, 8
..c4:
cmp esi, [@w]
je .e0
cmp eax, 255
ja .e0
shl ebx, 8
mov esi, [@w]
add ebx, eax
cmp ecx, 1
je .c5
cmp byte[esi], '.'
jne .e0
jmp short .c6
..c5:
cmp byte[esi], ' '
je .c7
cmp byte[esi], 10
je .c7
cmp byte[esi], 9
je .c7
jmp .e0
..c6:
inc esi
dec ecx
jmp .c3
..c7:
mov eax, [@ris]
mov dword[eax], 1
mov eax, ebx
..fn:
%undef @ris
%undef @arr
%undef @w
pop edi
pop esi
pop edx
pop ecx
pop ebx
mov esp, ebp
pop ebp
ret


; k= 0k, 4Ra, 8@argc, 12@argv
_main: ; foo[256], sp[4], w[4]

push ebp ; 11..266, 267..270, 271..274<512
mov ebp, esp
sub esp, 512
push ebx
push esi
push edi
%define @argc ebp+8
%define @argv ebp+12
%define @foo ebp-266
%define @w ebp-274
mov eax, 0
mov ebx, ebp
..l0:
mov byte[ebx], 0
inc eax
dec ebx
cmp eax, 400
jb .l0
..a0:
push Scrivi_numero_ip
call _printf
add esp, 4
lea eax, [@foo]
push __streams
push 256
push eax
call _fgets
add esp, 12
cmp eax, 0
jne .l4
..l1:
push Errore
call _printf
add esp, 4
jmp .fine
..l2:
push Errore_linea_troppo_lunga
call _printf
add esp, 4
jmp .fine
..l3:
push Errore_contenuto_linea
call _printf
add esp, 4
jmp .fine
..l4:
cmp byte[eax+254], 0
jne .l2
lea ebx, [@w]
push eax
push ebx
call ip_to_ul
add esp, 8
cmp dword[@w], 0
je .l3
cmp eax, 0
je .fine
push eax
push Numero_naturale_conversione_$u
call _printf
add esp, 8
jmp .l0
..fine:
mov eax, 0
%undef @argc
%undef @argv
%undef @foo
%undef @w
pop edi
pop esi
pop ebx
mov esp, ebp
pop ebp
ret
 
M

Martin Ambuhl

RSoIsCaIrLiIoA wrote:
Whatever possessed you to post this stuff
; nasmw -f obj this_file.asm
; bcc32 this_file.obj

section _DATA public align=4 class=DATA use32

Scrivi_numero_ip db "Srivi un internet adr. > " , 0

[etc. for 489 lines]

to < It may well be that <welcomes
such longish postings of code, but please remove CLC from your
crossposting. Your post is obviously off-topic in CLC and unwelcome.
{FWUPs set]
 
C

CBFalconer

Martin said:
RSoIsCaIrLiIoA wrote:

Whatever possessed you to post this stuff
; nasmw -f obj this_file.asm
; bcc32 this_file.obj

section _DATA public align=4 class=DATA use32

Scrivi_numero_ip db "Srivi un internet adr. > " , 0

[etc. for 489 lines]

to < It may well be that <welcomes such longish postings of code, but please remove CLC
from your crossposting. Your post is obviously off-topic in CLC
and unwelcome. {FWUPs set]

It's all in the sig.

--

+-------------------+ .:\:\:/:/:.
| PLEASE DO NOT F :.:\:\:/:/:.:
| FEED THE TROLLS | :=.' - - '.=:
| | '=(\ 9 9 /)='
| Thank you, | ( (_) )
| Management | /`-vvv-'\
+-------------------+ / \
| | @@@ / /|,,,,,|\ \
| | @@@ /_// /^\ \\_\
@x@@x@ | | |/ WW( ( ) )WW
\||||/ | | \| __\,,\ /,,/__
\||/ | | | jgs (______Y______)
/\/\/\/\/\/\/\/\//\/\\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
==============================================================

fix (vb.): 1. to paper over, obscure, hide from public view; 2.
to work around, in a way that produces unintended consequences
that are worse than the original problem. Usage: "Windows ME
fixes many of the shortcomings of Windows 98 SE". - Hutchison
 
R

Robert Redelmeier

In alt.lang.asm RSoIsCaIrLiIoA said:
in the origin was

"ping 192.0xb2.031.249"

it is for convert ip number like above; the number can be after each
point hexadecimal, decimal or octotal. you are right, i have not
'reduced' it; you are not the only one that like
small programs :))))))))

i have try to reduce but with no success [snippage]:
$i_p$i_p$i_p$i db " %d.%d.%d.%d%*[^" , 10 , "]" , 0
extern _printf , _errno , _sscanf , _fgets


Is this some sort of homework assignment?
If you're going to use sscanf(), why not use the %i
conversion that will do the hex, octal & decimal?

Something like [untested]:

call_entry:
push d
push c
push b
push a
push fmt
push input_string
call sscanf

add esp, 20
mov eax, [a]
shl eax, 4
add eax,
shl eax, 4
add eax, [c]
shl eax, 4
add eax, [d]
ret

fmt db " %i.%i.%i.%i"

Add error checking to taste (not more than 7 instructions) :)

-- Robert
 
V

Vladimir Oka

--

+-------------------+ .:\:\:/:/:.
| PLEASE DO NOT F :.:\:\:/:/:.:
| FEED THE TROLLS | :=.' - - '.=:
| | '=(\ 9 9 /)='
| Thank you, | ( (_) )
| Management | /`-vvv-'\
+-------------------+ / \
| | @@@ / /|,,,,,|\ \
| | @@@ /_// /^\ \\_\
@x@@x@ | | |/ WW( ( ) )WW
\||||/ | | \| __\,,\ /,,/__
\||/ | | | jgs (______Y______)
/\/\/\/\/\/\/\/\//\/\\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
==============================================================
 
V

void * clvrmnky()

Vladimir said:
--

+-------------------+ .:\:\:/:/:.
| PLEASE DO NOT F :.:\:\:/:/:.:
| FEED THE TROLLS | :=.' - - '.=:
| | '=(\ 9 9 /)='
| Thank you, | ( (_) )
| Management | /`-vvv-'\
+-------------------+ / \
| | @@@ / /|,,,,,|\ \
| | @@@ /_// /^\ \\_\
@x@@x@ | | |/ WW( ( ) )WW
\||||/ | | \| __\,,\ /,,/__
\||/ | | | jgs (______Y______)
/\/\/\/\/\/\/\/\//\/\\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
==============================================================
[OT]
I'm pretty sure that trolls practise cannibalism. So this warning is
likely just as much food as any shorter reply.
 
R

Robert Redelmeier

In alt.lang.asm Vladimir Oka said:
| PLEASE DO NOT F :.:\:\:/:/:.:
| FEED THE TROLLS | :=.' - - '.=:

What do you consider a troll?
I suspect we have very different definitions.

-- Robert
 
K

Keith Thompson

Robert Redelmeier said:
What do you consider a troll?
I suspect we have very different definitions.

One example: someone who posts large amounts of assembly code to
comp.lang.c.
 
R

Robert Redelmeier

In alt.lang.asm Keith Thompson said:
One example: someone who posts large amounts of assembly
code to comp.lang.c.

Poor assembly, I would add.

But that is _not_ troll behaviour in ALA,
where I read (see quote line).

-- Robert
 
I

Ian Collins

Robert said:
Poor assembly, I would add.

But that is _not_ troll behaviour in ALA,
where I read (see quote line).
Just look back through the OP's postings to c.l.c and form your own opinion.
 
R

Robert Redelmeier

In alt.lang.asm Ian Collins said:
Just look back through the OP's postings to c.l.c and form
your own opinion.

I could, but this would require me to understand CLC.

-- Robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top