Ubuntu x86-64汇编(2)

开发工具链

汇编编译器: yasm
连接器: ld
载入工具: os自带
Debug工具:  ddd

yasm安装

tar zxvf yasm-1.3.0.tar.gz 
cd yasm-1.3.0/
./configure --prefix=/opt/yasm
make
sudo make install
cd /usr/bin/
sudo ln -s /opt/yasm/bin/yasm yasm
yasm --version

编译命令

yasm -g dwarf2 -f elf64 example.asm -l example.lst

-g  dwarf2 在object文件里包含debug信息
-f elf64 使用Linux 64位系统的ELF64格式
-l <filename> 创建filename这个连接文件

连接器

命令格式

ld -­g -o example example.o

 -g 在输出的可执行文件中包含debug信息
-o 指定可执行文件的文件名, 默认会使用 a.out

方便编译和连接的Shell脚本

可以创建一个脚本以方便编译和连接asm文件

#!/bin/bash
# Simple assemble/link script.

if [ -z "$1" ]; then
  echo "Usage: ./asm <asmMainFile> (no extension)"
  exit
fi
# Verify no extensions were entered
if [ ! -e "$1.asm" ]; then
  echo "Error, $1.asm not found."
  echo "Note, do not enter file extensions."
  exit
fi
# Compile, assemble, and link.
yasm -g dwarf2 -f elf64 $1.asm -l $1.lst
ld -g -o $1 $1.o

执行时, 参数需要删除.asm扩展名

Debug工具 ddd

可以直接通过apt安装

sudo apt-get install ddd

使用时, 需要确认勾选这两个参数 Edit / Preference / General / Suppress X Warning 和 Edit / Preference / Source / Display Source Line Number

可以通过下方的控制台窗口, 或者弹出的控制菜单, 对debug进行控制.

 

.

posted on 2018-05-13 00:20  Milton  阅读(241)  评论(0编辑  收藏  举报

导航