Do you like this itoa1()? 
Author Message
 Do you like this itoa1()?

Do you like this itoa1()?

org 100h
 mov  ax, $+3
 push  ax
 push num
 call  itoa1
 add  sp, 4
 push  msbp
 call  puts_out
 add sp, 2
 push  num
 call  puts
 add  sp, 2
 mov  di, array
 add  di, 2
 mov  cx, 1
 lab:
   mov   ax, [di]
   push  ax
   push  ax
   push num
   call  itoa1
   add  sp, 4
   push  num
   call  puts_out
   add  sp, 2
   call  car_s
   test cx, 0x7
   jne  via
   call  acapo
  via:
   inc  cx
   add  di, 2
   pop ax
   or  ax, ax
   jnz lab

exit:
mov ax, 4C00h
int 21h

putc_out:
 push bx
    mov  bx, 7
    mov  ah, 14
    int 10h
 pop bx
 ret

getc_in_dos:
 mov  ah,  8
 int 21h
 ret

getc_in:
 mov  ah,  0
 int 16h
 ret

car_s:
 push ax
   mov  al, ' '
   call putc_out
 pop ax
 ret

acapo:
 push ax
   mov al,13
   call putc_out
   mov al,10
   call putc_out
 pop ax
 ret

; stampa senza \n
; int /* numero di caratteri stampati */ puts_out(char* );
puts_out:
 push  bp
 mov   bp, sp
 push  bx
 push  si
   mov  si,[bp +  4]
   mov  bx,si
   label_1:  
     mov  al,[si]  
     cmp  al,0
     je   fuori_1
     call putc_out
     inc  si
     jnz  label_1
  fuori_1:
   sub  si,bx
   mov ax,si
 pop  si
 pop  bx
 mov   sp, bp
 pop  bp
 ret

; int /* numero di caratteri stampati */ puts(char* );
puts:
 push  bp
 mov   bp, sp
 push  bx
 push  si
   mov  si,  [bp +  4]
   mov  bx, si
   label4:  
     mov  al, [si]  
     cmp  al, 0
     je fuori4
     call putc_out
     inc  si
     jnz  label4
  fuori4:
   mov   al, 10
   call  putc_out
   sub  si, bx
   inc  si  
   mov   ax, si
 pop  si
 pop  bx
 mov   sp, bp
 pop  bp
 ret

; char*  itoa1(unsigned , char* )
itoa1:
 push  bp
 mov   bp, sp
 push  dx
 push  bx
 push  di
 push  cx
   mov  di, [bp +  4]
   mov  ax, [bp +  6]
   cmp  ax, 255
   ja l2i
   mov   dl, 10
   mov  dh, 0
   l_2i:
      div   dl
      add ah, '0'
      mov  bl, ah
      push  bx
      inc dh
      or al, al
      jz   l2_2i
      xor ah, ah
      jmp  l_2i
   l2_2i:
      pop  ax
      mov [di], al
      inc  di
      dec  dh
      jnz  l2_2i
   jmp  end2i
  l2i:
   mov  bx, 10
   xor  dx, dx
   mov  ch, 0
   ri2i:
     div   bx
     add  dl, '0'
     mov  cl, dl
     push  cx
     inc ch
     or ax, ax
     jz esci2i
     xor dx, dx    
     jmp  ri2i
   esci2i:
     pop  ax
     mov [di], al
     inc  di
     dec  ch
     jnz  esci2i
  end2i:
   mov  byte  [di], 0
 pop  cx
 pop  di
 pop  bx
 pop  dx
 mov   sp, bp
 pop  bp
 ret

num  db  0, 0, 0, 0, 0, 0, 0, 0, 0
msbp db  "ip=", 0
array dw  34, 7952, 42720, 56941, 47825,     3,  4829, 32133,  29787,\
              7028,     2, 46128, 34856, 63646, 21032, 62660,  61244,\
             35057, 36989, 43989, 46043, 48547, 43704, 29749,     98,\
              3633, 50349, 33655, 36965, 48566,    43, 15168,  78001,\
             30425,  8425,   83,    625, 23789, 37438, 64887,     91,\
             19015, 43108, 61545, 24901, 58349, 52290, 62047,   3435,\
               173,    55, 27851, 47955, 14377, 14434,    55,      0



