print int as ascii in assembly 64 bit at&t float number error

匿名 (未验证) 提交于 2019-12-03 02:38:01

问题:

I've written a solo program just to figure out how to do this, earlier I added 48 to the number to print but now when I get numbers larger than 9 it's not really sufficient any more.

So the following program should put 23 into the my temp, compares 23 to 10 if it's smaller than 10 I can print otherwise put the temp away in rax, put 10 in r11 and divide 23 by 10. Put the result from rax in temp and check again. I still need to add a way to retrieve the earlier numbers but first thing first. Have I missunderstood what happens, the result I get is float number error

#include <stdio.h>          #Inkludera standard I/O  .data                   #Specifiera data temp:           .quad   0 temp2:          .quad   0  .text       .global main main: movq    $23, temp jmp check  check: cmpq    $10, $temp jl  under10 movq    $temp, %rax movq    $10, %r11 divq    %r11 movq    %rax,temp jmp check  under10: addq    $48, temp movq    $temp,%rdi call    puts 

回答1:

When you do divq %r11 you're actually dividing the 128-bit register pair rdx:rax by r11. So to get a quotient that will fit in rax you'll typically want to clear rdx before the division, i.e. before the divq, add an:

xorq %rdx, %rdx   # rdx = 0 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!