Przeglądaj źródła

add lab-ex3 for inline assembly for C examples

main
yuchen 9 lat temu
rodzic
commit
f2c3333eaa
3 zmienionych plików z 31 dodań i 2 usunięć
  1. +6
    -2
      related_info/lab1/Makefile
  2. +17
    -0
      related_info/lab1/lab1-ex3.c
  3. +8
    -0
      related_info/lab1/lab1-ex3.md

+ 6
- 2
related_info/lab1/Makefile Wyświetl plik

@ -1,4 +1,4 @@
all: lab1-ex0.exe lab1-ex1.exe
all: lab1-ex0.exe lab1-ex1.exe lab1-ex3.s
lab1-ex0.exe: defines.h lab1-ex0.s
gcc -m32 -g -o lab1-ex0.exe lab1-ex0.s
@ -10,6 +10,10 @@ lab1-ex1.exe: lab1-ex1.c
strace -c ./lab1-ex1.exe
echo "watch the interrupts in linux"
more /proc/interrupts
lab1-ex3.s: lab1-ex3.c
echo "show .s files"
gcc -m32 -S lab1-ex3.c
clean:
rm lab1-ex0.exe lab1-ex1.exe
rm lab1-ex0.exe lab1-ex1.exe lab1-ex3.s

+ 17
- 0
related_info/lab1/lab1-ex3.c Wyświetl plik

@ -0,0 +1,17 @@
void inline ex1(void){
asm ("movl $0xffff, %%eax\n");
}
void inline ex2(void){
unsigned cr0;
asm volatile ("movl %%cr0, %0\n" :"=r"(cr0));
cr0 |= 0x80000000;
asm volatile ("movl %0, %%cr0\n" ::"r"(cr0));
}
void inline ex3(void){
long __res, arg1 = 2, arg2 = 22, arg3 = 222, arg4 = 233;
__asm__ __volatile__("int $0x80"
: "=a" (__res)
: "0" (11),"b" (arg1),"c" (arg2),"d" (arg3),"S" (arg4));
}

+ 8
- 0
related_info/lab1/lab1-ex3.md Wyświetl plik

@ -0,0 +1,8 @@
# inline assembly for C example
Try below command
```
gcc -m32 -S lab1-ex3.c
```
Then you will get lab1_ex3.s
Try to understand the contents of this .s file and the relation between .c file and .s file.

Ładowanie…
Anuluj
Zapisz