flat assembler
Message board for the users of flat assembler.

Index > Main > Convert C types to assembly

Author
Thread Post new topic Reply to topic
Patrick_



Joined: 11 Mar 2006
Posts: 53
Location: 127.0.0.1
Patrick_ 16 Apr 2006, 18:42
I'm still learning assembly, and even so, it's my new favorite language. Smile Anyway, I'm not quite sure how I'd convert the following data-types to assembly. I have a general idea, but I get errors from fasm. Here are the ones I am interested in converting:

Code:
struct hostent {
    char    *h_name;
    char    **h_aliases;
    int     h_addrtype;
    int     h_length;
    char    **h_addr_list;
};

struct sockaddr_in {
    short int          sin_family;  
    unsigned short int sin_port;    
    struct in_addr     sin_addr;    
    unsigned char      sin_zero[8]; 
};    


Any help appreciated. Thanks!
Post 16 Apr 2006, 18:42
View user's profile Send private message Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner 16 Apr 2006, 19:08
hi patrick
if you take a look on your fasm installed directory, assume c:\fasm
c:\fasm\include\EQUATES\WSOCK32.INC

you would be able to see the following :
Code:
struct hostent
  h_name      dd ?
  h_aliases   dd ?
  h_addrtype  dw ?
  h_length    dw ?
  h_addr_list dd ?
ends

struct sockaddr_in
  sin_family dw ?
  sin_port   dw ?
  sin_addr   dd ?
  sin_zero   db 8 dup (?)
ends
    


if possible, plez take a look on this example.
http://flatassembler.net/examples/quetannon.zip
Quetannon
Demonstration of using WinSock library to make TCP/IP connections.
Written by Tomasz Grysztar.
Post 16 Apr 2006, 19:08
View user's profile Send private message Visit poster's website Reply with quote
Patrick_



Joined: 11 Mar 2006
Posts: 53
Location: 127.0.0.1
Patrick_ 16 Apr 2006, 21:39
Wow, thanks, I never thought to look in there. I will now. Smile
Post 16 Apr 2006, 21:39
View user's profile Send private message Reply with quote
RedGhost



Joined: 18 May 2005
Posts: 443
Location: BC, Canada
RedGhost 17 Apr 2006, 05:57
vbVeryBeginner wrote:
hi patrick
if you take a look on your fasm installed directory, assume c:\fasm
c:\fasm\include\EQUATES\WSOCK32.INC

you would be able to see the following :
Code:
struct hostent
  h_name      dd ?
  h_aliases   dd ?
  h_addrtype  dw ?
  h_length    dw ?
  h_addr_list dd ?
ends

struct sockaddr_in
  sin_family dw ?
  sin_port   dw ?
  sin_addr   dd ?
  sin_zero   db 8 dup (?)
ends
    


if possible, plez take a look on this example.
http://flatassembler.net/examples/quetannon.zip
Quetannon
Demonstration of using WinSock library to make TCP/IP connections.
Written by Tomasz Grysztar.



int would be dw on DOS
int would be dd on windows XP

don't know what OS this is for

_________________
redghost.ca
Post 17 Apr 2006, 05:57
View user's profile Send private message AIM Address MSN Messenger Reply with quote
UCM



Joined: 25 Feb 2005
Posts: 285
Location: Canada
UCM 17 Apr 2006, 12:59
its for Windows (all 32-bit versions)
if you do some research `short' always means 16 bits
Post 17 Apr 2006, 12:59
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 17 Apr 2006, 18:24
Code:
printf("%d\n",sizeof(char));
printf("%d\n",sizeof(short));
printf("%d\n",sizeof(int));
printf("%d\n",sizeof(long));
printf("%d\n",sizeof(void*)); // all pointers are of same size, unless "far" operator is used    
Post 17 Apr 2006, 18:24
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Patrick_



Joined: 11 Mar 2006
Posts: 53
Location: 127.0.0.1
Patrick_ 18 Apr 2006, 21:45
vid: my problem wasn't with simple data types, such as int, long, char; it was with data-type declarations such as "char **var", "char *var[100]", etc. Smile
Post 18 Apr 2006, 21:45
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 18 Apr 2006, 22:33
pointer is always dword. o if you have (anything)* it is always dword, holding addres of that anything. For example char*, is dword holding addres of char, or int** is dword holding address of int*, which is dword holding address of int. (anything)[] is just the same as (anything)*, so you treat it same.

in C there is alot confusion with types, you'll have to get it by time.

Code:
;char *a = "abcdefg";
;char *b = "xyz";
a db "abcdeg",0
b db "xyz",0
;char *c[2] = {a,b};
c dd a, b    


in short, in assembly you only know you have a dword value, but compiler doesn't know if it is number or pointer to something, and there also don't know what it is pointing to, it's up to you to handle it correct. In assembly only types are byte, word, dword etc. Less abstraction, like it or not :]
Post 18 Apr 2006, 22:33
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.