目录


1 入门

Chapter 1: What is Assembly language

略。

Chapter 2: The IA-32 Platform

略。

Chapter 3: 工具

C Tools for Linux

Chapter 4: 一个例程

如果要在64bit mac上运行32bit .s汇编源码,且使用dynamic linking of c libaray, 需要进行下面3步:

1.64bit mac上用virtualbox装 Ubuntu 64bit;

2.64bit Ubuntu 用gcc编译连接32bit assembly语法(本书).s文件成可执行文件需要加-m32flag;

1
gcc -m32 cpuid2.s -o cpuid

3.使用dynamic linking of c libaray,需安装libc6-dev-i386。

1
apt-get install libc6-dev-i386

这样就可以在64bit ubuntun虚拟机上编译连接,且运行下面.s源码(调用了c语言的printf)了。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#cpuid2.s View the CPUID Vendor ID string using C library calls

.section .data
output:
	.asciz "The processor Vendor ID is '%s'\n"

.section .bss
	.lcomm buffer,12

.section .text
.global main
main:
	mov $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

2 总结

本文快速浏览了本书的Chapter 1-4,构建了1个Linux 汇编 语言编程环境,为后面的章节打好基础。

3 Reference


Share Post

Twitter Google+

Shunmian

The only programmers in a position to see all the differences in power between the various languages are those who understand the most powerful one.