GNU assembles BTC instructions
it instruction yes, check the instruction carefully
# address into register
LDR R0, x
LDR R1, y
LDR R2, Z
# compare X and Y which is the smallest
CMP R0, R1
movle R5, R0 Le means less equal, instruction means if (X & lt= y) R5 = R0 (i.e. x)
movgt R5, R1 GT means greater than, instruction means if (X & gt; y) R5 = R1 (i.e., y)
? R5 registers store the minimum values of X and Y. as long as the values of R5 and Z are compared, the minimum values
CMP R5, R2
movgt R5, R2 # if (R5 & gt; z) r5=z; If min {x, y} & gt; z. It means that the value of Z is the minimum, R5 = Z
at this time, we can get the minimum value and save it in the R5 register. We know how to write the minimum value. In fact, the maximum value is just like a gourd, so I don't have to worry about it, There may be a few syntax problems. But this is the idea. To make a judgment, first compare with CMP (arm will save the result of comparison in CPSR), then write down the instruction to be executed (such as mov), and add execution conditions (EQ, NE, lt, GT, etc.) after the instruction.
there is another method, if C language can't write, you can write the code in C language, Through the GCC - s option to compile the output into assembly code, you can refer to how the compiler does
there is no GNU arm in the network.
adding l means that the following two operands are 4-byte 32bit
the first $- 16 is a number - 16, 4-byte int is 0xfffff0, and the second% ESP is a register, which stores the memory address (4 bytes) pointed by the stack pointer, This command means that the 4-byte address stored in the register and 0xfff0 are bitwise matched, and the result is stored in the register% esp
the function should be to adjust the address of the stack pointer
b instruction is:
b {condition} target address
b instruction is the simplest jump instruction. Once a B instruction is encountered, the arm processor will immediately jump to the given target address and continue to execute from there. Note that the actual value stored in the jump instruction is an offset from the current PC value, not an absolute address. Its value is calculated by the assembler (refer to relative addressing in addressing mode). It is a 24 bit signed number, which is extended to 32 bits after shifting two bits to the left. The effective offset is 26 bits (32MB address space before and after). The following instructions:
b label; The program jumps to label unconditionally to execute
CMP R1, 0; When the Z condition code in the CPSR register is set, the program jumps to the label and executes
BEQ label
goodluck. Please refer to the arm assembly instruction
8-byte alignment can improve the access speed
GNU. Many things use this at & T format, such as as as GCC embedded assembly. Of course, they also use the Intel format, such as NASM
to add a sentence, because the book you read teaches the Intel format, which is different from the Intel format, so you can't understand the normal phenomenon
The communication between human and computer is mainly accomplished by assembly language, which is a machine oriented programming language. In assembly language, memoni is used to replace the operation code, and symbol or label is used to replace the address code. In this way, the binary code of machine language is replaced by symbol, and the machine language becomes assembly language. So assembly language is also called symbolic language. The program written in assembly language can not be directly recognized by the machine. A program is used to translate assembly language into machine language. This kind of translation program is called assembly program. Assembly program is the language processing system software in system software. The process that assembler translates assembly language into machine language is called assembly
< / blockquote > it should be noted that the assembly language is closely related to the CPU of the machine, and of course the assembly language is not all instructions of the CPU
CPU instructions of different architectures are not the same, such as x86, PowerPC, arm have their own instruction systems; Even the CPU of the same architecture has several instruction sets. For example, arm has a 16 bit thumb instruction set in addition to a 32-bit instruction set. But as a development language, assembly is essentially a set of syntax rules and mnemonics, which can contain different instruction sets. If divided by CPU system, there are two kinds of assembly: IBM PC assembly and arm assembly
IBM PC assembly is Intel's assembly, because IBM first introced PC, and many of its later systems are compatible with it, so it also uses the same assembly language. Arm has not considered compatibility at all, its instruction set and x86 are two systems, so assembly language has developed a set of independentCPU only limits machine code. As a development language, assembly is closely related to compiler. Assembly language appeared early, and there was no standard defined as C language, so the compiler manufacturers did their own. Up to now, the most famous are MASM and GNU ASM. The former is Microsoft's and only supports x86, which is used in DOS / Windows platform; The latter is an open source proct, mainly used in Linux, and basically supports most CPU architectures. The difference between the two lies in the difference of pseudo instructions. Pseudo instructions are used to tell the compiler how to work, which are related to the compiler but not to the CPU< br />
.equ a
.equ a
. equ b, 4
equb, 4
ldrr0, = a
br/ >
br/ >cp r0, r1
sub r0, r1
.equ i, 0
a: .byte 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
ldr r2, = a
ldr r3, === = in
, new1 at
< cmp r3, #10
1. The pop / push instruction is not selected correctly. The as command under Linux comes from GNU binutils and uses at & T assembly syntax. According to the size of the operands, the stack should choose the required instructions in push, pushw, pushl and pushq, instead of using push to do everything like Intel assembly
the pop instruction also has similar popw, Popl and POPQ instructions
2. Is there a problem with the operands (the notation in at & T assembly is different from that in Intel assembly, such as using $to refer to the immediate number, which is probably the reason for your error)
either use an assembler that supports Intel assembly syntax (such as NASM), or learn at & T assembly (if you really want to work under Linux, it is recommended to learn at & T assembly).
