This post is related to Week1.

I strongly recommend you read all the material provided by official site.

ARM processor and architecture.

1.Basic conception

To run a program, we need machine to go at least 3 stages.

They are fetching, decoding and execution.

  1. Suppose your program starts at 0x8000, what assembly language instruction could you execute to jump to and start executing instructions at that location.
  2. If all instructions are 32-bits, can you move any 32-bit constant value into a register using a single mov instruction?
  3. What is the difference between a memory location and a register?

Answer:

  1. From the slides of this class before, PC stores the address the address of the next instruction to execute. So, we can update the value in R15 which holds the address we want. mov r15, #0x8000
  2. No, we can’t. The length of one instruction is fixed(32-bits). If we want to do it, the length of the instruction will be out of range.
  3. For us who intend to write assembly codes, the difference between them is that a memory location must be accessed by an address. It is an instance or immediate also. Besides, we just need symbol or name to use register. For computer, one is in RAM and the other is in CPU.

2. LDR & STR

Load from Memory to Register (LDR), ldr r0, [r1]. In C-style: r0 = *(r1)

Store Register in Memory (STR), str r0, [r1]. In C-style: *(r1) = r0

3.MMIO,Memory-Mapped IO

Peripherals are Controlled by Special Memory LocationsPeripheral Registers.” In this class, there are two kinds of Peripheral Registers: function select and out-put set,

This confusing when we relate Memory Locations with Registers. This is a technique that provide a way to access the peripheral registers like accessing memory. And device will sync the data in memory and registers. The sync operation between the memory mapped I/O and the peripheral device is done by DMA, which stands for Direct Memory Access. DMA is a technique that allows the device to transfer data directly to and from the memory, without involving the CPU.

So do not worry, just regard these Memory Locations as registers and write data as normal memory.

This slide shows the structure and function of function select.

Each register can control 9 pins. And if you want to control one of them, you have to take care of the other pins, as one register is the smallest unit we can operate.

This slide shows the structure and function of out-put set.

These registers set the output value of the GPIO pins to HIGH. From the previous slides, function select bits just indicate the mode of GPIO. But when the GPIO is set “output”, we do not know whether it is HIGH or LOW. So, we use extra registers to denote the output value.

4. Load a long number to memory

Here is a trick to load a long number to memory. You can separate the long number and load them part by part. In the end, use ORR to connect them together. For more please read this(skim Carl Burch’s Intro to ARM assembly) which is also recommended by the schedule.

5.The code and upload it

Here is the code. And previous post has recoded how to upload your binary file. And you may compile the code just follow what the official slide does.

q// turn on LED connected to GPIO20

// configure GPIO 20 for output
//
// GPIO 20 function select is in the 2nd function select register
//

mov r0, #0x20      // #0x00000020
lsl r1, r0, #24    // #0x20000000
lsl r2, r0, #16    // #0x00200000
orr r0, r1, r2     // #0x20200000
orr r0, r0, #0x08  // #0x20200008
mov r1, #1         // indicates OUTPUT
str r1, [r0]       // store 1 to address 0x20200008


// set GPI020 to 1
//
// GPIO 20 is in the 1st SET register
//
// GPIO 20's output value is controlled by bit 20
//
// SET0 = 0x2020001c

mov r0, #0x20
lsl r1, r0, #24    // #0x20000000
lsl r2, r0, #16    // #0x00200000
orr r0, r1, r2     // #0x20200000
orr r0, r0, #0x1c  // #0x2020001c
mov r1, #1    
lsl r1, #20        // #0x00100000
str r1, [r0]       // store 1<<20 to address 0x2020001c

// branch forever
loop:
b loop // go to loop

6. Lab 0 & Assignment 0

NONE

Previous Post

EOF

Views: 13

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.