打印INT 64位AT&放ASCII组装;吨浮点数错误 [英] print int as ascii in assembly 64 bit at&t float number error
问题描述
我写了一个程序独奏只是为了弄清楚如何做到这一点,我前面加48要打印的份数,但现在,当我得到大于9的数字是不是真的足够了。
所以,下面的程序应该把23进我的温度,相比23到10,如果是小于10我可以打印,否则将温度客场RAX,把10 R11和除以10 23。
把结果从兵营中的温度,并再次检查。
我还需要添加一个方法来首先检索前面的数字,但第一件事。
有我missunderstood会发生什么,结果我得到的是浮点数误差
的#include<&stdio.h中GT; #Inkludera标准I / O。数据#Specifiera数据
温度:0 .quad
TEMP2:.quad 0。文本 。全球主要
主要:
MOVQ $ 23日,临时
JMP检查检查:
cmpq $ 10,$温度
JL under10
MOVQ $温度,RAX%
MOVQ $ 10%R11
divq%R11
MOVQ%RAX,温度
JMP检查under10:
addq $ 48温度
MOVQ $温度,%RDI
电话看跌期权
当你做 divq%R11
你实际上是除以128位寄存器对 RDX:RAX
按 R11
。因此,为了得到一个商数,将适合在 RAX
您通常要清除 RDX
师之前,即前在 divq
,添加一个:
xorq%的RDX,RDX%RDX#= 0
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
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
这篇关于打印INT 64位AT&放ASCII组装;吨浮点数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!