gpt4 book ai didi

linux - 3 位整数到 nasm 中可打印的 3 位字符串?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:30:54 25 4
gpt4 key购买 nike

我的计划即将完成,预计将于明天完成。但是我已经确定了问题的根源。我正在循环执行一些掷骰子 1-6 并将结果添加到缓冲区以保持得分的函数。然后当我想打印时,我只能打印一位整数和任何带有两位数的数字,例如 10 或更大的无限循环通过我的 write_number 函数,直到出现段错误。我如何更改此算法以适应最多三位整数,因为在程序结束之前分数需要进步到 100?除非有人有更好的以前编码的算法,因为我的任务是使用在线找到的工作功能。非常感谢任何见解!

section .bss

userScore: resd 4
pcScore: resb 4

number: resd 4
digit: resd 4
count: resd 4

. . . . . . . . . . .

cmp edx, 6 ;dice roll result
call write_number
jmp printReadOption

write_number:

add dword[userScore], edx
mov edx, dword[userScore]
mov dword[number], edx
mov eax, dword[number]
mov ecx, 0Ah ;hex for 10
cdq
div ecx ;eax=number/10,edx=number%10
mov dword[number], eax ;number= number/10
add edx, 30h ;add 48 (30h) to make a printable character
push edx ;push edx in to the stack and
inc dword[count] ;increment count of numbers in the stack
cmp dword[number], 0 ;if number != 0, loop again
jne write_number

loop2:

pop dword[digit] ;pop the digit from the stack and
call write_digit ;write it
dec dword[count] ;decrement the count
cmp dword[count], 0 ; if count != 0, loop again
jne loop2
ret

write_digit: ;Print score

mov eax, 4
mov ebx, 1
mov ecx, userScoreIs
mov edx, userScoreIsLen
int 80h

mov eax, 4
mov ebx, 1
mov ecx, digit ;score to print
mov edx, 4
int 80h
ret

最佳答案

在每次循环迭代开始时,您不断增加要潜水的数字(添加双字[userScore], edx),所以商可能永远不会达到零,这最终会导致你将太多的数字压入堆栈。迈克尔的补充,如下面的评论所列。

关于linux - 3 位整数到 nasm 中可打印的 3 位字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27479410/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com