DPRG
DPRG List  



DPRG: Assembler (was Real good riddle.)

Subject: DPRG: Assembler (was Real good riddle.)
From: Eric Yundt eric at sssi.com
Date: Sat Jul 26 21:01:55 CDT 1997

Kipton Moravec wrote:
> 
> droid at bellatlantic.net wrote:
> > 
> > [SNIP]
> > 
> > The thing is...I don't know a thing about the assembler. I have seen some
> > example codes and to tell you the truth,,,this thing looks like
> > someone designed it while drinking the rest of his cappucino late at
> > night. I know that the PBasic wil compile the code for me but I can't run
> > away from it. I mean it will get me sooner or later. I can program in
> > other languages tough :
> > CBM Basic
> > Apple II Applesoft Basic
> > Qbasic
> > Boland C
> > Borland Turbo C++ (v 3.0 for DOS)
> > Borland Turbo Pascal 7.0(for DOS)
> > 
> > All of these programming languages do make sense, maybe that's becasue
> > they are sort of human soun'a'like. Well, in the assembler it looks
> > rather differnt, you have all these registers, accumulators, and whole
> > lot of other stuff.
> >
> My first language was FORTRAN IV (1974), then COBOL (1975), then PL1
> (1978), then IBM 360 Assembler (1979). (Damn, am I old or what!) COBOL
> is more readable
> 
> In C:
> PAY = Hourly_Rate * Hours_Worked;
> 
> In COBOL:
> Multiply Hourly_Rate by Hours_Worked giving PAY;
> 
> But I digress....
> 
> Going from those languages to assembler is much more difficult than
> going from C to assembler. Why? Because C was designed to map nearly 1
> to 1 with PDP-8 Assembler.  Why is C the only language with ++ or --?
> (Postincrement, preincrement, postdecrement, predecrement) because the
> assembler had an increment (INC) and decrement (DEC) command, and since
> the value was in a register already, you might as well take advantage of
> it.  
> 
> For example, assume you had a line of C
> 
> ANS = A + B++;
> 
> In C it is pretty simple. You are telling the computer to go out and get
> the values from the memory locations designated A and B, add the values,
> put the answer in the memory location ANS, increment the value of B and
> store it back in memory (so it will be incremented next time you get
> it). In assembler, each step is it's own command. 
> 
>      LD      R0, A   ; Take the value in memory location A 
>                      ; and put it in register 0 (R0)
>      LD      R1, B   ; Take the value in memory location B
>                      ; and put it in register 1 (R1)
>      ADD     R0, R1  ; Add the values of register 0, and 
>                      ; register 1, and put the results in 
>                      ; register 0.  (This wipes out the copy of
>                      ; A that was in the register)
>      STO     ANS,R0  ; Take the contents of register 0 and store it
>                      ; in the memory location ANS.
>      INC     R1      ; Add 1 to the value in R1.
>      STO     B, R1   ; Store the contents of register 1 in 
>                      ; the memory location B
> 
> This is pretty simple if the ADD is an integer add, and A and B are the
> same precision as the register, and the add does not overflow a
> register.  <grin>.  The compiler worries about all of that for you, when
> it makes the conversion from C to assembler.
> 
> Depending on the project, and what I am trying to accomplish, sometimes,
> I prefer assembler!  If the project is small, and speed is important or
> I am manipulating hardware, I usually prefer assembler. If I have to
> worry about writing to the screen, and deal with user input I will NOT
> use assembler. Assembler should be used if you want to take advantage of
> the special features of the processor or controller.  If you want to be
> generic, then use a higher level language.  
> 
> Usually in robotics, we want to wring every bit of power out of our
> processor, and we are manipulating the robot hardware.  In 8051
> Assembler, I can set or clear a bit (or change one output wire.)
> 
>      SET P0.1
> 
> This takes the line number 1 on port 0 and raises it to a High or logic
> level 1.  I can not do that in C. In C I have to work with the whole
> byte.
> 
>      P0value = P0value || 0b00000010;
>      OUTB(P0,P0value);
> 
> That translates to 
>      LD R0,P0value  ;Load the values from the memory location P0value
>      OR  R0,0b00000010 ; Perform a Logical Or operation on 
>                       ; R0 and the immediate binary value, and  
>                       ; put the results in R0.
>      STO P0value, RO  ; store the value in the memory mapped location.
> 
> By using assembler, in this case I am 3x faster.  I have been told, that
> by using a highly optimized compiler, you can get about 1.1x slower in a
> high level language than by writing in assembler.  Unfortunately, we can
> not afford highly optimized compilers, so assembler is usually closer to
> twice as fast, and sometimes can be as much as 10x faster, in special
> cases.
> 
> > 
> > Since I want to, well I should say I HAVE to learn the assembler, I
> > believe that PIC chip should not be TOO complicated and I hope that it
> > will allow me to learn a WHOLE lot about the guts of teh whole
> > chip(Someone told me that to be efficient or even programm at all in the
> > assembler you HAVE to know the guts of a chip...kind of makes sense to
> > me... :(   )
> >
> Yup, You need to learn the "guts of the chip".  Fortunately, the guts in
> these types of processors are not very complicated.  It is very easy to
> understand microcontroller guts because they are simple. You should pick
> it up pretty fast.
> 
> > 
> > [snip bunch of stuff about books]
> >
> As far as I am concerned, you can't have too many books. (Until you run
> out of book shelves.) :) I have 5 books on the 8051 processor.  Some
> books explain different parts of the processor better.  If I am working
> on the serial port, I go to the book on the shelf that explains the
> serial port the best.  They all talk about the serial port, but one may
> give better examples, which makes me go faster. 
> 
> > 
> > And another Q.
> > 
> > I know that Borland C and C++ (for DOS) have something called IDE
> > compiler..if I'm not mistaken that means that the whole thing is
> > integrated in single editor. Every assembler I have seen on the WWW is
> > old style ...which means the you write your programm with the DOS EDIT
> > and then compile it back in DOS and all...is there an assembler for the
> > microcontrollers which would look similar to the C or C++ (not commands
> > of course, DUHHHH, the feel and integration where you can write your
> > program in the on window then press button and thing compiles it)
> >
> 
> In general, NO.  At, least not for what we can afford.  I do not know
> about the PIC, but in general, the reason the Borland has the IDE is
> because you are running on the same computer you are editing and
> compiling on.  Your PC does not have a PIC in it. If you spend your
> bucks, and get an in-circuit emulater, then you have a chance to get an
> integrated environment.  Expect to spend $1000 to $5000 for the whole
> package, in-circuit emulator, integrated C, Assembler, and editor. 
> 
> The rest of us get evaluation boards, edit the program, compile it, link
> it, download it into the evaluation board, and run it, and see what
> happens.  Once it works, we load the program into an EPROM. 
> 
> Hope this helps you understand, better.
> 
> Regards,
> Kip
> 

- --
Eric

  .---_____-.
   \  ._____(    FacetCorp       Eric Yundt               eric at facetcorp.com
    | |     `                    Technical Support     support at facetcorp.com
 _--~~~---.    "Putting the      FacetTerm/Win Evals       www.facetcorp.com
( ,----._./     Power of UNIX
 `-_| |_,       behind Win95's    FacetCorp - Makers of FacetTerm & FacetWin
    | |         Pretty Face!"     4031 W Plano Pkwy, Plano, TX   75093   USA
   /___\                          Phone: 972-985-9901      Fax: 972-612-2035

------------------------------

More information about the DPRG mailing list