Fri, 01 Jul 2005 18:57:31 GMT  
 Do you like this itoa1()?

Quote:

> Do you like this itoa1()?

No :-)

Quote:
> org 100h

   You probably wanted to put a label here and let linker know that
it's a main module.

Quote:
>  mov  ax, $+3

   Where do you use this?

Quote:
>  push  ax
>  push num
>  call  itoa1
>  add  sp, 4

   I don't think that C calling convention is a good choice for a COM
program written in assembly. Why not use your own register-based
convention?

Quote:
>  push  msbp
>  call  puts_out
>  add sp, 2
>  push  num
>  call  puts
>  add  sp, 2
>  mov  di, array
>  add  di, 2
>  mov  cx, 1
>  lab:
>    mov   ax, [di]
>    push  ax
>    push  ax
>    push num
>    call  itoa1
>    add  sp, 4
>    push  num
>    call  puts_out
>    add  sp, 2
>    call  car_s
>    test cx, 0x7
>    jne  via
>    call  acapo
>   via:
>    inc  cx
>    add  di, 2
>    pop ax
>    or  ax, ax
>    jnz lab

> exit:
> mov ax, 4C00h
> int 21h

> putc_out:
>  push bx
>     mov  bx, 7
>     mov  ah, 14

   I think it's simple (and therefore better) to add "MOV CX, 1" here
rather than struggling to keep CX = 1 through all your program.

- Show quoted text -

Quote:
>     int 10h
>  pop bx
>  ret

> getc_in_dos:
>  mov  ah,  8
>  int 21h
>  ret

> getc_in:
>  mov  ah,  0
>  int 16h
>  ret

> car_s:
>  push ax
>    mov  al, ' '
>    call putc_out
>  pop ax

   I know that they say a programmer of a subroutine should always
preserve registers, but it's only valid when you provide an interface
to external modules. Especially since you use stack-based parameters.

- Show quoted text -

Quote:
>  ret

> acapo:
>  push ax
>    mov al,13
>    call putc_out
>    mov al,10
>    call putc_out
>  pop ax
>  ret

> ; stampa senza \n
> ; int /* numero di caratteri stampati */ puts_out(char* );
> puts_out:
>  push  bp
>  mov   bp, sp
>  push  bx
>  push  si
>    mov  si,[bp +  4]
>    mov  bx,si
>    label_1:  
>      mov  al,[si]  

   You limit your program to DS == SS (if you'll want to use this code
somewhere else).

- Show quoted text -

Quote:
>      cmp  al,0
>      je   fuori_1
>      call putc_out
>      inc  si
>      jnz  label_1
>   fuori_1:
>    sub  si,bx
>    mov ax,si
>  pop  si
>  pop  bx
>  mov   sp, bp
>  pop  bp
>  ret

> ; int /* numero di caratteri stampati */ puts(char* );
> puts:
>  push  bp
>  mov   bp, sp
>  push  bx
>  push  si
>    mov  si,  [bp +  4]
>    mov  bx, si
>    label4:  
>      mov  al, [si]  
>      cmp  al, 0
>      je fuori4
>      call putc_out
>      inc  si
>      jnz  label4
>   fuori4:
>    mov   al, 10
>    call  putc_out
>    sub  si, bx
>    inc  si  
>    mov   ax, si
>  pop  si
>  pop  bx
>  mov   sp, bp
>  pop  bp
>  ret

> ; char*  itoa1(unsigned , char* )
> itoa1:
>  push  bp
>  mov   bp, sp
>  push  dx
>  push  bx
>  push  di
>  push  cx
>    mov  di, [bp +  4]
>    mov  ax, [bp +  6]
>    cmp  ax, 255
>    ja l2i
>    mov   dl, 10
>    mov  dh, 0
>    l_2i:
>       div   dl
>       add ah, '0'
>       mov  bl, ah
>       push  bx
>       inc dh
>       or al, al
>       jz   l2_2i
>       xor ah, ah
>       jmp  l_2i
>    l2_2i:
>       pop  ax
>       mov [di], al
>       inc  di
>       dec  dh
>       jnz  l2_2i
>    jmp  end2i
>   l2i:
>    mov  bx, 10
>    xor  dx, dx
>    mov  ch, 0
>    ri2i:
>      div   bx
>      add  dl, '0'
>      mov  cl, dl
>      push  cx
>      inc ch
>      or ax, ax
>      jz esci2i
>      xor dx, dx    
>      jmp  ri2i
>    esci2i:
>      pop  ax
>      mov [di], al
>      inc  di
>      dec  ch
>      jnz  esci2i
>   end2i:
>    mov  byte  [di], 0
>  pop  cx
>  pop  di
>  pop  bx
>  pop  dx
>  mov   sp, bp
>  pop  bp
>  ret

