home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.asm.x86      Ahh, the lost art of x86 assembly      4,675 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 3,414 of 4,675   
   luserdroog to luserdroog   
   Re: indexing sp in 8086 (1/2)   
   20 May 18 15:39:19   
   
   From: luser.droog@nospicedham.gmail.com   
      
   On Tuesday, May 15, 2018 at 4:44:01 PM UTC-5, luserdroog wrote:   
   > On Monday, May 14, 2018 at 10:27:59 PM UTC-5, Rod Pemberton wrote:   
   > > On Fri, 11 May 2018 20:29:46 -0700 (PDT)   
   > > luserdroog  wrote:   
      
   > > > Need to stitch up the link fields somehow.   
   > >   
   > > Of course, &image[XX], provides the address: image+XX.  However, you   
   > > only have a byte to encode a length to the next primitive.  You could   
   > > subtract two addresses.  The problem is that any time you insert or   
   > > delete bytes into any Forth word within image[], /all/ of the XX   
   > > indexes from there onwards to the end of the dictionary, become   
   > > incorrect and must be manually adjusted, since their values have been   
   > > hard coded.  BTDT.   
   > >   
   > > Now, if you called putc() or putchar() in your macros to write the   
   > > bytes out to a file, then you could create a wrapper routine for putc()   
   > > or putchar(), say i_putc(), which also increments a counter variable   
   > > every time you output a character to a file.  This variable would give   
   > > you the current index position within image[].  Any time the char was   
   > > '\0', you'd save the counter to subtract to later subtract from the   
   > > current counter to obtain the LFA offset.  Of course, that would mean   
   > > that you'd need to use something other than '\0' for word padding the   
   > > name field, e.g., perhaps a space.   
   > >   
   >   
   > Yes, that does seem like a good approach. I've gone in a different   
   > direction with more complicated macros. But I am tempted to backtrack   
   > and build the image with smaller functional pieces which are then   
   > combined.   
   >   
   > Still a work in progress, but here's the latest draft. It's now split   
   > into several files.   
   >   
   > $ for i in [snip] forth.h ; do echo ---- $i: ---- ; cat $i ; done && echo --   
   && cpp -P forth.h   
   [snip]   
   > ---- forth.h: ----   
   > #include "ppnarg.h"   
   > #include "applyx.h"   
   > #include "asm8086.h"   
   >   
   > #define NEXT       LODS, JMP_(R,AX)   
   > #define PUSHRSP(r) LEA(,B,DI,DI_),0xfc, MOV(,Z,r,DI_)   
   > #define POPRSP(r)  MOV(F,Z,r,DI_), LEA(,B,DI,DI_),4   
   >   
   > #define CODE(letters,...) _COUNT(LETTERS letters __VA_ARGS__)   
   > #define WORD(letters,...) _COUNT(LETTERS letters JMP(DOCOL), __VA_ARGS__)   
   > #define LETTERS(...) PP_NARG(__VA_ARGS__),APPLYXn(CHARIFY, __VA_ARGS__)   
   > #define _FINIS(...) __VA_ARGS__   
   > #define _COUNT(...) __VA_ARGS__,PP_NARG(__VA_ARGS__)   
   > #define STRINGIFY(x) #x   
   > #define CHARIFY(x) *STRINGIFY(x),   
   >   
   >   
   > static inline int   
   > forth(char *mem){   
   >   unsigned char image[] = {   
   >     0,   
   >     CODE((d,o,c,o,l), PUSHRSP(SI), ADDAX,4,0, MOV(,R,DI,AX), NEXT),   
   >     CODE((e,x,i,t),   POPRSP(SI), NEXT),   
   >     CODE((l,i,t),     LODS, PUSH(AX), NEXT),   
   >     CODE((d,r,o,p),   POP(AX), NEXT),   
   >     CODE((s,w,a,p),   POP(AX), POP(BX), PUSH(AX), PUSH(BX), NEXT),   
   >     CODE((d,u,p),     MOV(,R,BP,SP), MOV(,B,AX,BP_),0, PUSH(AX), NEXT),   
   >     CODE((o,v,e,r),   MOV(,R,BP,SP), MOV(,B,AX,BP_),2, PUSH(AX), NEXT),   
   >     CODE((r,o,t),     POP(AX), POP(BX), POP(CX), PUSH(BX), PUSH(AX),   
   PUSH(CX), NEXT),   
   >     CODE((-,r,o,t),   POP(AX), POP(BX), POP(CX), PUSH(AX), PUSH(CX),   
   PUSH(BX), NEXT),   
   >     CODE((2,d,r,o,p), POP(AX), POP(AX), NEXT),   
   >     CODE((2,d,u,p),   MOV(,R,BP,SP), MOV(,B,AX,BP_),0, MOV(,B,BX,BP_),2,   
   PUSH(BX), PUSH(AX), NEXT),   
   >     CODE((2,s,w,a,p), POP(AX), POP(BX), POP(CX), POP(DX),PUSH(   
   X),PUSH(AX),PUSH(DX),PUSH(CX),NEXT),   
   >     CODE((?,d,u,p),   MOV(,R,BP,SP), MOV(,B,AX,BP_),0, TEST(R,AX,AX), JZ,1,   
   PUSH(AX), NEXT),   
   >     CODE((1,+),       MOV(,R,BP,SP), INC_(B,BP_),0, NEXT),   
   >     CODE((1,-),       MOV(,R,BP,SP), DEC_(B,BP_),0, NEXT),   
   >     CODE((+),         POP(AX), MOV(,R,BP,SP), ADD(F,B,AX,BP_),0, NEXT),   
   >     CODE((-),         POP(AX), MOV(,R,BP,SP), SUB(F,B,AX,BP_),0, NEXT),   
   >     CODE((*),         POP(AX),POP(BX), IMUL(R,BX), PUSH(AX), NEXT),   
   >     CODE((!),         POP(BX), POP(AX), MOV(F,Z,AX,BX), NEXT),   
   >     CODE((@),         POP(BX), MOV(,R,AX,BX), PUSH(AX), NEXT),   
   >     CODE((+,!),       POP(BX), POP(AX), ADD(F,Z,AX,BX), NEXT),   
   >     CODE((-,!),       POP(BX), POP(AX), SUB(F,Z,AX,BX), NEXT),   
   >     WORD((d,o,u,b,l,e), DUP, PLUS, EXIT),   
   >   };   
   >   return  memcpy(mem, image, sizeof image);   
   > }   
   > --   
   > static inline int   
   > forth(char *mem){   
   >   unsigned char image[] = {   
   >     0,   
   >     5,*"d", *"o", *"c", *"o", *"l", +0x8d,0175,0xfc, +0x8b,0065, 0x05,4,0,   
   +0x8b,0370, 0xAD, 0xff,0350,19,   
   >     4,*"e", *"x", *"i", *"t", -2 +0x8b,0065, +0x8d,0175,4, 0xAD,   
   0xff,0350,13,   
   >     3,*"l", *"i", *"t", 0xAD, 0x50+0, 0xAD, 0xff,0350,9,   
   >     4,*"d", *"r", *"o", *"p", 0x58+0, 0xAD, 0xff,0350,9,   
   >     4,*"s", *"w", *"a", *"p", 0x58+0, 0x58+3, 0x50+0, 0x50+3, 0xAD,   
   0xff,0350,12,   
   >     3,*"d", *"u", *"p", +0x8b,0354, +0x8b,0106,0, 0x50+0, 0xAD, 0xff,0350,13,   
   >     4,*"o", *"v", *"e", *"r", +0x8b,0354, +0x8b,0106,2, 0x50+0, 0xAD,   
   0xff,0350,14,   
   >     3,*"r", *"o", *"t", 0x58+0, 0x58+3, 0x58+1, 0x50+3, 0x50+0, 0x50+1,   
   0xAD, 0xff,0350,13,   
   >     4,*"-", *"r", *"o", *"t", 0x58+0, 0x58+3, 0x58+1, 0x50+0, 0x50+1,   
   0x50+3, 0xAD, 0xff,0350,14,   
   >     5,*"2", *"d", *"r", *"o", *"p", 0x58+0, 0x58+0, 0xAD, 0xff,0350,11,   
   >     4,*"2", *"d", *"u", *"p", +0x8b,0354, +0x8b,0106,0, +0x8b,0136,2,   
   0x50+3, 0x50+0, 0xAD, 0xff,0350,18,   
   >     5,*"2", *"s", *"w", *"a", *"p", 0x58+0, 0x58+3, 0x58+1, 0x   
   8+2,0x50+3,0x50+0,0x50+2,0x50+1,0xAD, 0xff,0350,17,   
   >     4,*"?", *"d", *"u", *"p", +0x8b,0354, +0x8b,0106,0, 0x85,0300, 0x74,1,   
   0x50+0, 0xAD, 0xff,0350,18,   
   >     2,*"1", *"+", +0x8b,0354, 0xff,0106,0, 0xAD, 0xff,0350,11,   
   >     2,*"1", *"-", +0x8b,0354, 0xff,0116,0, 0xAD, 0xff,0350,11,   
   >     1,*"+", 0x58+0, +0x8b,0354, -2 +0x03,0106,0, 0xAD, 0xff,0350,11,   
   >     1,*"-", 0x58+0, +0x8b,0354, -2 +0x2b,0106,0, 0xAD, 0xff,0350,11,   
   >     1,*"*", 0x58+0,0x58+3, 0xf7,0353, 0x50+0, 0xAD, 0xff,0350,10,   
   >     1,*"!", 0x58+3, 0x58+0, -2 +0x8b,0003, 0xAD, 0xff,0350,9,   
   >     1,*"@", 0x58+3, +0x8b,0303, 0x50+0, 0xAD, 0xff,0350,9,   
   >     2,*"+", *"!", 0x58+3, 0x58+0, -2 +0x03,0003, 0xAD, 0xff,0350,10,   
   >     2,*"-", *"!", 0x58+3, 0x58+0, -2 +0x2b,0003, 0xAD, 0xff,0350,10,   
   >     6,*"d", *"o", *"u", *"b", *"l", *"e", JMP(DOCOL), DUP, PLUS, EXIT,11,   
   >   };   
   >   return memcpy(mem, image, sizeof image);   
   > }   
      
   I thought about going forward and the alternative seemed more appealing.   
   But I got as far as this:   
      
   static int code();   
   static int word();   
   static int grow();   
      
   static int   
   forth( char *load_address ){   
     unsigned char *image = NULL;   
     unsigned int capacity;   
     unsigned int offset = 0;   
     offset += code( image, offset, capacity, "docol", PUSHRSP(SI), ADDAX,4,0,   
   MOV(,R,DI,AX), NEXT );   
     offset += word( image, offset, capacity, "double", "dup", "plus", "exit" );   
   }   
      
   static int   
      
   [continued in next message]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca