现在的位置: 首页 > 综合 > 正文

C指针原理(29)-AT&T汇编

2013年02月03日 ⁄ 综合 ⁄ 共 2437字 ⁄ 字号 评论关闭

linux-汇编静态符号

.equ 符号名 值

比如

.equ PI 3.1415

使用方式 为:

movl $PI,%eax

汇编数据类型

本博客所有内容是原创,如果转载请注明来源

http://blog.csdn.net/myhaspl/

.ascii 文本字符串

.asciz 以空字符结尾的文本字符串

.byte 字节值

.double 双精度符点数

.float 单精度符点数

.int 32位整数

.long 64位整数

.octa 16字节整数

.quad 8字节整数

.short 16位整数

.single 单精度整数与float相同

汇编传送指令

传送数据元素

movl:32位长度

movw:16位长度

movb:8位长度

比如:

movl 源,目标

汇编-多值内存位置访问(1)

.section .data
  myvalue:
     .byte 67,68,69,70,0
  mygs:
     .asciz "%s\n"
   
.section .text
.globl main
   main:
    movl $myvalue,%ecx
    inc %ecx#本来应输出CDEF,68代表D
    push %ecx
    push $mygs    
    call printf
    push $0
    call exit



        deepfuture@deepfuture-laptop:~/private/mytest$ gcc -o test12 test12.s

deepfuture@deepfuture-laptop:~/private/mytest$ ./test12

DEF

deepfuture@deepfuture-laptop:~/private/mytest$ 

    
    

deepfuture@deepfuture-laptop:~/private/mytest$ gcc -o test12 test12.s

deepfuture@deepfuture-laptop:~/private/mytest$ ./test12

E

deepfuture@deepfuture-laptop:~/private/mytest$ 

.section .data
  myvalue:
     .byte 67,68,69,70,0
  mygs:
     .asciz "%c\n"
   
.section .text
.globl main
   main:
    #基地址(偏移地址[必须为寄存器],数据元素变址,数据元素长度[必须为寄存器],)
    #基地址+偏移地址+数据元素变址*数据元素长度
    movl $2,%ecx
    movl myvalue(,%ecx,1),%ebx #将myvalue的变址为2,长度为1的数据值移到ebx中
    push %ebx
    push $mygs    
    call printf
    push $0
    call exit
       
    
    .section .data
  myvalue:
     .byte 67,68,69,70,0
  mygs:
     .asciz "%c\n"
  mygss:
     .asciz "%s\n"
.section .text
.globl main
   main:
    #以下为传数值
    #深未来技术,http://deepfuture.iteye.com
    #基地址(偏移地址[必须为寄存器],数据元素变址,数据元素长度[必须为寄存器],)
    #基地址+偏移地址+数据元素变址*数据元素长度
    movl $2,%ecx
    movl myvalue(,%ecx,1),%ebx #将myvalue的变址为2,长度为1的数据值移到ebx中
    push %ebx
    push $mygs    
    call printf
    #以下为传地址
    movl $2,%ecx
    movl $myvalue,%ebx#传myvalue的地址,变量前加上$
    push %ebx
    push $mygss    
    call printf 
    #以下为传数值
    movl $2,%ecx
    movl myvalue,%ebx#传myvalue第一个内存位置的数值
    push %ebx
    push $mygs    
    call printf    
    #以下为传地址,mov %eax,(%ebx)表示把eax值复制到寄存器ebx所代表内存位置中,寄存器中存放着地址
    movl $71,%edx
    movl $myvalue,%eax;
    movb %dl,2(%eax)#eax指向位置后的第2个字节,将69改为71
    movl $myvalue,%ebx
    push %ebx
    push $mygss    
    call printf  
    push $0
    call exit

deepfuture@deepfuture-laptop:~/private/mytest$ gcc -o test12 test12.s

test12.s: Assembler messages:

test12.s:0: Warning: end of file not at end of a line; newline inserted

deepfuture@deepfuture-laptop:~/private/mytest$ ./test12

E

CDEF

C

CDGF

deepfuture@deepfuture-laptop:~/private/mytest$ 

汇编的movl使用


.section .data
  myvalue:
    .int 67
   
.section .text
.globl main
   main:
    movl $myvalue,%ecx
    push $myvalue
    call printf
    push $0
    call exit

deepfuture@deepfuture-laptop:~/private/mytest$ gcc -o test12 test12.s

deepfuture@deepfuture-laptop:~/private/mytest$ ./test12

Cdeepfuture@deepfuture-laptop:~/private/mytest$ 


抱歉!评论已关闭.