栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用x86 32位Linux sys_write(NASM)打印整数

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用x86 32位Linux sys_write(NASM)打印整数

您的数字将迅速增长,而不仅仅是一个数字。您应该做的是输入一个整数

num
而不是一个字符,然后将该整数转换为可以使用打印的字符串
sys_write

这是进行转换的一种方法:重复除以10,首先获得最低的位数作为余数:

; Input:; eax = integer value to convert; esi = pointer to buffer to store the string in (must have room for at least 10 bytes); Output:; eax = pointer to the first character of the generated string; ecx = length of the generated stringint_to_string:  add esi,9  mov byte [esi],0    ; String terminator  mov ebx,10.next_digit:  xor edx,edx         ; Clear edx prior to dividing edx:eax by ebx  div ebx  ; eax /= 10  add dl,'0'          ; Convert the remainder to ASCII   dec esi  ; store characters in reverse order  mov [esi],dl  test eax,eax   jnz .next_digit     ; Repeat until eax==0  ; return a pointer to the first digit (not necessarily the start of the provided buffer)  mov eax,esi  ret

您可以这样使用:

    mov    dword [num],1    ...    mov    eax,[num]       ; function args using our own private calling convention    mov    esi,buffer    call   int_to_string; eax now holds the address that you pass to sys_write    ...section .bss    num    resd 1    buffer resb 10

您的倍数可以简化为

shl dword [num],1
。或者更好的是,在仍与保持一致时,将其加倍
add eax,eax



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/405875.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号