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_
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
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_
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
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
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
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_
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
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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.