相关疑难解决方法(0)

GNU as, puts 有效,但 printf 无效

这是我现在正在玩的代码:

# file-name: test.s
# 64-bit GNU as source code.
    .global main

    .section .text
main:
    lea message, %rdi
    push %rdi
    call puts

    lea message, %rdi
    push %rdi
    call printf

    push $0
    call _exit

    .section .data
message: .asciz "Hello, World!"
Run Code Online (Sandbox Code Playgroud)

编译说明:gcc test.s -o test

修订版 1:

    .global main
    .section .text
main:
    lea message, %rdi
    call puts

    lea message, %rdi
    call printf

    mov $0, %rdi
    call _exit

    .section .data
message: .asciz "Hello, World!"
Run Code Online (Sandbox Code Playgroud)

最终修订版(作品):

    .global main
    .section .text
main:
    lea message, %rdi …
Run Code Online (Sandbox Code Playgroud)

64-bit x86 assembly gnu-assembler crt

0
推荐指数
1
解决办法
681
查看次数

通过将所有寄存器名称从eXX更改为rXX,从32位移植到64位,使因子返回0?

幸运的是,学习计算机编程艺术的所有用途都可以访问Stack Overflow等社区!我决定承担学习如何编程计算机的任务,我正在通过一本名为"从头开始编程"的电子书的知识这样做,该电子书教会读者如何用汇编语言创建程序在GNU/Linux环境中.

我在本书中的进展已经到了创建一个程序,该程序用函数计算整数4的阶乘,我已经完成并完成了没有由GCC的汇编程序引起的或由运行程序引起的任何错误.但是,我的程序中的功能没有返回正确的答案!阶乘4是24,但程序返回值0!说对了,我不知道为什么会这样!

以下是供您考虑的代码:

.section .data

.section .text

.globl _start

.globl factorial

_start:

push $4                    #this is the function argument
call factorial             #the function is called
add $4, %rsp               #the stack is restored to its original 
                           #state before the function was called
mov %rax, %rbx             #this instruction will move the result 
                           #computed by the function into the rbx 
                           #register and will serve as the return 
                           #value 
mov $1, %rax               #1 must be placed inside this register for 
                           #the exit system …
Run Code Online (Sandbox Code Playgroud)

assembly x86-64 function 32bit-64bit

0
推荐指数
1
解决办法
138
查看次数

你好,有 Linux 系统调用的汇编语言世界?

  1. 我知道这int 0x80会在 linux 中造成中断。但是,我不明白这段代码是如何工作的。它会返回一些东西吗?

  2. 代表什么$ - msg

global _start

section .data
    msg db "Hello, world!", 0x0a
    len equ $ - msg

section .text
_start:
    mov eax, 4
    mov ebx, 1
    mov ecx, msg
    mov edx, len
    int 0x80 ;What is this?
    mov eax, 1
    mov ebx, 0
    int 0x80 ;and what is this?
Run Code Online (Sandbox Code Playgroud)

linux x86 assembly nasm system-calls

0
推荐指数
1
解决办法
1179
查看次数

为什么C/C++比Assembly和其他低级语言慢?

我编写了一个代码,在C++中什么都不做

void main(void){

}
Run Code Online (Sandbox Code Playgroud)

和大会.

.global _start
.text

_start:
    mov $60, %rax
    xor %rdi, %rdi 
    syscall
Run Code Online (Sandbox Code Playgroud)

我编译C代码并编译和链接汇编代码.我用time命令比较了两个可执行文件.

部件

time ./Assembly

real    0m0.001s
user    0m0.000s
sys     0m0.000s
Run Code Online (Sandbox Code Playgroud)

C

time ./C

real    0m0.002s
user    0m0.000s
sys     0m0.000s
Run Code Online (Sandbox Code Playgroud)

汇编速度比C快两倍.我反汇编代码,在汇编代码中,只有四行代码(相同).在C代码中,有大量不必要的代码用于将main链接到_start.主要有四行代码,其中三行代表不可能(你不能从函数博客外部访问函数的变量)从' block ' 外部访问' local '(如函数变量)变量(像功能块一样).

push %rbp ; push base pointer.
mov  %rsp, %rbp ; copy value of stack pointer to base pointer, stack pointer is using for saving variables.
pop  %rbp ; 'local' variables are removed, because we pop the base …
Run Code Online (Sandbox Code Playgroud)

c++ assembly

-27
推荐指数
1
解决办法
690
查看次数

标签 统计

assembly ×4

x86 ×2

32bit-64bit ×1

64-bit ×1

c++ ×1

crt ×1

function ×1

gnu-assembler ×1

linux ×1

nasm ×1

system-calls ×1

x86-64 ×1