How to compile and send the binary file?

arm-none-eabi-as blink1.s -o blink1.o
arm-none-eabi-objcopy blink1.o -O binary blink1.bin
rpi-run.py blink1.bin

Here is the simple answer of assign1.

.equ DELAY, 0x3F0000

// configure GPIO 20-27 for output
ldr r0, FSEL2
ldr r1, CTRMASS
str r1, [r0]
// init
mov r1, #(1<<20)

ldr r0, SET0
str r1, [r0]


// set counter r4 to 0
mov r4, #0
// set flag r5 to 0, when 0, count up; when 1,count down
mov r5, #0

//infinate loop
loop:

cmp r5, #0
//turn off current one
ldr r0, CLR0
str r1, [r0]
// update counter
addeq r4, r4, #1
subne r4, r4, #1
// shift
moveq r1, r1, LSL #1
movne r1, r1, LSR #1
// set next high
ldr r0, SET0
str r1, [r0]
// wait 1s
mov r2, #DELAY
wait1:
  subs r2, r2, #1
  bne wait1

// update the flag r5
cmp r4, #7
moveq r5, #1
cmp r4, #0
moveq r5, #0

b loop

FSEL2: .word 0x20200008
CTRMASS: .word 0x00249249
CLR0:  .word 0x20200028
SET0:  .word 0x2020001C

Lab 1

The first question is how to know the level of the pins?

Here:

 Broadcom peripheral manual , you can find it from lab page.

Code with explanation.

// notice: to make it simple, we use GPIO10 AND 20
// Because they are the LSBs in each register!
// configure GPIO 10 for input
ldr r0, FSEL1
mov r1, #0
str r1, [r0]

// configure GPIO 20 for output
ldr r0, FSEL2
mov r1, #1
str r1, [r0]

// bit 10
mov r2, #(1<<10)

// bit 20
mov r3, #(1<<20)

loop: 
    // read GPIO 10
    ldr r0, LEV0
    ldr r1, [r0]
    // compare 
    tst r1, r2
    beq off // if button is pressed (reads LOW), goto label "off"

        // set GPIO 20 high (turn on LED)
    on:
        ldr r0, SET0
        str r3, [r0]
        b loop

        // set GPIO 20 low (turn off LED)
    off:
        ldr r0, CLR0
        str r3, [r0]
        b loop


FSEL0: .word 0x20200000
FSEL1: .word 0x20200004
FSEL2: .word 0x20200008
SET0:  .word 0x2020001C
SET1:  .word 0x20200020
CLR0:  .word 0x20200028
CLR1:  .word 0x2020002C
LEV0:  .word 0x20200034
LEV1:  .word 0x20200038

What value is being tested by the beq instruction? The nearest tst or cmp or other things that change the Z flag. More

Previous

Views: 21

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.