Assembly Instructions?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Assembly Instructions?

Jump to solution
1,607 Views
CIA_MAN275
Contributor III

Hey Guys!

 

I need help!

 

I want an assembly instruction for those c-commands:

 DDRH |= 0x80;

 and

PORTH ^=0x80;

Aim is to switch the light off an on! I am a rookie yes :smileyvery-happy:

THX!!

Labels (1)
0 Kudos
1 Solution
1,046 Views
kef
Specialist I

A = A -+ 0x80 will toggle bit7 of A. Will it make LED connected to PORTH on or off I don't know, it depends on initial state of PORTH, also on the circuit.

View solution in original post

0 Kudos
8 Replies
1,046 Views
HSW
NXP Employee
NXP Employee

There is a S12 opcode for setting a bit in memory:

 

   BSET DDRH #$80

 

To toggle bit 7 you could implement the following sequence:

 

    LDAA    #$80

    ADDA    PORTH

    STAA     PORTH

0 Kudos
1,046 Views
CIA_MAN275
Contributor III

Can you also explain me the following code:

 

  ADDA    PORTH

 

why do you this?

 

 

0 Kudos
1,046 Views
Lundin
Senior Contributor IV

Fundamental Boolean algebra: A + B equals A UNION B equals A OR B

 

 

0 Kudos
1,046 Views
kef
Specialist I

Why? To be smarter than average, probably :-). ADD isn't faster than EOR, so this trick is as useless as this one

 

   LDAA PORTH   ;// PORTH ^= 0x80

   SUBA  #$80

   STAA  PORTH

 

Your successor will like it..., or maybe not

0 Kudos
1,046 Views
CIA_MAN275
Contributor III

When you make -> A= A- $80 than you become the led light off or?

 

I mean this explanation also above!

 

THX!!!

0 Kudos
1,047 Views
kef
Specialist I

A = A -+ 0x80 will toggle bit7 of A. Will it make LED connected to PORTH on or off I don't know, it depends on initial state of PORTH, also on the circuit.

0 Kudos
1,046 Views
CIA_MAN275
Contributor III

Okay THX!!!!

 

Here is the whole code:

 

include <stdio.h>

#include <mc912d128.h>


void delay1ms(void) {
  asm("ldy #2666"); //2666 in Y-Register laden
  asm("dbne y,.");  // Decrement, bis Y=0 ist /
            //3cyc x 125ns x 2666 = 0,99975ms
}


void wait(int duration)
{
  while(duration--)
  delay1ms();
}

void main(void) {

 asm("LDAA #$80");               //DDRH |= 0x80;
 asm("STAA $002B");


while(1){
  asm("LDAA #$80");           //PORTH ^=0x80;
  asm("ADDA $0029");
  asm("STAA $0029");
  wait(1000);
 
  }

}

 

Program is ICC12!

 

THX to all of you for helping hands! :smileywink:

0 Kudos
1,046 Views
CIA_MAN275
Contributor III

I have no S12... so the code don't work! :smileysad:

0 Kudos