To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.legosOpen lugnet.robotics.rcx.legos in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / legOS / 3646
3645  |  3647
Subject: 
Re: BrickOS Assembler
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Tue, 20 Jan 2004 03:24:44 GMT
Viewed: 
4360 times
  
In lugnet.robotics.rcx.legos, Michael Purvis wrote:
In lugnet.robotics.rcx.legos, Mark Riley wrote:
In lugnet.robotics.rcx.legos, Michael Purvis wrote:
In lugnet.robotics.rcx.legos, Iain McInnes wrote:

2) Figure out the assembler idiom for referring to symbols and use that.

???

One more answer... :-)

PERFECT. That was exactly what I was looking for.

Glad to help!

Clearly, the @_variablename
method only works for words and not bytes. This had been my problem.

However, it *does* work for bytes...  See the program below.  In your example
program, you declared the "total" variable as an unsigned short (which is a
16-bit word), but accessed it using an 8-bit move instruction.  Instead, declare
the variable as an unsigned char (8-bit byte).  See this post for a table of the
various types and their sizes:

  http://news.lugnet.com/robotics/rcx/legos/?n=3466

Also, if you're going to use inline assembly code, the compiler needs to be
aware that variables can be changed by your code.  One way is to declare the
total variable as "volatile" like so:

  volatile unsigned char total;

If you look at the assembly code produced by the compiler, you'll see that it
doesn't reload the total variable before calling the cputw function.  This is
because the compiler is unaware that total got changed by your assembly code and
it is trying to avoid reloading it into r0 as an optimization.

FYI, I believe there are other ways (besides the volatile keyword) to tell the
compiler about what your assembly code is doing, but I haven't delved that far
into the docs yet (look under the __asm__ keyword for more info).

Now, one last thing remains to get the program to produce an output of 0x0008 (I
think that's what you wanted) and that is to replace these lines:

  cmp.b r2h,r2l
  bge loopout
  bra verticalxloop
  loopout:

with this:

  cmp r2l,r2h
  blt verticalxloop

BTW, Kevin's suggestion of using the "-S" option with gcc is a good one, you can
learn a lot about H8 assembly just by seeing what the C compiler produces (you
can also learn what *not* to do! ;-)  A simple way to get the source file is to
type "make program.s" if your program is named program.c (I think you'll have to
modify the Makefile if you're using C++, though).

Cheers,

Mark

#include <unistd.h>
#include <conio.h>

char x = 40;
char y = 5;
char z;

int main()
  {
  __asm__("
    mov @_x,r0h
    mov @_y,r1h
    add r1h,r0h
    mov r0h,@_z
  ");

  lcd_int(z);

  msleep(5);

  return 0;
  }



Message has 1 Reply:
  Re: BrickOS Assembler
 
(...) Oh, I see. That's nifty. So a 'volatile' keyword ensures that it's reloaded every time? (...) Which doc is this? The only ones I have are the BrickOS command reference (it's a shorter HTML one), and the software manual from Hitachi. (...) (...) (21 years ago, 20-Jan-04, to lugnet.robotics.rcx.legos)

Message is in Reply To:
  Re: BrickOS Assembler
 
(...) PERFECT. That was exactly what I was looking for. Clearly, the @_variablename method only works for words and not bytes. This had been my problem. Thanks very much. And thanks to everyone else who contributed too... I'm just a sucker for the (...) (21 years ago, 19-Jan-04, to lugnet.robotics.rcx.legos)

11 Messages in This Thread:




Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR