組合語言程式設計 01 獲取cpuid

2021-06-29 07:46:04 字數 1040 閱讀 3435

今天開始學習x86彙編:

硬平台:intel,軟平台:linux

《組合語言程式設計》

原始碼:root@ubuntu-core:/home/cpuid# vim cpuid.s

1 #cpuid.s sample program to extract the processor vendor id

2 3 .section .data

4 output:

5         .ascii "the processor vendor id is '************'\n"

6 .section .text

7 .globl _start

8 _start:

9         movl $0, %eax     //填寫cpuid指令的輸入

10         cpuid//執行cupid指令

11 movl $output,%edi//獲取輸出

12 movl %ebx,28(%edi)

13 movl %edx,32(%edi)

14 movl %ecx,36(%edi)

15 16 movl $4,%eax//write函式,核心中對應數字4

17 movl $1,%ebx //標準輸出

18 movl $output,%ecx//字元重首位址

19 movl $42,%edx//字元長度

20 int $0x80//促發系統呼叫

21 movl $1,%eax//exit函式

22 movl $0,%ebx//函式執行的返回值

23 int $0x80//促發系統呼叫

root@ubuntu-core:/home/cpuid# as -o cpuid.o cpuid.s 

root@ubuntu-core:/home/cpuid# ld -o cpuid  cpuid.o

root@ubuntu-core:/home/cpuid# ./cpuid 

the processor vendor id is 'genuineintel'

組合語言程式設計學習筆記01

第一章 組合語言基礎知識 1.1 暫存器 暫存器是cpu內部高速儲存單元,它們提供資料和位址。16位intel 8086 80826 cpu中的暫存器為 ax bx cx dx si di bp sp 儲存器位址 儲存器位址是儲存器中儲存單元的編號 每個儲存單元存放乙個位元組量的資料 乙個位元組b ...

組合語言程式設計

1.彙編語句的三種基本型別 2.標號相關 3.變數相關 4.運算元定址方式 buffer dw 500 x 17 rept 500 這是乙個重複巨集,以下重複彙編500遍 x x 979 mod 65535 這句話我也不懂 dw x endm 巨集在這裡結束transto10 proc near 函...

組合語言程式設計

乙個完整的源程式通常由若干邏輯段組成,包括資料段 附加段 堆疊段和 段。它們分別對映到儲存器中的物理段上。每個邏輯段以segment語句開始,以ends結束,整個源程式用end語句結尾。段中存放源程式的所有指令碼 資料 變數等則放在資料段和附加段中。程式中可以定義堆疊段,也可以直接利用系統中的堆疊段...