# Assembly Instructions?

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

## Assembly Instructions?

1,789 Views
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

THX!!

Labels (1)
• ### General

1 Solution
1,228 Views
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.

8 Replies
1,228 Views
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

STAA     PORTH

1,228 Views
Contributor III

Can you also explain me the following code:

why do you this?

1,228 Views
Senior Contributor IV

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

1,228 Views
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

1,228 Views
Contributor III

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

I mean this explanation also above!

THX!!!

1,229 Views
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.

1,228 Views
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("STAA \$0029");
wait(1000);

}

}

Program is ICC12!

THX to all of you for helping hands!

1,228 Views
Contributor III

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