1. To complete the 1c.c program to get a+ B value, you can only fill in the relevant assembly code in (), which was last stored at 0x20009000. 1c. C Procedure is as follows:
GNU style inline assembly syntax is as follows:
asm volatile ("asm code": output: input: changed);

void _start(void)
{
    int a = 30;
    int b = 48;
    int sum = 0;
    __asm__ __volatile__(
    	"mov r0, %1\n"
    	"mov r1, %2\n"
    	"add %0, r1, r2\n"
    	:"=r"(sum) 	// result =r means only write
    	:"r"(a),"r"(b) // The r argument uses any general purpose register); * ((int(*)0x20009000)) = sum;
}
Copy the code
  1. C program 2c. C, in C to implement the function usigned LRSP (int flag), when flag=1 to return the value of register LR, is 0, return the value of register SP. The function LRSP (0) is called in the main program to write the returned result into memory 0x20009000.
unsigned lrsp( int flag );
void _start(void)
{
   unsigned val;
   val 			=	lrsp(0); * (int*)0x20009000	=	val;
}
unsigned lrsp( int flag )
{
   unsigned val;
   if( flag == 1 )
   {
   	__asm__ __volatile__(

   	"mov %0,lr\n"
   	:"=r"(val)
   	:
   	);

   }
   else if( flag == 0 )
   {
   	__asm__ __volatile__(
   	
   	"mov %0,sp\n"	
   	:"=r"(val)
   	:
   	);
   }
   else
   {
   	 val = - 1;
   }
   return val;
}
Copy the code
  1. If uboot loads printf at 0x2fd17b18, assembler 3s.S calls printf and prints hello world!
.global _start _start: push {lr} ldr r4, =0x2fd17b18 ldr r0, =mystr mov lr,pc mov pc,r4 pop {lr} mov pc, lr mystr: .string "hello world! \n" .endCopy the code
  1. Change the following c program to assembler 4s.S, given that uboot loads the printf function at memory address 0x2fd17b18.
void _start( void )
{
   int a=1,b=2,c=3,d=4,e=5;
   printf(" \ na = % d, b = % d, c = % d, d = % d, e = % d \ n ", a, b, c, d, e); }Copy the code

4s.S

.global _start _start: push {lr} ldr r0, =mystr ldr r1, a ldr r2, b ldr r3, c ldr r4, d push {r4} ldr r4, R4} pop {r4,r4} pop {lr} mov PC,lr a:.word 1 b: .word 2 c: .word 3 d: .word 4 e: .word 5 mystr: .string "\na=%d,b=%d,c=%d,d=%d,e=%d\n"Copy the code