gpt4 book ai didi

assembly - 汇编 6502 中的 256 和 64 位数字

转载 作者:行者123 更新时间:2023-12-04 03:43:33 24 4
gpt4 key购买 nike

我必须用 6502 汇编语言编写一个代码,使用基本的位移运算以及算术和逻辑运算将 256 位数字除以 64 位数字。
我只是不知道如何在程序集 6502 中编写 256 和 64 位数字。

最佳答案

i just don't know how to write 256 and 64 bit number in assembly 6502.


您可以将它们分别存储为 32 8 字节的字符串。
在内存中,qword 编号 $1122334455667788 看起来像以下 8 个字节:
$88, $77, $66, $55, $44, $33, $22, $11
对于 256 位数字,类似且长 4 倍。

了解如何处理多字节数字。这是几个 16 位数字的相加。
如果 NumA 是 1122 美元,而 NumB 是 3344 美元,那么总和就是 Res:
CLD
CLC
LDA NumA ; -> A = $22
ADC NumB ; -> A = $22 + $44 = $66
STA Res
; The carry propagates to the higher order addition
LDA NumA+1 ; -> A = $11
ADC NumB+1 ; -> A = $11 + $33 = $44
STA Res+1
Res 现在持有总额为 4466 美元。
处理非常大的数字将需要一个循环。接下来是添加两个qwords:
 CLD
CLC
LDY #8 ; Qwords have 8 bytes
LDX #0
Loop:
LDA NumA,X
ADC NumB,X
STA Res,X
INX ; INX and DEY don't clobber the carry
DEY ; and thus it can propagate
BNE Loop

关于assembly - 汇编 6502 中的 256 和 64 位数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65550451/

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