> num  db  0, 0, 0, 0, 0, 0, 0, 0, 0
> msbp db  "ip=", 0
> array dw  34, 7952, 42720, 56941, 47825,     3,  4829, 32133,  29787,\
>               7028,     2, 46128, 34856, 63646, 21032, 62660,  61244,\
>              35057, 36989, 43989, 46043, 48547, 43704, 29749,     98,\
>               3633, 50349, 33655, 36965, 48566,    43, 15168,  78001,\
>              30425,  8425,   83,    625, 23789, 37438, 64887,     91,\
>              19015, 43108, 61545, 24901, 58349, 52290, 62047,   3435,\
>                173,    55, 27851, 47955, 14377, 14434,    55,      0

   Anyway, if it works personally I like it :)

/BP



Sat, 02 Jul 2005 01:33:29 GMT  
 Do you like this itoa1()?

Do you like more reverse() or reverse1()?

; char*  reverse(char* )
reverse:
 push  bp
 mov   bp, sp
 push  di
 push  si
 push  bx
     mov  di,[bp +  4]
     mov  si, di
     r_1_9:
         cmp byte [si],0
         je  r_2_9
         inc si
         jmp r_1_9
r_2_9:
     dec  si
     r_3_9:
         cmp   si, di
         jbe   r_4_9
         mov   al,[si]
         mov   bl,[di]
         mov  [si],bl
         mov  [di],al
         inc   di
         dec   si
         jmp r_3_9
r_4_9:
     mov  ax, [bp +  4]
 pop  bx
 pop  si
 pop  di
 mov   sp, bp
 pop  bp
 ret

; char*  reverse1(char* )
reverse1:
 push  bp
 mov   bp, sp
 push  si
 push  bx
    mov  si,[bp +  4]
    cmp  si, 0
    je end_rev
    mov  bh, 0
    push_rev:
      mov  bl, [si]
      cmp  bl, 0
      je  f_rev
      push  bx
      inc  si
      inc  bh
      jmp  push_rev
    f_rev:
    cmp  bh, 0
    je h_rev
    mov  si, [bp +  4]
    pop_rev:
      pop  ax
      mov  [si], al
      inc   si
      dec   bh
      jnz   pop_rev
   h_rev:
   mov  ax, [bp +  4]
   jmp  en_rev
   end_rev:
   mov  ax, 0
   en_rev:
 pop  bx
 pop  si
 mov  sp, bp
 pop  bp
 ret



Sat, 02 Jul 2005 03:47:09 GMT  
 Do you like this itoa1()?

Quote:


>> Do you like this itoa1()?
>No :-)
>> org 100h

>   You probably wanted to put a label here and let linker know that
>it's a main module.

label_start:

Quote:
>>  mov  ax, $+3

>   Where do you use this?

here, push ax

Quote:
>>  push  ax
>>  push num
>>  call  itoa1
>>  add  sp, 4

in char* num there is ax 'string' number

Quote:
>   I don't think that C calling convention is a good choice for a COM
>program written in assembly.

Why not?

Quote:
>Why not use your own register-based convention?

e.g.
; ax  funct(bx, ch)
funct:
 push  dx
 to_do_with_bx_and_ch_and_ax_and_dx
 pop   dx
 ret
?

Quote:
>> putc_out:
>>  push bx
>>     mov  bx, 7
>>     mov  ah, 14

>   I think it's simple (and therefore better) to add "MOV CX, 1" here
>rather than struggling to keep CX = 1 through all your program.

I've found this:
_______________________________________________________________
INT 10H Function 0EH Write Text in Teletype mode
Writes an ASCII character to the display at the current cursor
position, using the specified
colour (if in graphics mode), then increments the cursor position.
_______________________________________________________________
Register Call                           Value Return Value
AH 0EH
AL ASCII value
BH screen page
BL foreground colour in graphics mode
_______________________________________________________________
for this, cx would not be changed from putc_out

