0

I need some help with an 8 bit counter in Assembly. I want to map this to I/O portB to be used by the Led. To explain it further what happens is that the counter decrements each time before and loops back until it reaches zero. At the same a value x is incremented until it reaches 255. The value x is then pushed to the led pins in port B. will INX increment the desired count value like I am expecting it to, From 0 to 255? AN insert of the main portion of the code is below.

mycount EQU $1000;             count

MOVB #$FF,DDRB;   configure port B output 

Main:
 Again:MOVB #$FF,mycount;  set count lop
       LDX #0;             load count val
       STX PTB;           store count led
       INX;                Increment X
       DEC  mycount;      Decrement count
       BNE Again;      Loop if count =/=0
Ryan Paye
  • 21
  • 4
  • Did you try single-stepping it in a debugger/simulator to see what happened? Resetting `X` back to zero *inside* the loop every iteration is probably not what you want, but yes INX increments the X register, as an instruction-set reference will tell you. Google finds lots of them. – Peter Cordes Jul 09 '22 at 05:02
  • @PeterCordes I just noticed that. How could I avoid reseting it to zero? Still want to set it to zero for the first part of the loop. What should I call when I do LDX? – Ryan Paye Jul 09 '22 at 05:15
  • Before the `Again:` label that your loop branch jumps back to. Exactly like C `i=0; do{...}while(++i < max);` vs. `do{ i=0; ... }while(++i < max);` – Peter Cordes Jul 09 '22 at 05:24
  • @PeterCordes I put the LDX before the MOVB instruction so it just keeps incrementing the value in the x register and not reseting to 0. Thanks for pointing it out in C – Ryan Paye Jul 09 '22 at 05:57

0 Answers0