Chapter 3 arm instructions in gba asm of gbaguy

Source: Internet
Author: User
Tags value store

Chapter 3 arm commands

 

Today, we started to learn some arm commands, but you should remember some previous things (related to execution speed ):
· Align your data. Use the. Align command, such as. Align 4 and. Align 2. If you use a non-alignment address, the CPU will do some sweaty operations to definitely reduce the speed.
· Commands that do not access the memory are always faster. use registers to the maximum extent and do not load data from the memory. Use the mov and add commands to load the 32-bit immediate number. Do not use the LDR command.

 

Command LDR

 

The command LDR is also widely used, although its main function is to load (read) a value from the memory. It has multiple addressing modes, and I am not quite sure about some of them... go to the manual. I was lucky to find an ARM architecture reference manual 2nd edition in a special book store. There are also some manuals on gbadev.org. The simplest form of LDR is to read a value from the Rom's "pool" (or where you run the program. It looks like this:

 

LDR r0, = 0x32bitnumber (0x32bitnumber is a 32-digit number, such as 0x403, 0 xcafebabe, 0xbad00fed, 0x6000000 ...).

 

The 32-digit value is stored in the "pool" and will be automatically processed by the assembler. In general, you need to explicitly use the. ltorg command behind each subroutine (or at the end of the file, if the program is not large) to tell the assembler where to place the "pool ".

 

I am afraid it is not clear here. Put a picture to give you some perceptual knowledge)

 

The next form is from register addressing, such:

 

LDR r0, [R1]

 

It will load the 32-digit number at the address indicated by R1 to R0. (Similar to R0 = * R1; in C ;)

 

Here is a syntax point. If there is square brackets outside the Register, it indicates the content of the address pointed to by the Register, rather than the value itself in the register.

 

The following are some other addressing methods that you need to know: (I have been using R0. In fact, any register can be used. Registers can also be used at # offset)

[R0, # offset] The address is R0 + # offset. This is called pre-indexed.
If you add a pair after the brackets !, Then the address must be written to R0. This is called "write back", which is useful in loop, so that you do not need to write another instruction to update the address pointer.
[R0], # The offset address is r0, and R0 + # The offset is written to R0. This is called post-indexed.
Write-back is automatically performed.

These are only addressing modes. The complete commands should be "LDR R1, address_mode ". You can write "LDR R1, [r0, R2]", "LDR R3, [R2], #4" and so on. The first one is "R1 = * (R0 + R2)", and the second one is "R3 = * R2; r2 + = 4 ;". Arm commands are powerful, right? Believe me, you haven't seen anything yet!

 

Command Str

 

The STR command is used almost the same as LDR (except in the format of = 0x32bitnumber ). The only difference is that it writes a value store to the memory. This is very simple.


Instruction mov

 

Instruction mov is used to move data between registers. It also includes a displacement instruction. The syntax is as follows: (reg1, reg2 can be any register, and the value of reg2 will not change)
MoV reg1, reg2 {, LSL/LSR/ASR/ror/rrx #} copies the reg2 value to reg1. If there is an optional displacement parameter, the reg2 will be displaced. For example: mov r0, R1, LSL #2, that is, R0 = R1 <2.
MoV reg1, #0 xnumber stores an immediate number in reg1, but this number is limited. It must be obtained by a large number of bytes through displacement.

You can also perform operations such as mov R0 and R0 as Nop (do not do anything). If you want to shift a register value, the mov command is what you want:
MoV r0, R0, LSL #3, R0 = R0 <3; there are no separate displacement commands in the arm instruction set.

 

The syntax for displacement of many commands is the same (except for arithmetic commands, add, sub, EOR, Orr, And, BIC and so on), which is the same as mov, so I won't mention the displacement syntax later.

 

I hope you have mastered these things and these commands are important. Next, we will try to read a small number from Ram, then learn the branch command, and finally analyze the program in Chapter 2.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.