Quote:
>>     int 10h
>>  pop bx
>>  ret

>> getc_in_dos:
>>  mov  ah,  8
>>  int 21h
>>  ret

>> getc_in:
>>  mov  ah,  0
>>  int 16h
>>  ret

>> car_s:
>>  push ax
>>    mov  al, ' '
>>    call putc_out
>>  pop ax

>   I know that they say a programmer of a subroutine should always
>preserve registers, but it's only valid when you provide an interface
>to external modules. Especially since you use stack-based parameters.

so, do you say:
car_s:
 mov  al, ' '
 call putc_out
 ret
?

- Show quoted text -

Quote:
>>  ret

>> acapo:
>>  push ax
>>    mov al,13
>>    call putc_out
>>    mov al,10
>>    call putc_out
>>  pop ax
>>  ret

>> ; stampa senza \n
>> ; int /* numero di caratteri stampati */ puts_out(char* );
>> puts_out:
>>  push  bp
>>  mov   bp, sp
>>  push  bx
>>  push  si
>>    mov  si,[bp +  4]
>>    mov  bx,si
>>    label_1:  
>>      mov  al,[si]  

>   You limit your program to DS == SS (if you'll want to use this code
>somewhere else).

Why? (I don't know what you say) What does it mean DS, SS? Where are
they useful?
Thank you


Sun, 03 Jul 2005 02:59:26 GMT  
 Do you like this itoa1()?

Quote:

>Do you like this itoa1()?

>org 100h
> mov  ax, $+3
> push  ax
> push num

But I use some macro .)

org 100h
 inizia:
 =  ax, $+3
 pu  ax\\ pu num\\ call  itoa1\\ ++  sp, 4
 pu  msbp \\ call  puts_out\\ ++ sp, 2
 pu  num\\ call  puts\\ ++  sp, 2
 =   di, array
 ++  di, 2\\ =  cx, 1
 lab:
 =   ax, [di]
 pu  ax
 pu  ax\\ pu num\\ call  itoa1\\ ++  sp, 4
 pu  num\\ call  puts_out\\ ++  sp, 2
 call  car_s
 test cx, 0x7
 jne  via
 call  acapo
 via:
 +++  cx
 ++  di, 2
 po ax
 |  ax, ax
 jnz lab

exit:
mov ax, 4C00h
int 21h

putc_out:
 pu bx
    =  bx, 7\\ =  ah, 14\\ int 10h
 po bx
 ret

getc_in_dos:
 =  ah,  8\\ int 21h\\ ret

getc_in:
 =  ah,  0\\ int 16h\\ ret

car_s:
 pu ax
 =  al, ' '\\ call putc_out
 po ax
 ret

acapo:
 pu ax
 = al,13\\ call putc_out
 = al,10\\ call putc_out
 po ax
 ret

; stampa senza \n
; int /* numero di caratteri stampati */ puts_out(char* );
puts_out:
 pu  bp
 =   bp, sp
 pu  bx
 pu  si
  =  si,[bp +  4] \\ =  bx,si
  label_1:  
    =  al,[si]   \\ <  al,0 \\ je   fuori_1
    call putc_out\\ +++  si \\ jnz  label_1
  fuori_1:
  --  si,bx\\ = ax,si
 po  si
 po  bx
 =   sp, bp
 po  bp
 ret

; int /* numero di caratteri stampati */ puts(char* );
puts:
 pu  bp
 =   bp, sp
 pu  bx
 pu  si
  =  si,  [bp +  4] \\ =  bx, si
    label4:  
    =  al, [si]  \\ <  al, 0\\ je fuori4
    call putc_out\\ +++  si \\ jnz  label4
  fuori4:
  =   al, 10\\ call  putc_out
  --  si, bx\\ +++  si  \\ =   ax, si
 po  si
 po  bx
 =   sp, bp
 po  bp
 ret

