NASM的Linux大会整数印刷 [英] NASM Linux Assembly Printing Integers
本文介绍了NASM的Linux大会整数印刷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想打印在Linux上在NASM装配一个数字的整数。我目前有编译罚款,但没有被写入到屏幕上。任何人都可以向我解释什么,我做错了什么?
.text段
全球_start_开始:
MOV ECX,1;在RCX商店1
添加EDX,ECX;商店ECX在EDX
添加EDX,30H;获取EDX的ASCII值
MOV ECX,EDX; ASCII值现在在ECX
JMP写;跳转到写
写:
MOV EAX,ECX;移动ECX到EAX写作
MOV EAX,4; SYS要求写
MOV EBX,1;标准输出 INT 80H;调用内核
MOV EAX,1;退出系统
MOV EBX,0;退出0
INT 80H;再次调用内核
解决方案
这是添加,不存储:
添加EDX,ECX;商店ECX在EDX
此副本ECX到EAX,然后用4覆盖它:
MOV EAX,ECX;移动ECX到EAX写作
MOV EAX,4; SYS要求写
编辑:
对于'写'系统调用:
EAX = 4
EBX =文件描述符(1 =画面)
字符串的ECX =地址
字符串的EDX =长度
I am trying to print a single digit integer in nasm assembly on linux. What I currently have compiles fine, but nothing is being written to the screen. Can anyone explain to me what I am doing wrong here?
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
解决方案
This is adding, not storing:
add edx, ecx ; stores ecx in edx
This copies ecx to eax and then overwrites it with 4:
mov eax, ecx ; moves ecx to eax for writing
mov eax, 4 ; sys call for write
EDIT:
For a 'write' system call:
eax = 4
ebx = file descriptor (1 = screen)
ecx = address of string
edx = length of string
这篇关于NASM的Linux大会整数印刷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文