Michael Geer

ASM Register vs. C Array

Discussion created by Michael Geer on Jul 24, 2012
Latest reply on Jul 25, 2012 by bigmac

wasnt sure where to post this so i stuck with my 8 & 16 bit forum, always good answers :smileyhappy:

 

 

In assembly I have an 8 bit register, GPREG

 

LDA #$6D        ; which is decimal 109

STA GPREG

 

gives me 01101101

 

lets say i want an LED to turn on off according to that pattern

 

LSR GPREG

(check carry bit set LED on/off etc. for 8 bits)

 

now the led blinks in an order unique to "decimal 109"

 

how would i accomlpish this in C?

 

i have "decemial 109" or even "hex 6D"

i have:

 

byte b;

b = 109;  // my variable type in this case is a byte, and i CANT change that

 

do i have to right an algorith creating an array?

 

for i = 0 to 7 {

if b divided by whatever*i has a remander or not theh pattern[i] = 0 or 1

} // sorry for ugly pseudo code

 

so now my "pattern[]" has 8 ints 0 and 1s, and matches my GPREG,

 

But is there an easier way?

 

byte b = 109;

if b.0

if b.1

if b.2 (bit 2 "third bit") is 0 then LED off

 

or something like that?

 

thanks in advance for the help

 

-mike

Outcomes