; char*  itoa1(unsigned , char* )
itoa1:
 pu  bp
 =   bp, sp
 pu  dx
 pu  bx
 pu  di
 pu  cx
   =  di, [bp +  4]\\ =  ax, [bp +  6]
   <  ax, 255
   ja l2i
   =   dl, 10\\ =  dh, 0
   l_2i:
      div   dl\\ ++ ah, '0'\\ =  bl, ah\\ pu  bx\\ +++ dh
      | al, al\\ jz   l2_2i\\ ^ ah, ah \\ jmp  l_2i
   l2_2i:
      po  ax\\ = [di], al\\ +++  di\\---  dh\\ jnz  l2_2i
   jmp  end2i
   l2i:
   =  bx, 10\\ ^  dx, dx\\ =  ch, 0
   ri2i:
     div   bx \\ ++  dl, '0' \\ =  cl, dl \\ pu  cx\\ +++ ch
     | ax, ax \\ jz esci2i \\ ^ dx, dx    \\ jmp  ri2i
   esci2i:
     po  ax\\ = [di], al\\ +++  di\\---  ch\\ jnz  esci2i
   end2i:
   =  byte  [di], 0
 po  cx
 po  di
 po  bx
 po  dx
 =   sp, bp
 po  bp
 ret

num  db  0, 0, 0, 0, 0, 0, 0, 0, 0
msbp db  "ip=", 0
array dw  34, 7952, 42720, 56941, 47825,     3,  4829, 32133,  29787,\
              7028,     2, 46128, 34856, 63646, 21032, 62660,  61244,\
             35057, 36989, 43989, 46043, 48547, 43704, 29749,     98,\
              3633, 50349, 33655, 36965, 48566,    43, 15168,  78001,\
             30425,  8425,   83,    625, 23789, 37438, 64887,     91,\
             19015, 43108, 61545, 24901, 58349, 52290, 62047,   3435,\
               173,    55, 27851, 47955, 14377, 14434,    55,      0



Mon, 11 Jul 2005 01:11:30 GMT  
 Do you like this itoa1()?
/* name   7e.c => 7e.exe*/
/* questo programma ha un diverso tipo di getword
 serve come preprocessore di macro per file .asm */
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#define R return
#define P printf
#define F for
#define W while
#define MAXW  500
#define HASHSIZE 101

struct nlist{
 struct nlist* next;
 char* name;
 char* defn;

Quote:
};

static struct nlist* hashtab[HASHSIZE];

/*hash: calcola il valore di hashing della stringa s*/
unsigned hash(char* s)
{unsigned hashval;
 if(s==NULL) R 0;
 F(hashval=0;*s!='\0';++s)
     hashval=*s+31*hashval;
 R hashval%HASHSIZE;

Quote:
}

/*lookup: cerca s in hashtab*/
struct nlist* lookup(char* s)
{struct nlist *np;
 if(s==NULL) R NULL;
 F(np=hashtab[hash(s)];np!=NULL;np=np->next)
   if(strcmp(s,np->name)==0)
                  R np; /* trovata */
 R NULL; /*non trovata*/

Quote:
}

/* dupstr: fa una copia di s */
char* dupstr(char* s)
{char *p;
 if(s==NULL) return NULL;
 p=malloc(strlen(s)+1);    /* +1 per '\0' */
 if(p!=NULL)
    strcpy( p, s );
 return p;

Quote:
}

void free_node(struct nlist* a)
{if(a==NULL) R;
 if(a->name!=NULL) free(a->name);
 if(a->defn!=NULL) free(a->defn);
 free(a);

Quote:
}

void free_tab(void)
{unsigned i;
 struct nlist *p, *q;
 F(i=0;i<HASHSIZE;++i)
   F(p=hashtab[i];p!=NULL; p=q)
       {q=p->next;
        free_node(p);
       }

Quote:
}

/*undef: rimuove un nodo dalla tabella*/
int undef(char* name)
{struct nlist *pp, *p;
 unsigned hsv;
 if(name==NULL) R -1;
 hsv=hash(name);
 F(p=hashtab[hsv], pp=NULL;p!=NULL;pp=p, p=p->next)
   if(strcmp(name,p->name)==0)
         {if(pp==NULL)
               hashtab[hsv]=p->next; /*il primo */
          else pp->next=p->next;
          free_node(p);
          R 0;
         }
 R 1;

Quote:
}

