zoukankan      html  css  js  c++  java
  • Linux 编译汇编

    将下面的代码保存为asm.s文件:
     .section .data
    data_items: #These are the data items
    .
    long 3,67,34,222,45,75,54,34,44,33,22,11,66,0
    .section .text
    .globl _start
    _start:
    movl $
    0, %edi # move 0 into the index register
    movl data_items(,
    %edi,4), %eax # load the first byte of data
    movl
    %eax, %ebx # since this is the first item, %eax is
    # the biggest
    start_loop: # start loop
    cmpl $
    0, %eax # check to see if we've hit the end
    je loop_exit
    incl
    %edi # load next value
    movl data_items(,
    %edi,4), %eax
    cmpl
    %ebx, %eax # compare values
    jle start_loop # jump to loop beginning
    if the new
    # one isn
    't bigger
    movl %eax, %ebx # move the value as the largest
    jmp start_loop # jump to loop beginning
    loop_exit:
    #
    %ebx is the status code for the _exit system call
    # and it already has the maximum number
    movl $
    1, %eax #1 is the _exit() syscall
    int $0x80

    在Linux终端中编译这段代码:

      $as asm.s -o asm.o   //编译这段汇编代码

      $ld asm.o -o asm     //链接编译代码为可执行程序

      $ ./asm                   //执行程序

    如何在Linux查看自己写的程序的汇编代码?

    有两种方法:

    1、gcc -S temp.c 这样会生成temp.s的汇编文件

    2、$ gcc temp.c -g

       $ objdump -dS a.out 

  • 相关阅读:
    题目1.A乘以B
    题目1.A乘以B
    秋季学习总结
    题目1.A乘以B
    第一周作业
    C语言I博客作业02
    Silverlight中图像的变换(1)
    SQL SERVER 2005安装过程中COM+错误解决!
    c++ 对文件的操作
    JS标准DES加解密
  • 原文地址:https://www.cnblogs.com/bugY/p/2176215.html
Copyright © 2011-2022 走看看