Siêu thị PDFTải ngay đi em, trời tối mất

Thư viện tri thức trực tuyến

Kho tài liệu với 50,000+ tài liệu học thuật

© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

Tài liệu Advanced Linux Programming: 9-Inline Assembly Code ppt
MIỄN PHÍ
Số trang
8
Kích thước
200.2 KB
Định dạng
PDF
Lượt xem
1549

Tài liệu Advanced Linux Programming: 9-Inline Assembly Code ppt

Nội dung xem thử

Mô tả chi tiết

Inline Assembly Code

9

TODAY, FEW PROGRAMMERS USE ASSEMBLY LANGUAGE. Higher-level languages such

as C and C++ run on nearly all architectures and yield higher productivity when

writing and maintaining code. For occasions when programmers need to use assembly

instructions in their programs, the GNU Compiler Collection permits programmers

to add architecture-dependent assembly language instructions to their programs.

GCC’s inline assembly statements should not be used indiscriminately.Assembly

language instructions are architecture-dependent, so, for example, programs using x86

instructions cannot be compiled on PowerPC computers.To use them, you’ll require a

facility in the assembly language for your architecture. However, inline assembly

statements permit you to access hardware directly and can also yield faster code.

An asm instruction allows you to insert assembly instructions into C and C++

programs. For example, this instruction

asm (“fsin” : “=t” (answer) : “0” (angle));

is an x86-specific way of coding this C statement:1

answer = sin (angle);

1.The expression sin (angle) is usually implemented as a function call into the math

library, but if you specify the -O1 or higher optimization flag, GCC is smart enough to replace

the function call with a single fsin assembly instruction.

11 0430 CH09 5/22/01 10:36 AM Page 189

Tải ngay đi em, còn do dự, trời tối mất!