/*instal: inserisce il nome (name, defn) in hashtab*/
struct nlist* install(char* name, char* defn)
{struct nlist *np;
 unsigned hashval;
 if((np=lookup(name))==NULL)    /*non trovata*/
  {np=malloc(sizeof(*np));
   if(np==NULL) R NULL;
   if((np->name=dupstr(name))==NULL)
              {free(np);
               R NULL;
              }
   if((np->defn=dupstr(defn))==NULL)
              {free(np->name);
               free(np);
               R NULL;
              }
   hashval=hash(name);
   np->next=hashtab[hashval];
   hashtab[hashval]=np;/*mette il nuovo nodo davanti a tutti*/
  }
 else
     {free(np->defn); /*annulla il precedente defn P*/
      np->defn=NULL;
      if((np->defn=dupstr(defn))==NULL)
              {undef(name);
               R NULL;
              }
     }
 return np;

Quote:
}

int main(int x, char** a)
{int getword(char* , int , FILE* );
 int next_word_line(char* , int , FILE* );
 int next_defn(char* , int , FILE* );
 int getch(FILE*);
 int c, cp, cpp;
 char word[MAXW];
 struct nlist *np;
 FILE *f_in, *f_out;
 if(x<2||a[1]==NULL||a[2]==NULL)
  {P("USO:\n>nome_prog     nome_file_in      nome_file_out\n"); R 0;}
 if((f_in=fopen(a[1],"r"))==NULL)
  {printf("\n ERRORE, impossibile leggere il file %s\n", a[1]);
   return 0;
  }
 if((f_out=fopen(a[2],"w"))==NULL)
  {printf("\n ER R ORE, impossibile scrivere il file %s\n", a[2]);
   fclose(f_in);
   return 0;
  }
 install( "pu", "push");
 install( "po", "pop");
 install( "=" , "mov");
 install( "a" , "eax");
 install( "b" , "ebx");
 install( "c" , "ecx");
 install( "d" , "edx");
 install( "\\\\" , "\n");
 install( "**", "mul");
 install( "//", "div");
 install( "++", "add");
 install( "--", "sub");
 install( "<" , "cmp");
 install( "w2", "dword");
 install( "w1", "word");
 install( "w4", "qword");
 install( "<<", "shl");
 install( ">>", "shr");
 install( "&" , "and");
 install( "|" , "or");
 install( "^" , "xor");
 install( "+++","inc");
 install( "---","dec");
 F(c=getword(word, MAXW, f_in),cpp=EOF;c!=EOF;
               cpp=c, c=getword(word, MAXW, f_in))
      {if(isspace(c)) fputc(c, f_out);
       else if(c=='\"'&& cpp!='\\')
          {fputs(word,f_out);
           F(cp=c;(c=getch(f_in))!=EOF && !(c=='\"'&& cp!='\\'); cp=c)
                                               fputc(c,f_out);
           if(c!=EOF) fputc('\"', f_out);
          }
       else if(c=='\''&& cpp!='\\')
         {fputs(word,f_out);
          F(cp=c;(c=getch(f_in))!=EOF && !(c=='\''&& cp!='\\'); cp=c)
                                               fputc(c,f_out);
          if(c!=EOF) fputc('\'', f_out);
         }
       else if(c==';')
              {fputs(word,f_out);
               F(;(c=getch(f_in))!=EOF && c!='\n';)
                                     fputc(c,f_out);
               if(c!=EOF) fputc('\n', f_out);
              }
       else  {if((np=lookup(word))!=NULL)
                         fputs(np->defn,f_out);
              else fputs(word,f_out);
             }
      }
 fclose(f_in);
 fclose(f_out);
 free_tab();
 R 0;

Quote:
}

#define  BUFSIZE  100

int buf[BUFSIZE];
int bufp=0;

int getch(FILE* pnt)
{R (bufp>0) ? buf[--bufp] : fgetc(pnt);}

void ungetch(int c)
{if(bufp>=BUFSIZE)
   P("ungetch: troppi caratteri\n");
 else buf[bufp++]=c;

Quote:
}

/*getword: legge la prossima parola o carattere
 dall'input*/
