Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assembly code for blink the LEDs from right to left then back again from the rig

ID: 3712061 • Letter: A

Question

Assembly code for blink the LEDs from right to left then back again from the right side.Describe this assembly code step by step.

AREA |.text|, CODE, READONLY

EXPORT __main

ENTRY

__main

LDR R2, =0x2009C054 ;LPC_GPIO2->FIOPIN address, see LPC1768 manual

LDR R0, =0x2009C040 ;LPC_GPIO2->FIODIR address, see LPC1768 manual

MOV R1, #0xFF

STR R1, [R0] ;Set direction of all 8 pins to OUT

MOV R5, #1

B main_loop

delay

MOV R4, #0 ; int R4;

delay_loop

ADD R4, R4, #1 ; for(R4 = 0; R4 < R1; R4++);

CMP R4, R1

BLT delay_loop

MOV PC, LR ;return

main_loop

CMP R5, #0x100

MOVEQ R5, #1

MOV R3, #1

STR R5, [R2] ;turn on LED - write 1 to FIOPIN

LDR R1, =6000000

BL delay ;delay(12000000)

MOV R3, #0

STR R5, [R2] ;turn off LED - write 0 to FIOPIN

BL delay

LSL R5, R5, #1

B main_loop

ALIGN

END

Can someone explain in detail the following assembly language program? The program is written using KEIL.

Explanation / Answer

Please find the commented code below.

AREA |.text|, CODE, READONLY

EXPORT __main

ENTRY

; start execution
__main

; FIOPIN register is used for both reading and writing data from/to the PORT.
; Writing to this register places corresponding values in all bits of the particular PORT pins.
LDR R2, =0x2009C054 ;LPC_GPIO2->FIOPIN address, Writing 0x2009C054 to R2

; This register individually controls the direction of each port pin.
LDR R0, =0x2009C040 ;LPC_GPIO2->FIODIR address, Writing 0x2009C040 to R0.

MOV R1, #0xFF ; Moving R1 ADDRESS 0xFF

STR R1, [R0] ;Set direction of all 8 pins to OUT by storing the content of memory locatio of R0 into R1

MOV R5, #1 ; Moving R5 ADDRESS 0x1

B main_loop

delay

MOV R4, #0 ; initialize R4 to 0. R4 will act as a counter variable for the loop

delay_loop

ADD R4, R4, #1 ; for(R4 = 0; R4 < R1; R4++);

CMP R4, R1 ; Compare R1 and R4

BLT delay_loop ; jump to delay_loop if R4 < R1

MOV PC, LR ;return out of the loop

main_loop

CMP R5, #0x100 ; compare R5 with 100

MOVEQ R5, #1 ; R5 = 1

MOV R3, #1 ; R3 = 1

STR R5, [R2] ;turn on LED - write 1 to FIOPIN

LDR R1, =6000000

BL delay ;delay(12000000) - create a delay

MOV R3, #0 ; R3 = 0

STR R5, [R2] ;turn off LED - write 0 to FIOPIN

BL delay ; branch delay loop

LSL R5, R5, #1 ; Logical left shift R5 by 1 bit

B main_loop ; branch main_loop

ALIGN

END

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote