BeefCake
BeefCake

Reputation: 3

How do I write a 32-bit ARM ASM program to activate a loop using input from a wiringPi?

So I am creating a program that will cause an LED to blink on and off when a button is being pressed and held down, however, when I run the program that I have written, pressing the button will not initiate the LED's "blnkr" loop, are there any things I can fix with my program so that the LED's "blnkr" loop will run while the button's (BTN) input is returning HIGH?

// to compile: g++ redLed.s -lwiringPi -g -o redLed
// Program will power an LED when button is pressed, and when button is not pressed, LED will remain off

.equ INPUT, 0
.equ OUTPUT, 1
.equ LOW, 0
.equ HIGH, 1
.equ LED, 29    // wiringPi 29 (bcm 21 / physical 40)
.equ BTN, 28   // wiringPi 28 (bcm 20)

.text
.global main
main:
// int main()
    push {lr} // {
    bl wiringPiSetup // wiringPiSetup(); // initialize the wiringPi library
    
    mov r0, #LED // pinMode(29,OUTPUT); // set the wpi 29 pin for output
    mov r1, #OUTPUT
    bl pinMode
    
    mov r2, #BTN
    mov r1, #INPUT
    bl pinMode    // initiate r2 as input for wpi pin 28
    
do_while:
    mov r0, #LED
    mov r1, #LOW
    bl digitalWrite // turn off LED when button is not pressed
    
    mov r2, #BTN
    bl digitalRead    // r2 = digitalRead(BTN);

    cmp r2, #HIGH
    bleq blnkr       // if BTN is HIGH then branch with link to the blnkr loop
    b do_while

blnkr:
    cmp r2, #HIGH
    beq do_while
    
    mov r0, #LED // digitalWrite(29,HIGH); // write high volt signal to pin 21 to turn rgb led to red
    mov r1, #HIGH
    bl digitalWrite

    ldr r0, =#350 // delay(500); // delay for 500 milliseconds or 0.5 seconds
    bl delay

    mov r0, #LED // digitalWrite(29,LOW); // write low voltage to wpi 21 to turn off the rgb led
    mov r1, #LOW
    bl digitalWrite
    
    ldr r0, =#350
    bl delay
    b blnkr

    mov r0, #0 // return 0;
    pop {pc} // }

When I first tried to write this code, I attempted to make use of a while and do while loop, so the do while loop is supposed to run over and over again until the exit condition (BTN = HIGH) is met, then it should have branched into the blnkr loop where as long as BTN = HIGH the loop will repeat itself over and over while constantly checking after each iteration whether BTN = HIGH, however, when I run the program, the LED will remain off even when I press the button.

Upvotes: 0

Views: 81

Answers (0)

Related Questions