int getword(char* word, int lim, FILE* pnt)
{int c;
 char *w=word;
 int  cp, i, ip;        
 c=getch(pnt);
 if(c!=EOF)
        *w++=c;
 if(!isalpha(c)&&c!='_'&& !isdigit(c) &&
    !(c=='+' || c=='-' || c=='/' || c=='*' ||
      c=='=' || c=='\\'|| c=='<' || c=='>'
     )
   )
    {*w='\0';
     R c;
    }
 cp=c; ip=!isalnum(c);
 label:
 F(; --lim>0; cp=c, ip=i, ++w)
  if( (i=!isalnum(c=*w=getch(pnt))) || c=='_' ||
     (cp=='+' || cp=='-' || cp=='/' || cp=='*'||
      cp=='<' || cp=='>' || c=='='  || cp=='\\'
     )
    )
     {if( (cp=='+' && c=='+')    || (cp=='-' &&  c=='-') ||
          (cp=='*' && c=='*')    || (cp=='/' &&  c=='/') ||
          (cp=='\\' &&  c=='\\') || (cp=='<' &&  c=='<') ||
          (cp=='>' &&  c=='>')   || (!ip && c=='=')
        )
          { cp=c; ++w ; goto label; }
      ungetch(c);
      break;
     }
 *w='\0';
 R word[0];

Quote:
}

int next_word_line(char* word, int lim, FILE* pnt)
{int c;
 if(word==NULL||pnt==NULL) R 0;
 W( isspace(c=getword(word, lim, pnt)) && c!='\n');
 R c;

Quote:
}

int next_defn(char* word, int lim, FILE* pnt)
{int c, cp, i;
 if(word==NULL||pnt==NULL) R 0;
 word[0]='\0';
 W( isspace(c=getch(pnt)) && c!='\n');
 if(c==EOF||c=='\n') R c;
 word[0]=c;
 F(cp=c,i=0;i<lim &&(c=getch(pnt))!=EOF && !(c=='\n'&&cp!='\\');cp=c)
            if(c!='\n'&&c!='\\') word[++i]=c;
 word[++i]='\0';
 R c;
Quote:
}

__________________________________

#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#define R return
#define P printf
#define F for
#define W while

int main()
{char l_m[100]="7e ";
 char l_asm[100]="nasmw  -f bin -o ";
 char buf[50], buf1[50], i, j;
 int c;
 P("Inserire file asm(del tipo nome.x):"); fflush(stdout);
 fgets(buf1, sizeof(buf1), stdin);
 i=0;
 W(isspace(buf1[i])) ++i;
 F(j=0;buf1[i]!='\0'&& j<20 && buf1[i]!='.' && !isspace(buf1[i]);
      ++i, ++j)
                    buf[j]=buf1[i];
 buf[j]=0;
 if(buf1[i]!='.')
           return 0;
 F(;buf1[i]!='\0'&& !isspace(buf1[i]) ;++i);
 buf1[i]=' '; buf1[++i]=0;
 strcat(l_m, buf1);
 strcat(l_m, buf);
 strcat(l_m, ".asm ");
 strcat(l_asm, buf);
 strcat(l_asm, ".com ");
 strcat(l_asm, buf);
 strcat(l_asm, ".asm ");
 do{system(l_m);
    system(l_asm);
    P("per continuare premi <return> per finire premi e <return>:");
    fflush(stdout);
    W((c=getchar())!=EOF && c!='\n' && isspace(c));
   }W(c!='e' && c!=EOF);
 P("string 6_8e=%s\n", l_m);
 P("string asm=%s\n", l_asm);
 return 0;

Quote:
}



Tue, 12 Jul 2005 04:59:36 GMT  
 Do you like this itoa1()?

Quote:



> >> Do you like this itoa1()?
> >No :-)
> >> org 100h

> >   You probably wanted to put a label here and let linker know that
> >it's a main module.

> label_start:

> >>  mov  ax, $+3

> >   Where do you use this?

> here, push ax

> >>  push  ax
> >>  push num
> >>  call  itoa1
> >>  add  sp, 4

> in char* num there is ax 'string' number

> >   I don't think that C calling convention is a good choice for a COM
> >program written in assembly.

> Why not?

it is fine either way.  Really experienced ASM programmers will go to quite
a bit of work to maximize register throughput though, because that speeds
things up somewhat and also cuts code size.  If you want to learn some
really good techniques, download the IDA disassembler from www.simtel.net
and disassemble the turbo Pascal compiler from borland.

Quote:

> >Why not use your own register-based convention?

> e.g.
> ; ax  funct(bx, ch)
> funct:
>  push  dx
>  to_do_with_bx_and_ch_and_ax_and_dx
>  pop   dx
>  ret
> ?

yep you have the idea!

