AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题

问题[assembler](ubuntu)

Martin Hope
Грузчик
Asked: 2019-12-08 00:22:16 +0800 CST

sys_write 不向终端打印消息

  • 0

我正在尝试使用以下示例探索 GNU 汇编程序:https ://0xax.github.io/asm_1/

我的代码 main.s 是

 .data
 message: .ascii "ASSEMBLY OUTPUT"

.text
.globl _start

_start:
movq $1, %rdi
movq $1, %rax
movq $15, %rdx
movq $message, %rsi
syscall
movq $60, %rax
movq $0, %rdi
syscall

命令行准备:

as -g -o main.o main.s

ld -o main main.o

现在,我运行 ./main 但它不打印任何内容,终端正在等待我的下一个命令。

怎么了?

在 GNU 调试器中,数字已成功存储在寄存器中。

我在 RAX 中看到了第一个系统调用“-14”的结果。

programming system assembler
  • 1 个回答
  • 159 Views
Martin Hope
SDIdo
Asked: 2018-10-20 01:34:16 +0800 CST

gcc -Hello.s 问题

  • 2

我的系统是 Ubuntu 18.04 64bit 。 安装了 build-essentials 和 devtools。

你好,我有一个名为 Hello.s 的程序集文件,内容如下:

        #This is a simple "Hello World!" program
    .section    .rodata #read only data section
str:    .string "Hello World!\n"
    ########
    .text   #the beginnig of the code
.globl  main    #the label "main" is used to state the initial point of this program
    .type   main, @function # the label "main" representing the beginning of a function
main:   # the main function:
    pushq   %rbp        #save the old frame pointer
    movq    %rsp,   %rbp    #create the new frame pointer

    movq    $str,%rdi   #the string is the only paramter passed to the printf function (remember- first parameter goes in %rdi).
    movq    $0,%rax
    call    printf      #calling to printf AFTER we passed its parameters.

    #return from printf:
    movq    $0, %rax    #return value is zero (just like in c - we tell the OS that this program finished seccessfully)
    movq    %rbp, %rsp  #restore the old stack pointer - release all used memory.
    popq    %rbp        #restore old frame pointer (the caller function frame)
    ret         #return to caller function (OS)

尝试使用 gcc -Hello.s 编译它会返回以下消息:

/usr/bin/ld: /tmp/ccY9hdWi.o: relocation R_X86_64_32S against `.rodata' can not be used when making a PIE object; recompile with -fPIC

/usr/bin/ld:最终链接失败:输出 collect2 上的不可表示部分:错误:ld 返回 1 退出状态

尝试了没有效果的 gcc -fPIC Hello.s - 带来了相同的消息。

有人告诉我安装gcc-4.8,那没用

还建议安装以前版本的 ubuntu.. 在我看来,这是最后的手段。

有什么建议么?

compiling gcc 18.04 assembler
  • 1 个回答
  • 779 Views
Martin Hope
Scorch
Asked: 2018-08-13 02:43:20 +0800 CST

如何在 Ubuntu 18.04 中编译和运行程序集?

  • 27

所以最近想学汇编,所以学了一点。我把它放入 nano 并保存为 playground.asm。现在我想知道,如何编译和运行它?我已经到处找了,还是找不到。我真的很好奇,如果你甚至不会使用一门语言,那么学习它是没有意义的。

compiling 18.04 assembler
  • 2 个回答
  • 68463 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve