Fro*_*and 6 linux assembly nasm
我试图在linux上的nasm程序集中打印单个数字整数.我目前编写的内容很好,但没有任何内容写入屏幕.任何人都可以向我解释我在这里做错了什么吗?
section .text
global _start
_start:
mov ecx, 1 ; stores 1 in rcx
add edx, ecx ; stores ecx in edx
add edx, 30h ; gets the ascii value in edx
mov ecx, edx ; ascii value is now in ecx
jmp write ; jumps to write
write:
mov eax, ecx ; moves ecx to eax for writing
mov eax, 4 ; sys call for write
mov ebx, 1 ; stdout
int 80h ; call kernel
mov eax,1 ; system exit
mov ebx,0 ; exit 0
int 80h ; call the kernel again
Run Code Online (Sandbox Code Playgroud)
这是添加,而不是存储:
add edx, ecx ; stores ecx in edx
Run Code Online (Sandbox Code Playgroud)
这将ecx复制到eax,然后用4覆盖它:
mov eax, ecx ; moves ecx to eax for writing
mov eax, 4 ; sys call for write
Run Code Online (Sandbox Code Playgroud)
编辑:
对于'写'系统调用:
eax = 4
ebx = file descriptor (1 = screen)
ecx = address of string
edx = length of string
Run Code Online (Sandbox Code Playgroud)
在查看了其他两个答案之后,这就是我最终想到的。
sys_exit equ 1
sys_write equ 4
stdout equ 1
section .bss
outputBuffer resb 4
section .text
global _start
_start:
mov ecx, 1 ; Number 1
add ecx, 0x30 ; Add 30 hex for ascii
mov [outputBuffer], ecx ; Save number in buffer
mov ecx, outputBuffer ; Store address of outputBuffer in ecx
mov eax, sys_write ; sys_write
mov ebx, stdout ; to STDOUT
mov edx, 1 ; length = one byte
int 0x80 ; Call the kernel
mov eax, sys_exit ; system exit
mov ebx, 0 ; exit 0
int 0x80 ; call the kernel again
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8807 次 |
| 最近记录: |