- Show quoted text -

Quote:

> >> putc_out:
> >>  push bx
> >>     mov  bx, 7
> >>     mov  ah, 14

> >   I think it's simple (and therefore better) to add "MOV CX, 1" here
> >rather than struggling to keep CX = 1 through all your program.

> I've found this:
> _______________________________________________________________
> INT 10H Function 0EH Write Text in Teletype mode
> Writes an ASCII character to the display at the current cursor
> position, using the specified
> colour (if in graphics mode), then increments the cursor position.
> _______________________________________________________________
> Register Call                           Value Return Value
> AH 0EH
> AL ASCII value
> BH screen page
> BL foreground colour in graphics mode
> _______________________________________________________________
> for this, cx would not be changed from putc_out

technically yes.  Be aware that some DOS and BIOS functions wipe certain
registers, and various documentation doesn't talk about this.  Some of it
at least is bugs in the handlers that have persisted for quite a while.  So
when writing code, be prepared to be a little defensive when calling
interrupt functions even when you have the docs.

- Show quoted text -

Quote:

> >>     int 10h
> >>  pop bx
> >>  ret

> >> getc_in_dos:
> >>  mov  ah,  8
> >>  int 21h
> >>  ret

> >> getc_in:
> >>  mov  ah,  0
> >>  int 16h
> >>  ret

> >> car_s:
> >>  push ax
> >>    mov  al, ' '
> >>    call putc_out
> >>  pop ax

> >   I know that they say a programmer of a subroutine should always
> >preserve registers, but it's only valid when you provide an interface
> >to external modules. Especially since you use stack-based parameters.
> so, do you say:
> car_s:
>  mov  al, ' '
>  call putc_out
>  ret
> ?

yeah...  that will take less code space, and won't need stack pushes loads
and pops so it will be faster.

- Show quoted text -

Quote:

> >>  ret

> >> acapo:
> >>  push ax
> >>    mov al,13
> >>    call putc_out
> >>    mov al,10
> >>    call putc_out
> >>  pop ax
> >>  ret

> >> ; stampa senza \n
> >> ; int /* numero di caratteri stampati */ puts_out(char* );
> >> puts_out:
> >>  push  bp
> >>  mov   bp, sp
> >>  push  bx
> >>  push  si
> >>    mov  si,[bp +  4]
> >>    mov  bx,si
> >>    label_1:
> >>      mov  al,[si]

> >   You limit your program to DS == SS (if you'll want to use this code
> >somewhere else).
> Why? (I don't know what you say) What does it mean DS, SS? Where are
> they useful?
> Thank you

This is an X86 architecture thing.  It is especially valid for DOS 16 bit
programs, but not useful so much for 32-bit operating systems since they
generally provide the illusion of a flat address space.

The various registers are 16 bits wide, which leads to a native code/data
size of 64K.  However they wanted to extend this out to 1MB.  What they did
was create something called a 'segment' register (CS,DS,ES,SS, and later FS
and GS) which would allow them to extend the addressing by 4 bits.  The
basic idea is that you can set each of these registers independently to
point to the beginning of any 64K block in memory, in increments of 16
bytes.  They each form the base of a 'window' to a 64K block of memory.
Most instructions default to using DS addressing so that is where your data
will lie.  However if you push things on the stack or index via BP that
defaults to SS addressing.  Some of the string instructions may default to
ES addressing, at least in part.  In this case you pushed a value on the
stack (SS addressing) and then indexed it with the DI register (DS
addressing).  For you this will work fine because when you make a COM file
MSDOS sets SS=DS=CS=ES so you don't have to worry about it unless you
explicitly change one of these registers.  But if you wanted to put this
same code in an EXE file the mentioned line of code will break the
program...

David



Tue, 12 Jul 2005 05:37:35 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Doing assembly and really doing assembly

2. Doing assembly and really doing assembly

3. Microsoft likes us :)

4. Looking for someone who likes to write reports

5. Greg likes Oberon (response)

6. Summary of Seek ELIZA-liked Source Codes!!!

7. Q: EAI likes BLUE ??

8. Sun compiler not liking X in format statements

9. Web interface to Majordomo-likes?

10. Who likes Info files?

11. I liked TCL, i love LUA

12. Likes/Dislikes of LISP

 

 
Powered by phpBB® Forum Software