Re: Linux / NASM equivalent of Iczelion's Win32 assembly tut's
- From: Herbert Kleebauer <klee@xxxxxxxxx>
- Date: Fri, 07 Mar 2008 10:41:40 +0100
Frank Kotler wrote:
Herbert came back claiming this was "better readable":
/**********************************************************************************/
main()
{char name[80];
putstring ("Please tell me your name? ");
getstring (79,name);
putstring ("Hello, ");
putstring (name);
putstring ( "! Welcome to Linux Assembly!\n");
}
putstring(s) char *s;
{while (*s) putchar(*s++);}
getstring(i,s) int i; char *s;
{int j; for (j=0; j<i; j++) if ((*s++ = getchar())=='\n') {s--; break;} *s=0;}
/**********************************************************************************/
I claim that this is a "preconceived notion". Swahili is "more readable"
to a native Swahili speaker, I imagine. I don't doubt that this is
"readable" to a "C speaker". Only Rosario could love those last couple
lines, but the first part is pretty "readable", even to the "naive reader".
The "readabilty" was about "main" and not the subroutines "putstring/getstring".
To make the essential readable, you has to hide the unimportant in as less as
possible lines.
If I wanted to make the subroutines "readable for an assembly programmer",
I would have written:
main()
{char name[80];
putstring ("Please tell me your name? ");
getstring (79,name);
putstring ("Hello, ");
putstring (name);
putstring ( "! Welcome to Linux Assembly!\n");
}
putstring(text) char *text;
{int pos=0;
loop1:
if (text[pos]==0) return;
putchar(text[pos]);
pos=pos+1;
goto loop1;
}
getstring(max,name) int max; char *name;
{int pos=0;
char c;
loop2:
c=getchar();
if (c=='\n') {name[pos]=0; return;}
name[pos]=c;
pos=pos+1;
if (pos <= max) goto loop2;
name[pos]=0;
}
We can write macros that make asm "look more like C". I could do:
sys_write stdout, prompt, prompt_len
sys_read stdin, name, MAXNAME
mov [name_len], eax
sys_write stdout, greet, greet_len
sys_write stdout, name, dword [name_len]
sys_write stdout, coda, coda_len
Sure you can, but what sense does it make? If you want it to look like a
HLL, why don't you use a HLL?
.
- Follow-Ups:
- Re: Linux / NASM equivalent of Iczelion's Win32 assembly tut's
- From: Frank Kotler
- Re: Linux / NASM equivalent of Iczelion's Win32 assembly tut's
- References:
- Linux / NASM equivalent of Iczelion's Win32 assembly tut's
- From: Pop Tart
- Re: Linux / NASM equivalent of Iczelion's Win32 assembly tut's
- From: Herbert Kleebauer
- Re: Linux / NASM equivalent of Iczelion's Win32 assembly tut's
- From: Pop Tart
- Re: Linux / NASM equivalent of Iczelion's Win32 assembly tut's
- From: Frank Kotler
- Re: Linux / NASM equivalent of Iczelion's Win32 assembly tut's
- From: Pop Tart
- Re: Linux / NASM equivalent of Iczelion's Win32 assembly tut's
- From: Frank Kotler
- Re: Linux / NASM equivalent of Iczelion's Win32 assembly tut's
- From: Herbert Kleebauer
- Re: Linux / NASM equivalent of Iczelion's Win32 assembly tut's
- From: Frank Kotler
- Re: Linux / NASM equivalent of Iczelion's Win32 assembly tut's
- From: Herbert Kleebauer
- Re: Linux / NASM equivalent of Iczelion's Win32 assembly tut's
- From: Frank Kotler
- Re: Linux / NASM equivalent of Iczelion's Win32 assembly tut's
- From: Frank Kotler
- Re: Linux / NASM equivalent of Iczelion's Win32 assembly tut's
- From: Rod Pemberton
- Re: Linux / NASM equivalent of Iczelion's Win32 assembly tut's
- From: Frank Kotler
- Linux / NASM equivalent of Iczelion's Win32 assembly tut's
- Prev by Date: Re: Linux / NASM equivalent of Iczelion's Win32 assembly tut's
- Next by Date: Re: for the close of all fission nuclear reactor in the world
- Previous by thread: Re: Linux / NASM equivalent of Iczelion's Win32 assembly tut's
- Next by thread: Re: Linux / NASM equivalent of Iczelion's Win32 assembly tut's
- Index(es):