Download presentation
Presentation is loading. Please wait.
Published byPatrick Nickeson Modified over 9 years ago
1
1 ARM Movement Instructions u MOV Rd, ; updates N, Z, C Rd = u MVN Rd, ; Rd = 0xF..F EOR
2
2 ALU Arithmetic Instructions u ADD Rd, Rn, ; updates N, Z, V, C Rd = Rn + u SUB Rd, Rn, Rd = Rn - u MUL Rd, Rm, Rs Rd = Rm * Rs u CMP Rd, Flags (difference lost)
3
3 ALU Logical Examples u TST Rd, Flags u TEQ Rd, Flags u AND Rd, Rn, Rd = Rn AND update N, Z, C
4
4 ALU Logical Examples u EOR Rd, Rn, Rd = Rn EOR u ORR Rd, Rn, Rd = Rn OR u BIC Rd, Rn, ;BIt Clear Rd = Rn AND NOT
5
5 Branch Instructions u B(cond) label PC <= “address” of label if cond is met u BL(cond) label PC <= “address” of label if cond is met, set link register to current PC value
6
6 Load Instructions u LDR Rd, Rd = [address] u LDM(cond){IB|IA|DB|DA}, Rd(!), {^} “block pop”, ! => update Rd, => list of registers ^ => set the S bit
7
7 Store Instructions u STR Rd, [address] = Rd u STM(cond){IB|IA|DB|DA}, Rd(!), {^} “block push”, ! => update Rd, => list of registers ^ => set the S bit
8
8 Stack Manipulation u LDM(cond), Rd(!), u STM(cond), Rd(!), LDM:pop STM:push stack, ! => update Rd => list of registers
9
9 Assembler Pseudo-ops u AREA -> chunks of data ($data) or code ($code) u ADR -> load address into a register ADR R0, BUFFER u ALIGN -> adjust location counter to word boundary usually after a storage directive u END -> no more to assemble
10
10 u DCD -> defined word value storage area BOW DCD 1024, 2055, 9051 u DCB -> defined byte value storage area BOB DCB 10, 12, 15 u % -> zeroed out byte storage area BLBYTE % 30 Assembler Pseudo-ops
11
11 u IMPORT -> name of routine to import for use in this routine IMPORT _printf ; C print routine u EXPORT -> name of routine to export for use in other routines EXPORT add2 ; add2 routine u EQU -> symbol replacement loopcnt EQU 5 Assembler Pseudo-ops
12
12 Assembly Line Format label instruction ; comment label: created by programmer, alphanumeric whitespace: space(s) or tab character(s) instruction: op-code mnemonic or pseudo-op with required fields comment: preceded by ; ignored by assembler but useful to the programmer for documentation All fields are optional.
13
13 Example: linking C and assembly language u Add two integers using an assembly language routine, follow the ARM standard for linking routines
14
14 C Language Driver Routine #include /* standard input and output */ #include /* standard library */ extern int add2( int I, int j ) ; /* tell the compiler that the routine is not defined here */ Int main( int argc, char * argv[] ) /* entry point to the program */ { int i, j ; /* declare the variable types */ int answer ; i = 5 ; /* give the variables values */ j = 20 ; answer = add2( i, j ) ; /* call the assembly language routine */ printf( “result is: %d\n”, answer ) ; /* print out the answer */ exit( 0 ) ; /* leave the driver program */ }
15
15 Assembly Language Routine AREA |add2$code|, CODE, READONLY ; tell the assembler stuff EXPORT add2 ; tell the assembler to show this label to the linker add2 ; the label defining the entry point stmfd sp!, {v1-v6, lr} ; ‘standard’ entry, save registers on the stack add a1, a1, a2 ; do the addition requested ldmfd sp!, {v1-v6, pc} ; put the registers back and go back to caller END ; tell the assembler this is the end of the file Pseudo-op codes: tell the assembler to do something rather than generate code. Above, END, EXPORT, AREA, CODE, READONLY.
16
16 Another C to Assembler Example u Add an array of integers in assembly language and print out the total using C language library routine.
17
17 C Language Driver #include #define ARRAY_SIZE 5 /* set the size of the array */ extern int sumarray( int array[], int size ) ; /* declare the assembly routine */ Int main( int argc, char * argv[] ) { int size = ARRAY_SIZE ; /* as input to the summation routine */ int answer ; int numarray[] = { 1, 2, 3, 4, 5 } ; /* initialize the array */ answer = sumarray( numarray, size ) ; /* call the assembly language routine */ exit( 0 ) ; /* we’re done */ }
18
18 Assembly Language Routine AREA |sumarray$code|, CODE, READONLY EXPORT sumarray IMPORT _printf sumarray stmfd sp!, {v1-v6, lr} ; standard entry mov a3, #0 ; set sum to zero Sumloop ldr a4, [a1], #4 ; get element, increment pointer add a3, a3, a4 ; add element to partial sum subs a2, a2, #1 ; one less element bne sumloop ; have we done all? mov v1, a3 ; save sum adr a1, anstext ; get address of message mov a2, a3 ; get sum (for %d parameter) bl _printf ; use the C language routine mov a1, v1 ; return value to C ldmfd sp!, {v1-v6, pc} ; standard exit AREA |sumarray$data|, DATA ; message area anstext DCB “Result of summation = %d\n”, 0 END a1 is pointer to array a2 is number of elements a3 is sum of elements a4 element to add
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.