Assigning and changing values of variables?

I've only skimmed a few C tutorial / reference pages at this point (including some of the links in the sticky posts), trying to find something that would explain how to change the value of a variable as the program goes along, not just incrementing or decrementing that number, but I'm not finding much beyond the need to declare the variables at the beginning of the code.

In other words, I'm not finding how to do the C equivalent of:

LDA #$4A: STA $FF
(code etc.)
LDA #$41: STA $FF

For those portions of the program that simply stow numbers in memory for later, I know I eventually want the code to look something like the below, but I do NOT know the proper C syntax to do so, so please forgive my 'intellegince'.

LET R_0FF = 0x4A
(code etc.)
LET R_0FF = 0x41

Being able to understand how one can stick new numbers in a given variable on the fly will be a massive help in rewriting some 6800 assembly into something that can potentially be loaded into an Arduino.

Looks like the old LET stuff from BASIC.

LET R_0FF = 0x4A
(code etc.)
LET R_0FF = 0x41

Today we just assign the value to the variable. Easy peasy. Or have I missed something?

R_0FF = 0x4A;
(code etc.)
R_0FF = 0x41;

-jim lee

Or are you actually talking about stuffing a value into a certain memory location?

Lets say its a byte.

   byte* bytePtr;    // Pointer to a byte.

   bytePtr = 0x02;   // Point to address Hex 2
   *bytePtr = 45;    // Stuff a 45 in that memory location.

-jim lee

JimLee: Your first post was EXACTLY what I needed. I knew it had to be something simple. Thank you!

Cool! Go have fun!

-jim lee

Working on it! :slight_smile:

I'll be asking more questions soon, as the further I get into rewriting the assembly into C, I'm bumping into things like conditional branches for which I don't see clear equivalents, bit shifting, etc.

In the meantime, I want to check on the syntax of a few representative statements I've worked out (proper formatting will come later):

Disp06 = ( RM57 && 0x0F ); - there are a fair number of cases where I need to strip out certain bits.

MSG06 = ( MSG06 || 0x01 ); - likewise, certain cases where I need to turn on certain bits.

if ( Disp09 != 0x02 ) goto LB_F8D3; - is this the same as the assembly snippet below?

LDA Disp09
Cmp # 0x02
BNE LB_F8D3

There are people here that are WAY better at the bit level stuff than I am.

-jim lee

'&&' is a logical AND. It produces a value of TRUE or FALSE and is used mostly in arguments of conditional statements. When you're bit twiddling, you want bitwise AND: '&'.

Same distinction for OR operations: '||' verses '|'.

gfalvo: Thank you!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.