汇编语言简介(二)
2016-06-13 00:00
585 查看
摘要: 通过《汇编语言程序设计》第四章学习
这个程序查看CPUID指令产生的厂商ID字符串。
1、使用GNU汇编器和GNU连接器构建可执行程序
运行情况:
2、使用GNU通用编译器编译
gcc有默认的_start标签,查找的是main标签,所以代码要进行以下修改:
运行情况:
两种最常被检查的数据元素是用于变量的寄存器和内存位置。如下:
用连接器生成:
用gcc,只需把_start标签变为main。
一、范例程序:cpuid.s
[code=plain].section .data output: .ascii "The processor Vendor ID is 'xxxxxxxxxxxx'\n" .section .text .globl _start _start: movl $0, %eax cpuid movl $output, %edi movl %ebx, 28(%edi) movl %edx, 32(%edi) movl %ecx, 36(%edi) movl $4, %eax movl $1, %ebx movl $output, %ecx movl $42, %edx int $0x80 movl $1, %eax movl $0, %ebx int $0x80
这个程序查看CPUID指令产生的厂商ID字符串。
1、使用GNU汇编器和GNU连接器构建可执行程序
运行情况:
2、使用GNU通用编译器编译
gcc有默认的_start标签,查找的是main标签,所以代码要进行以下修改:
[code=plain].globl main main: movl $0, %eax cpuid
运行情况:
二、调试程序
使用GDB两种最常被检查的数据元素是用于变量的寄存器和内存位置。如下:
三、在汇编语言中使用C库函数
代码如下:cpuid2.s[code=plain].section .data output: .asciz "The processor Vendor ID is '%s'\n" .section .bss .lcomm buffer, 12 .section .text .globl _start _start: movl $0, %eax cpuid movl $buffer, %edi movl %ebx, (%edi) movl %edx, 4(%edi) movl %ecx, 8(%edi) pushl $buffer pushl $output call printf addl $8, %esp pushl $0 call exit
用连接器生成:
用gcc,只需把_start标签变为main。
相关文章推荐
- Linux2.4打开一个文件的系统调用
- Linux2.6系统调用
- 数论-Special Numbers
- 《重构》第一章 笔记
- 背包问题
- Linux2.6-4G的线性地址空间的分配与使用
- 快速选择
- redis的持久化
- LychrelNumber实现V1.0
- 算法导论 第10章 10.3 指针和对象实现
- 百度面试经历
- 算法导论-15-3-编辑距离
- 第16章 贪心算法
- docker误区
- 使用Python处理目录(一):打印目录下的文件名
- 算法导论 第22章 图算法 22.3 深度优先搜索
- 算法导论-14.3-6-MIN-GAP
- 算法导论 14.1-7 顺序统计树求逆序对 O(nlgn)
- 2012-9-23 搜狗笔试
- 你想成为更好的程序员吗?